Xcode:如果前一个失败则跳过测试

时间:2018-06-22 12:47:51

标签: swift xcode unit-testing testing xctest

如果先前的测试失败,那么Xcode中是否有任何选项可以跳过测试类中的测试?

现在我在可能会跳过的测试正文中使用类似的内容:

if previousTestFailed == true {
    XCTFail("Test can't proceed because previous one failed")
}

也许有些更愉快的事情?

1 个答案:

答案 0 :(得分:1)

测试必须相互独立运行。当单独运行一个测试时,这一点尤其重要。 Xcode 10 will help enforce this independence by giving the option to shuffle test order

要在先决条件失败后终止测试,只需测试该先决条件,即使那意味着要从更基本的测试中重复一些代码。如果不满足前提条件,则XCTFail。

如果前提条件适用于多个测试,则将其提取到帮助程序中。然后测试可以做类似的事情

if !meetsPrecondition() {
    XCTFail("Precondition not met")
    return
}
相关问题