I'm trying to implement Application Tests as described here. So far, so good, but i fail to test, for instance, the location of the device using Core Location. I have added the appropriate Framework to the Target, and have initiated the update of location, but i have no clue of how to wait for the location to be loaded, the test suite just ends before the second thread finish. Please help me to find a way to test this sort of things.
If you're relying on CLLocationManager
you can implement these two delegate methods in CLLocationManagerDelegate
:
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
- (void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error
Then you set the CLLocationmanager
delegate and tell it to startUpdatingLocation
. If you get didUpdateLocation
(with oldLocation
set to nil) it means you now have a location and you can consider the test a success (make sure you turn off updating). If you get the other one there was a location-manager error.
If you're relying on MapKit and are using MKMapView
's user-location update mechanism, then take a look at my response to this question and implement the observer section (observeValueForKeyPath
) to be notified when the map has a location (success) or implement MKMapViewDelegate's mapViewDidFailLoadingMap
to be notified if there was an error.