XCTAssert break函数

时间:2015-08-05 19:36:00

标签: ios swift unit-testing xctest xctestexpectation

如果逻辑失败,如何停止单元测试执行。以下是示例。如何在XCTAssertEqual("Hello", "Hi", "Passed")条件失败时停止执行。

func test_one() 
{    
    XCTAssertEqual("Hello", "Hi", "Passed")    
    let b = "Good Morning!" 
    // code continues...
}

1 个答案:

答案 0 :(得分:28)

XCTestCase有一个变量var continueAfterFailure: Bool,默认为true。 这意味着即使在测试失败后测试仍继续运行

override func setUp() {
    super.setUp()
    // Put setup code here. This method is called before the invocation of each test method in the class.
    continueAfterFailure = false
}