【发布时间】:2015-07-30 16:46:31
【问题描述】:
我正在尝试将 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];
}
测试如下:
- (void)testInitWithDefaultsSettings
{
GeolocationService *defaultGeolocationService = [GeolocationService defaultGeolocationService];
XCTAssertTrue(defaultGeolocationService.settings.autoPause, @"autoPause");
}
我得到一个例外: *** 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“非 UI 客户端无法自动暂停”
我应该怎么做才能使这个测试工作?
【问题讨论】:
-
我猜苹果不会对自己的代码进行单元测试。 :(
-
或者拼写检查,想想看。
标签: unit-testing ios8 xcode6 xctest