Search code examples
iosxcodexctestcase

How to set a condition in setUp() of a XCTestCase?


I have an XCTestCase with two test methods.

I'd like to set up different launch arguments depending on the function that's about to be run. But I don't know how I can do this.

override func setUp() {
    super.setUp()
    //app.launchArguments += ["USER_REGISTERED"]
    // or 
    //app.launchArguments += ["USER_NOT_REGISTERED"]
}

// Should be launched with "USER_REGISTERED" launch arg
func testUserRegistered() {
    app.launch() 
}

// Should be launched with "USER_NOT_REGISTERED" launch arg
func testUserNotRegistered() {
    app.launch() 
}

What can I do? Thanks for your help


Solution

  • You can use self.name to distinguish between the test cases being run. It will give you something like:

    -[MyProjectTests testExample]