ios - XCTAssert 中断函数

标签 ios swift unit-testing xctest xctestexpectation

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

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

最佳答案

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

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
}

关于ios - XCTAssert 中断函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31841355/

相关文章:

ios - IOS 上的 Xamarin 工具栏项目未正确对齐

ios - 从 Swift 中的回调返回对象

javascript - 开 Jest : how to count call from mock methods called via `call` or `apply` ?

c# - 如何在单元测试中从我的 MVC 框架中获取 Session.SessionID?

swift - 在 swift 中覆盖 get-only 属性

python - Flask-SQLAlchemy 单元测试运行两次

ios - 如何比较同一个 Swift 枚举的不同实例?

ios - 在 github 中创建新分支但它不是最新的?

iPhone - 动态改变颜色

swift - 如何在约会 child 后从 Firebase 中读取内容?