On XCode 26.x, calling XCFail with continueAfterFailure set to false causes xcodebuild command to hang indefinitely if the XCUIApplication object is stored outside the test method.
- Create a new template iOS App project with UI tests
- Add
XCFail(...)to a UI test test-case - Set the
XCUIApplicationinself.app(avoiding this fixes the hang) - Run tests with
xcodebuild test - The terminal hangs forever
Reproduction example
import XCTest
final class TestAppUITests: XCTestCase {
var app: XCUIApplication? = nil
override func setUpWithError() throws {
continueAfterFailure = false
}
override func tearDownWithError() throws {
app?.terminate()
}
@MainActor
func testExample() throws {
let app = XCUIApplication()
self.app = app // <- HERE this causes the problem
app.launch()
XCTFail()
}
}
Reproduction environment
- macOS Sequoia 15.7.3
- Tested XCode 26.3 and XCode 26.2 have the hang
- Tested XCode 16.4 does work as expected
XCode 16.4
The issue does not happen on XCode 16.4, and is likely introduced in XCode 26.
Related threads:
Work-around
Do not store XCUIApplication in the XCTestCase instance, maintain it scoped to the test methods.