views:

469

answers:

1

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.

+2  A: 

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.

Ramin
Ramin, sorry, it seems that i was not able to explain myself. My issue is not how to get the location in the real app, but how to test the application. Let me try again: Let's say, for instance, that i trigger the startUpdatingLocation on applicationDidFinishLaunching: and set the appDelegate as the delegate of the CLLocationManager. The question is how to set the test suite to be able to test whether the CLLocationManager delegate receives locationManager:didUpdateLocation:fromLocation: As far as i was able to get, the test just ends before the delegate calls are triggered. Anythow, thanks
ariel