XCTest
Write and run unit, performance and UI tests for your Xcode projects.
Overview
XCTest is Apple's original testing framework for Xcode projects. Tests are methods on XCTestCase subclasses that check conditions with assertions such as XCTAssertEqual and record a failure when a condition isn't met. Test methods can be marked async to test Swift concurrency code, and performance tests measure a block of code against a baseline. UI tests use XCUIApplication and related classes, now part of the XCUIAutomation framework that XCTest imports, to launch an app and drive its interface.
Swift Testing, added in Xcode 16, is now recommended for new unit tests. The two frameworks can share a test target, and Apple still recommends XCTest for UI and performance tests.
Unit tests
XCTestCase subclasses with assertions, setup, teardown and async test methods.
UI automation
Launch the app with XCUIApplication, find elements and simulate user input.
Performance tests
measure(metrics:block:) records metrics and compares them to a baseline.
Accessibility audits
performAccessibilityAudit checks an app's UI for accessibility issues in a test.
History
How it grew up.
XCTest
Xcode 5 introduces XCTest as the default test framework, replacing OCUnit.
UI testing
Xcode 7 adds UI testing to XCTest, with XCUIApplication and UI recording.
Test plans
Xcode 11 adds test plans for running tests under several configurations.
Async tests
Test methods can be marked async to test Swift concurrency code directly.
Framework interoperability
Xcode 27 lets XCTest and Swift Testing APIs be called across frameworks.