英文:
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:
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:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论