While continueAfterFailure = false
worked earlier for me, it no longer does.
Demo: This little test should stop in func testExample
, but func testExample2
is also executed, see the log.
import XCTest
final class FailureTests: XCTestCase {
override func setUp() {
continueAfterFailure = false
}
override func tearDown() {
}
func testExample() {
XCTFail("Test fails as required")
}
func testExample2() {
XCTFail("Unexpextedly executed")
}
}
Test log:
What could be the reason? What to do to let it stop again?
Consider this test case:
func testExample() {
XCTFail("first")
XCTFail("second")
}
By default, XCTest keeps going even when an assertion fails. That is, it will report both failures. This is different from the behavior of other xUnit frameworks.
With continueAfterFailure
set to false, it will stop the test case after the first failure, and not reach the second. But it will continue to run all other test cases.