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?
Aucun commentaire:
Enregistrer un commentaire