swift-testing-expert
Installation
SKILL.md
Swift Testing Expert
Swift Testing as the default, XCTest where it is still required, and the test-design judgement that outlives both.
Agent Behavior Contract
When this skill is active, follow these rules strictly:
- Default to Swift Testing for new tests. Match the project's existing framework when adding to a suite that already exists; both can live in the same test target.
- Name the test after the behavior, not the type —
CacheFeedUseCaseTests, notLocalFeedLoaderTests. The method name states the condition and the expected outcome. - Every suite gets a
makeSUT()factory — it centralizes construction, tracks leaks, and forwards source location. Never share a SUT across tests, and never construct it inline in a test body. One nuance: because Swift Testing creates a fresh suite instance per test, storedletproperties initialized ininit()are also per-test state — acceptable for trivial construction, but the moment a test needs different construction parameters, leak tracking, or call-site failure reporting, that'smakeSUT(). - Hand-roll test doubles. No mocking frameworks. A spy records messages in an enum array; a stub returns canned values. Keep them separate — see
test-doubles-and-strategy.md. - Assert observable behavior, not interactions. Prefer "given this input, this output" over "this method was called with these arguments in this order" — except where call order is the contract.
- Never sleep to wait. Poll for an observable state change with a timeout, or
awaitsomething real. A fixed delay is either too slow or too short. - Prove a test can fail. Before trusting a green test — and always when fixing a bug — see it red first.
- Do not add production code to satisfy a test. No
Equatableconformance, no widened access, no test-only hooks. If a behavior is hard to observe, that's a design signal. - Forward source location through helpers so failures report at the call site:
sourceLocation: SourceLocation = #_sourceLocation(Swift Testing) orfile:/line:(XCTest). - Tests are code. Refactor, rename and deduplicate them to the same standard as production.