XCTest continueAfterFailure = false no longer stops tests.

huangapple go评论123阅读模式
英文:

XCTest continueAfterFailure = false no longer stops tests

问题

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:

XCTest continueAfterFailure = false no longer stops tests.

What could be the reason? What to do to let it stop again?

英文:

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:

XCTest continueAfterFailure = false no longer stops tests.

What could be the reason? What to do to let it stop again?

答案1

得分: 0

考虑这个测试案例:

func testExample() {
    XCTFail("第一个")
    XCTFail("第二个")
}

默认情况下,XCTest 在断言失败时仍会继续执行。也就是说,它会报告两个失败。这与其他 xUnit 框架的行为不同。

当将 continueAfterFailure 设置为 false 时,它将在第一个失败后停止测试案例,不会执行第二个。但它将继续运行所有其他测试案例。

英文:

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.

huangapple
  • 本文由 发表于 2023年3月8日 16:22:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/75670721.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定