XCTests failing to launch app in simulator intermittently XCTests failing to launch app in simulator intermittently ios ios

XCTests failing to launch app in simulator intermittently


I experienced the same issue. I found out that there is a rader open for this. In the comments I found a tip that I implemented in a function that does a retry.

The arguments array is an array of enum values where the base type is String. I use that for the app arguments.

Unfortunately this is still not full prove. In my case the number of failures went down considerably, but did not go away.

var app: XCUIApplication = XCUIApplication()public func tryLaunch<T>(_ arguments: [T], _ counter: Int = 10) where T: RawRepresentable {    sleep(3)    XCUIApplication().terminate()    sleep(3)    app = XCUIApplication()    app.launchArguments = arguments.map { $0.rawValue as! String }    app.launch()    sleep(3)    if !app.exists && counter > 0 {        tryLaunch(arguments, counter - 1)    }}

The function above is included in https://github.com/evermeer/UITestHelper


After playing around we were observed that if we run limited test cases, this error went down considerably. You can find more details at https://blog.talentica.com/2017/04/04/use-xcode-8-with-jenkins/