Here's another way to allow both common or non-common app launches on each test.
you can do it by creating your custom XCUIApplication
and include state in your app launches as shown below.
import XCTest
class MyUIApplication: XCUIApplication {
private(set) var isLaunched = false
static let shared = MyUIApplication()
private override init() {
super.init()
// add your launch arguments and environment keys
launchArguments += ["isRunningTests"]
launchEnvironment["state"] = "InitState"
}
func launchIfNeeded(at state: AppState) {
if !isLaunched {
launch(at: state)
}
}
func launch(at state: AppState) {
switch state {
case .home:
launchEnvironment["state"] = "InitState"
...
}
launch()
isLaunched = true
}
}
An example of test case with the above solution:
class MyViewControllerTests: XCTestCase {
let app = VFGUIApplication.shared
override func setUp() {
super.setUp()
app.launchIfNeeded(at: .home)
}
}
This is preferable specially if you are working with a team and you want to make sure that launches are executed properly based on pre-defined launchArguments
and launchEnvironment
, etc.