swift-testing
Installation
SKILL.md
Swift Testing Framework: Basics
Core Concepts
- Import
Testingto unlock macros; tests are plain functions annotated with@Test. - Name tests freely; XCTest's
testname prefix has no meaning in Swift Testing. Use@Test("Display Name")to set the navigator title. #expectis the primary assertion; pass it a boolean expression.- Assert one behaviour per test function; split a test that checks unrelated behaviours.
- Mark the test function
async/throwsfor async or throwing tests. - Swift Testing and XCTest run side by side in the same test target; a project that still holds XCTest tests is a supported end state.
- When one change would be too large to review or bisect, convert an XCTest target in stages: give the staged order, one class or small batch per stage, and keep the target green between stages (
principle-sequence-verifiable-units). - Swift Testing covers unit and integration tests but has no UI-automation or performance-measurement API. Keep XCUITest tests and XCTest
measureperformance tests on XCTest.
Example: Simple Test
import Testing
func add(_ a: Int, _ b: Int) -> Int { a + b }