How to open an application between UITests in Xcode

I have a series of UITests that I want to run as separate tests, but I do not want to restart the application between each test. How to run the application and leave it open so that it does not disconnect and does not restart between tests.

I tried to put XCUIApplication (). launch () in init (), but received an error.

+6
source share
3 answers

In your method, setUp()delete [[[XCUIApplication alloc] init] launch];and put it in the first test that you will run.

For example,

If you have tests: testUI (), testUIPart2 (), testUIPart3 (), etc., and it works in that order, put [[[XCUIApplication alloc] init] launch];testUI () on the first line and there’s no where else.

+6

@James Goe -

, - , , :

class MyTests: XCTestCase {
    static var launched = false

    override func setUp() {
        if (!MyTests.launched) {
            app.launch()
            MyTests.launched = true
        }

(, , , , . , , .)

+3

, XCTestCase func setup() tearDown() . XCUIApplication() (, XCUIAppManager), XCUIAppManager.shared.launchApp() override class func setup()... 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.
}

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

Example implementation of a singleton application manager:

import XCTest

class XCUIAppManager {
    static let shared = XCUIAppManager()
    let app = XCUIApplication(bundleIdentifier: "com.something.yourAppBundleIdentifierHere")
    private(set) var isLaunched = false

    private init() {}

    func launchApp() {
        app.launch()
        isLaunched = true
    }
}
+1
source

Source: https://habr.com/ru/post/1620149/


All Articles