22.2 · XCTest and Swift Testing
Apple now ships two test frameworks side by side. You are expected to read XCTest fluently, write new unit tests in Swift Testing, and know what each one cannot do.
Mental model. XCTest is class-based and covers everything (UI and performance too); Swift Testing is macro-based, parallel by default and for unit-level tests. They can live in the same target.
Two frameworks
What changed with @Test, #expect and #require, and what stays in XCTest.
- How do XCTest and Swift Testing differ, and when do you still use XCTest?
XCTest is the long-standing, Objective-C-rooted framework: you subclass XCTestCase, name methods test…, use setUpWithError and tearDown, and assert with…
More in Testing
- 22.1 · The pyramid, and what not to test
- 22.3 · Async tests, expectations and controlling time
- 22.4 · Fakes, mocks and the inputs that make tests random
- 22.5 · Snapshot tests and UI tests
- 22.6 · Testing SwiftUI, tvOS focus, and watchOS logic
- 22.7 · Flakes, hermetic CI, and a quality system for a large team
- 22.8 · Swift Testing in depth: arguments, traits, errors, confirmations, isolation and scoping
- 22.9 · XCTest lifecycle and expectations, Sendable doubles, and the main actor in tests