iPhone: Application Testing and Core Location
Asked Answered
Z

1

6

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.

Zoraidazorana answered 20/10, 2009 at 18:8 Comment(3)
Good luck with this one. I couldn't get that to work... :-)Oceanid
This is also what I am looking for with my unit testing. It looks like the application-tests are started before applicationDidFinishLaunching gets called.Esbjerg
I'm trying to do something similar, and hoping to mock the location.Ladyship
S
1

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.

Sheela answered 20/10, 2009 at 18:37 Comment(1)
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, thanksZoraidazorana

© 2022 - 2024 — McMap. All rights reserved.