/swift:testing-swift-codefrom Swift
Plan or write Swift unit tests using the Swift Testing framework (Swift 6/Xcode 16+). Covers macro-based annotations, expression-level assertions, test organization with struct suites, traits, and migration from XCTest.
Ships in Swift. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Write tests using the Swift Testing framework (Swift 6 / Xcode 16+). It provides macro-based annotations and expression-level assertions for unit and integration tests. Preserve existing XCTest suites unless migration is requested; UI and performance tests still use XCTest.
This skill layers Apple-platform and Swift testing specifics onto designing-verification-strategies when available—reusing its verification-boundary and non-vacuous assertion principles without restarting that workflow—while remaining useful standalone.
Ordinary function-output regression tests stay here. Positive, negative, empty, or boundary inputs do not by themselves call for type modeling or invariant verification; those skills address representations and enforcement boundaries.
For a test plan, give each test a clear behavior-based name and concrete input/expected-output assertions. A parameterized table can share one named test; identify that test as well as what its rows cover. Mark planned checks as unrun.
import Testing
@Suite("Calculator Tests")
struct CalculatorTests {
@Test("Addition")
func addition() {
#expect(2 + 2 == 4)
}
@Test(arguments: [1, 2, 3])
func isPositive(i: Int) {
#expect(i > 0)
}
}
Use #expect for non-fatal checks that let the test continue, and #require for preconditions that should stop the test immediately if they fail. #require throws on failure, so the test function must be marked throws.
@Test func checking() throws {
let x: Int? = 42
let y = try #require(x) // Unwraps or stops the test
#expect(y == 42) // Records failure but continues
}
// Expect a specific error type
#expect(throws: MyError.self) { try risky() }
// Expect any error
#expect(throws: (any Error).self) { try risky() }
// Expect no error
#expect(throws: Never.self) { try safe() }
Use struct suites by default. Each test gets a fresh instance, providing natural isolation without explicit setup/teardown. Use init for shared setup.
@Suite("Networking")
struct NetworkingTests {
let client: APIClient
init() {
client = APIClient(baseURL: .test)
}
@Test func fetchUser() async throws {
let user = try await client.fetchUser(id: 1)
#expect(user.name == "Alice")
}
}
Control test execution with traits passed to @Test or @Suite:
@Test(.enabled(if: ProcessInfo.processInfo.environment["CI"] != nil))
func ciOnly() { ... }
@Test(.timeLimit(.minutes(1)))
func bounded() async { ... }
@Test(.tags(.integration))
func networkTest() { ... }
@Suite(.serialized) // Serialize this suite’s tests; unrelated suites may still run in parallel
struct SerialTests { ... }
@Test(.disabled("Blocked by #1234"))
func pendingFeature() { ... }
Run the same logic over multiple inputs. Each argument combination runs as a separate test case in the results.
@Test(arguments: [1, 2, 3])
func isPositive(i: Int) {
#expect(i > 0)
}
// Combinatorial: runs all pairs (4 tests)
@Test(arguments: [1, 2], ["a", "b"])
func combinations(i: Int, s: String) { ... }
// Zipped: runs matched pairs (2 tests)
@Test(arguments: zip([1, 2], ["a", "b"]))
func pairs(i: Int, s: String) { ... }
Mark the test function async. A confirmation checks the callback count when its body returns; it does not wait for future callbacks. Await the operation’s completion inside the body and remove any retained callback during cleanup:
@Test func callbacks() async {
await confirmation("Called 3 times", expectedCount: 3) { confirm in
stream.onReceive = { confirm() }
await stream.start()
}
}
Mark tests with known failures using withKnownIssue so they do not count as unexpected failures:
@Test func knownBug() {
withKnownIssue {
#expect(buggyFunction() == 42)
}
}
See REFERENCE.md for the XCTest migration table mapping XCTAssert* calls to their Swift Testing equivalents.
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub kylehughes/agent-plugins-for-making-good-software --plugin swift10 skills in this plugin
/designing-swift-apisDesign Swift API names, labels, signatures, and documentation contracts. Use proactively when adding or changing APIs or reviewing call-site clarity against Apple's API Design Guidelines./modeling-swift-types-for-correctnessModel Swift invariants, validated decoding, legal transitions, ownership, and generic relationships. Load before assessing or changing enforcement boundaries; not ordinary output tests or naming./ordering-symbolsOrder Swift members by declaration kind, access, and name when semantics permit. Use proactively when adding or moving members; preserve initialization, enum, UI, and other meaningful order./organizing-swift-typesOrganize Swift types, conformances, extensions, access control, and files. Use proactively when adding or restructuring declarations; apply repository conventions before the suggested layout./structuring-swift-packagesStructure Swift package boundaries, dependencies, exports, and composition roots. Use proactively for module placement or dependency cycles; preserve the repository’s architecture and naming./testing-async-swift-codeMake Swift async tests deterministic. Use proactively for timing, observer readiness, completion, cancellation, cleanup, or flaky tests; not general test organization.Other plugins' skills for the same job