首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >xctestcase在通过pretest时运行测试

xctestcase在通过pretest时运行测试
EN

Stack Overflow用户
提问于 2015-09-22 18:55:20
回答 1查看 247关注 0票数 1

我在XCTestCase类中有几个测试用例,例如test1、test2等。我只想在传递testPrecondition的情况下运行test1, test2。我怎样才能做到这一点呢?

EN

回答 1

Stack Overflow用户

发布于 2015-09-22 23:30:12

您必须重写XCtest的testInvocations类方法。下面的例子来自Github,代码是不言自明的。

代码语言:javascript
复制
+ (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];
}

如果您想要决定在运行时=>期间运行哪个测试,那么您的测试(依赖项)中有一种代码气味,这意味着您正在做错误的测试。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32715046

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档