我正在编写一个测试来验证位置服务是否在单击按钮时启动。这需要一个非常简单的 if 语句来确保手机有可用的定位服务。
现在的工作测试看起来像这样
- (void)testStartUpdatingLocationInvokedWhenLocationServicesAreEnabled
{
[[[self.locationManager stub] andReturnValue:[NSNumber numberWithBool:true]] locationServicesEnabled];
[[self.locationManager expect] startUpdatingLocation];
[self.sut buttonClickToFindLocation:nil];
[self.locationManager verify];
}
现在测试的实现看起来像这样
- (IBAction)buttonClickToFindLocation:(id)sender
{
if ([self.locationManager locationServicesEnabled])
{
[self.locationManager startUpdatingLocation];
}
}
除了该方法在 iOS 4.0 中已弃用之外,一切都很好。所以现在我需要改用类方法 [CLLocationManager locationServicesEnabled]。
问题是我似乎无法找到 ocmock 是否支持此功能,如果不支持,我现在应该如何解决这个问题。