如何确保我的异步测试在断言失败后不会继续?在做了一些研究之后,我明白我必须使用
@MainActor
和 async
来确保我的 restAPI 集按顺序运行。但是,就我而言,我不希望断言失败后继续测试。但是我该怎么做呢?
@MainActor func testAsync() async throws {
XCTAssert(false)
print("xxxxxxx")
}
与现有的所有其他单元测试框架不同,XCTest 中失败断言的默认行为是继续测试。
但是您可以通过以下方式更改此设置:
continueAfterFailure = false
https://developer.apple.com/documentation/xctest/xctestcase/1496260-continueafterfailure