I am trying to test creation of CLLocationManager as a singletone with default parameters:
+ (GeolocationService *)defaultGeolocationService
{
static GeolocationService *_defaultGeolocationService = nil;
static dispatch_once_t oncePredicate;
dispatch_once(&oncePredicate, ^{
_defaultGeolocationService = [[GeolocationService alloc] init];
[_defaultGeolocationService initLocationManager];
});
return _defaultGeolocationService;
}
- (void)initLocationManager
{
self.locationManager = [CLLocationManager new];
self.locationManager.delegate = self;
self.locationManager.pausesLocationUpdatesAutomatically = YES;
[self.locationManager requestAlwaysAuthorization];
}
Test looks like this:
- (void)testInitWithDefaultsSettings
{
GeolocationService *defaultGeolocationService = [GeolocationService defaultGeolocationService];
XCTAssertTrue(defaultGeolocationService.settings.autoPause, @"autoPause");
}
And I get an exception: *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Non-UI clients cannont be auto paused'
What should I do to make this test work?
The issue is with the following line
self.locationManager.pausesLocationUpdatesAutomatically = YES;
This property cannot be set on an application that is not running a UI (not sure why, I could not find any documentation about it).
You may want to do some checks in your test to ensure that the UI has loaded before initialising your GeoLocationService
and setting self.locationManager.pausesLocationUpdatesAutomatically
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With