Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XCTest fails with with exception 'Non-UI clients cannont be autopaused'

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?

like image 691
Nadzeya Avatar asked Jul 30 '15 16:07

Nadzeya


1 Answers

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.

like image 82
Matthew Cawley Avatar answered Nov 15 '22 05:11

Matthew Cawley