小编Nad*_*eya的帖子

XCTest 失败,出现异常“非 UI 客户端不能自动暂停”

我正在尝试使用默认参数将 CLLocationManager 的创建测试为单音:

+ (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];
}
Run Code Online (Sandbox Code Playgroud)

测试看起来像这样:

- (void)testInitWithDefaultsSettings
{
    GeolocationService *defaultGeolocationService = [GeolocationService defaultGeolocationService];

    XCTAssertTrue(defaultGeolocationService.settings.autoPause, @"autoPause");
}
Run Code Online (Sandbox Code Playgroud)

我得到一个例外:*** 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“非 UI 客户端不能自动暂停”

我应该怎么做才能使这个测试工作?

unit-testing xctest xcode6 ios8

6
推荐指数
1
解决办法
809
查看次数

标签 统计

ios8 ×1

unit-testing ×1

xcode6 ×1

xctest ×1