Ye Tan
Ye Tan

Reputation: 21

Terminate and Reopen the app with XCUITest iOS9

I've been using the new XCUITest in Xcode. Right now I am about to make a test case that will do some certain procedure, terminates the app and reopen it. I know this is impossible in instrument so I wonder if it is possible to do it with XCUITest.

Upvotes: 2

Views: 3130

Answers (2)

JJohnston
JJohnston

Reputation: 407

If you are using swift and XCTestCase

import XCTest

class SomeTests: XCTestCase {

    func testSomeFunctionality() {
        let app = XCUIApplication()
        // by setting launch arguments you can set your app to "test mode"
        app.launchArguments = ["arg1", "arg2"]
        app.launch()

        // .... code that runs the desired procedure.

        app.terminate()

        // At this point you can set different launch args if you need the app to be in a different mode
        app.launchArguments = ["arg1", "arg2"]
        app.launch()

        // .... code that finishes up the test.
    }

}

Upvotes: 6

atgrubb
atgrubb

Reputation: 1203

The XCUIApplication class contains launch and terminate methods that you can call to close and reopen the application.

I'm unsure of the swift syntax but you can do the following in Objective-C:

XCUIApplication *app = [[XCUIApplication alloc] init];

app.terminate;

app.launch;

Upvotes: 0

Related Questions