Create and run unit tests, performance tests, and UI tests for your Xcode project
open sourceApache-2.0 WITH Swift-exceptionself-hostablefree
XCTest is Apple's testing framework for Swift and Objective-C, built into Xcode and its testing workflow. Tests are XCTestCase subclasses whose test methods make assertions and record failures; it also supports asynchronous tests with expectations, performance tests that measure blocks of code to catch regressions, and UI tests that drive an app through accessibility to check user flows, with activities and attachments in test reports. On Apple platforms it ships with Xcode as a closed framework; the open source swift-corelibs-xctest (Apache-2.0) implements most of the same APIs so the same tests run with swift test on Linux, Windows and every other platform Swift supports. Apple's newer Swift Testing framework sits beside it.
Problems it solves
- write unit tests for my iOS or macOS app in Swift
- test asynchronous code that completes later, with expectations and timeouts
- automate UI tests that tap through my iPhone app
- catch performance regressions by measuring how long code takes in tests
- run my Swift package's tests on Linux in CI with swift test
- attach screenshots and logs to test results in Xcode
Features
- XCTestCase test classes with setUp and tearDown
- assertions that record failures with optional messages
- asynchronous tests with expectations
- performance tests that measure blocks of code
- UI tests that drive an app's interface (XCUIApplication)
- activities and attachments in test reports
- integrated with Xcode's test navigator and xcodebuild
- swift-corelibs-xctest runs the same tests on Linux, Windows and other Swift platforms through swift test
Ways to run it
XCTest in Xcode
free with Xcode1
Only in this edition
You arrange
- a Mac with Xcode1
swift-corelibs-xctest
free2
Only in this edition
- runs on Linux, Windows and other platforms Swift supports2
Not included
- parts of the Xcode XCTest API: it implements the majority of the unit testing APIs from Xcode 7 and later2
Capabilities
| Has official SDKs | plan not known |
|---|
Alternatives
The same job
These do what XCTest does.
- Swift Testing Expressive and intuitive APIs that make testing your Swift code a breeze