我正在使用Xcode8.3.3,swift,并且我正试图让Teardown方法只运行一次。
我使用此处提供的解决方案启动应用程序一次:
XCTestCase not launching application in setUp class method
在Teardown方法中,我想退出应用程序。我只想做一次。
xctest文档有一个类teardown()方法,但是当我尝试使用它时-它不再有访问应用程序的权限了?以下内容:
https://developer.apple.com/documentation/xctest/xctestcase/understanding_setup_and_teardown_for_test_methods
这是我在Teardown方法中得到的所有信息,因此它无法再访问应用程序上的任何元素:
swift - 如何一次运行Swift XCTest tearDown-LMLPHP
在所有测试结束时,我怎样才能在Teardown中只运行一次代码?

最佳答案

你可以这样做

import XCTest

class TestSuite: XCTestCase {

    static var testCount = testInvocations.count

    override func setUp()
    {
        super.setUp()

        TestSuite.testCount -= 1
    }

    override func tearDown()
    {
        if TestSuite.testCount == 0 {
            print("Final tearDown")
        }

        super.tearDown()
    }

    func testA() {}
    func testB() {}
    func testC() {}
}

关于swift - 如何一次运行Swift XCTest tearDown,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45354408/

10-09 04:13