Larry B
Larry B

Reputation: 193

UITesting command line argument options

I'm trying to write UITests for my company's app. I came across several articles about passing command line arguments to my app, such as:

if CommandLine.arguments.contains("--uitesting-enrolled") {
    resetEnrolledState()
} else if CommandLine.arguments.contains("--uitesting-unenrolled") {
    resetUnenrolledState()
}

Within the resetEnrolledState() and resetUnenrolledState() methods, I set/unset UserDefault values, so that I know my environment has been properly configured.

Is there a better option than mixing my prod code with my test code?

Upvotes: 1

Views: 782

Answers (1)

jpetrichsr
jpetrichsr

Reputation: 247

The only ways I know of involve mixing your production and test code, and this is by design. From Apple's documentation:

UI testing exercises your app's UI in the same way that users do without access to your app's internal methods, functions, and variables.

The best advice I can give is to try and put all of your test-centric code in a single place, and do as much in unit testing as possible.

Upvotes: 3

Related Questions