簡體   English   中英

通過預測試時,xctestcase運行測試

[英]xctestcase run tests when a pretest is passed

我有一個多組測試XCTestCase類比如為test1,test2的等等。我想運行test1, test2只有testPrecondition傳遞。 我該如何實現?

您必須重寫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];
}

如果要決定在運行時運行哪個測試=>,則測試中會有代碼異味(依賴性),這意味着您做錯了測試。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM