XC testing is incredibly difficult. Sometimes it seems that the direction of the wind or the speed of the Earthโs rotation will determine whether you get a random glitch or not. One fix I found to mitigate these annoying problems somewhat if you call it your tearDown () function:
XCUIApplication().terminate()
Where XCUIApplication () is the application you are working in.
source share