N13
N13

Reputation: 91

Xcode: skip test if previous one failed

Is there any option in Xcode to skip the test in test-class if previous one failed?

Now I use something like that in potentially skippable test body:

if previousTestFailed == true {
    XCTFail("Test can't proceed because previous one failed")
}

Maybe there is something more pleasant?

Upvotes: 1

Views: 443

Answers (1)

Jon Reid
Jon Reid

Reputation: 20980

Tests must function independently of each other. This is especially important when running one test in isolation. Xcode 10 will help enforce this independence by giving the option to shuffle test order.

To terminate a test when a precondition fails, just test for that precondition, even if that means repeating some code from the more fundamental test. XCTFail if the precondition is not met.

If the precondition applies to multiple tests, extract it to a helper. Then the tests can do something like

if !meetsPrecondition() {
    XCTFail("Precondition not met")
    return
}

Upvotes: 3

Related Questions