Swift UITest обрабатывает запуск всех тестов и завершение всех тестовых случаев - PullRequest
0 голосов
/ 16 января 2019

При написании UITest с XCTest я хочу обработать «Запуск всех тестов» и «Завершение всех тестов». Я хочу «Зарегистрировать» пользователя перед тестовыми случаями и удалить учетную запись после всех тестовых случаев. Я не могу использовать целое значение счетчика, потому что после всех тестовых случаев его сбрасывает. Как я мог справиться с этим "Start-Finish"?

1 Ответ

0 голосов
/ 16 января 2019

Все это описано в документации Apple. Вы хотите использовать setUp и tearDown специально.

https://developer.apple.com/documentation/xctest/xctestcase/understanding_setup_and_teardown_for_test_methods

class SetUpAndTearDownExampleTestCase: XCTestCase {

    override class func setUp() { // 1.
        super.setUp()
        // This is the setUp() class method.
        // It is called before the first test method begins.
        // Set up any overall initial state here.
    }

    override func setUp() { // 2.
        super.setUp()
        // This is the setUp() instance method.
        // It is called before each test method begins.
        // Set up any per-test state here.
    }

    func testMethod1() { // 3.
        // This is the first test method.
        // Your testing code goes here.
        addTeardownBlock { // 4.
            // Called when testMethod1() ends.
        }
    }

    func testMethod2() { // 5.
        // This is the second test method.
        // Your testing code goes here.
        addTeardownBlock { // 6.
            // Called when testMethod2() ends.
        }
        addTeardownBlock { // 7.
            // Called when testMethod2() ends.
        }
    }

    override func tearDown() { // 8.
        // This is the tearDown() instance method.
        // It is called after each test method completes.
        // Perform any per-test cleanup here.
        super.tearDown()
    }

    override class func tearDown() { // 9.
        // This is the tearDown() class method.
        // It is called after all test methods complete.
        // Perform any overall cleanup here.
        super.tearDown()
    }

}
...