【发布时间】:2015-12-19 07:45:42
【问题描述】:
我在 XCTestCase 类中有几个测试用例,例如测试1,测试2等
仅当通过 testPrecondition 时,我才想运行 test1, test2。我怎样才能做到这一点?
【问题讨论】:
标签: ios objective-c xcode macos xctest
我在 XCTestCase 类中有几个测试用例,例如测试1,测试2等
仅当通过 testPrecondition 时,我才想运行 test1, test2。我怎样才能做到这一点?
【问题讨论】:
标签: ios objective-c xcode macos xctest
你必须重写 XCtest 的 testInvocations 类方法。以下示例来自Github 代码一目了然。
+ (NSArray *)testInvocations
{
BOOL onlineTests = [[[[NSProcessInfo processInfo] environment] objectForKey:@"ONLINE_TESTS"] boolValue];
if (!onlineTests)
return [super testInvocations];
NSMutableArray *testInvocations = [NSMutableArray new];
for (NSInvocation *invocation in [super testInvocations])
{
if (![NSStringFromSelector(invocation.selector) hasSuffix:offlineSuffix])
[testInvocations addObject:invocation];
}
return [testInvocations copy];
}
如果您想决定在运行时运行哪个测试 => 您的测试中有代码异味(依赖性),这意味着您做错了测试。
【讨论】: