No slash command · from swift-foundation
Writes and runs Swift tests using Swift Testing (@Suite, @Test, #expect, #require) and XCTest. Covers async/actor tests, test doubles, parameterized tests, and deterministic time/randomness for logic and networking code.
Ships in swift-foundation. 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.
None: SKILL.md is the whole skill.
import Testing → Swift Testing. New test files in that target use it too.import XCTest → XCTest. Add new tests in the same style as the target; do not convert existing suites.XCUIApplication) and performance tests (measure) still require XCTest.import Testing
@testable import Billing
@Suite("Invoice totals")
struct InvoiceTotalTests {
let calculator = InvoiceCalculator(taxRate: 0.2)
@Test("adds tax to the subtotal")
func addsTax() {
let total = calculator.total(for: [LineItem(price: 100, quantity: 2)])
#expect(total == 240)
}
@Test(arguments: [0, -1])
func rejectsNonPositiveQuantity(_ quantity: Int) {
#expect(throws: InvoiceError.invalidQuantity) {
try calculator.validate(LineItem(price: 10, quantity: quantity))
}
}
@Test func parsesStoredInvoice() throws {
let invoice = try #require(Invoice(json: Fixtures.invoiceJSON))
#expect(invoice.lines.count == 3)
}
}
struct suite gets a fresh instance per test — put setup in init() (it may be async throws), teardown in deinit only when the suite is a class / actor.#expect for checks that should continue; #require when the rest of the test cannot run without the value (it unwraps optionals and stops on failure).#expect(throws: SomeError.self) or a specific error value; #expect(throws: Never.self) to assert no error.arguments: instead of loops — each argument is reported separately. Two collections → all combinations; zip(a, b) for pairs..tags(.network), .disabled("reason"), .enabled(if:), .timeLimit(.minutes(1)), .serialized for suites that share external state, .bug("URL") to link an issue.await confirmation("delegate called", expectedCount: 1) { confirm in … }.withKnownIssue { … }, not a disabled test with no reason.final class InvoiceTotalTests: XCTestCase {
private var calculator: InvoiceCalculator!
override func setUp() {
super.setUp()
calculator = InvoiceCalculator(taxRate: 0.2)
}
func test_total_addsTaxToSubtotal() {
XCTAssertEqual(calculator.total(for: [LineItem(price: 100, quantity: 2)]), 240)
}
func test_load_returnsUser() async throws {
let user = try await sut.load(id: "42")
XCTAssertEqual(user.name, "Ada")
}
}
async throws test methods instead of XCTestExpectation for async code; expectations only for delegate/notification callbacks (await fulfillment(of: [exp], timeout: 1)).setUp; reset them in tearDown if they hold resources.XCTUnwrap instead of force-unwrapping in tests.@MainActor when the subject is main-actor isolated — do not hop with MainActor.run inside each test.#expect(await counter.value == 3).sleep / Task.sleep to wait for a result. Inject a clock (any Clock<Duration>; ContinuousClock in production, a test clock or ImmediateClock in tests) or await the operation directly.Date.now the same way when results depend on them.protocol PaymentGateway: Sendable), then hand-write a stub or spy in the test target:final class PaymentGatewaySpy: PaymentGateway, @unchecked Sendable {
// Test-only spy: mutated from one test at a time.
private(set) var charges: [Decimal] = []
var result: Result<Receipt, PaymentError> = .success(.fixture)
func charge(_ amount: Decimal) async throws -> Receipt {
charges.append(amount)
return try result.get()
}
}
actor spy when the subject calls it concurrently.URLProtocol subclass registered on a URLSessionConfiguration.ephemeral session, or a protocol around the HTTP client — never real network calls in unit tests.ModelConfiguration(isStoredInMemoryOnly: true) for SwiftData, an in-memory GRDB DatabaseQueue(), a temporary directory for files).test_<unit>_<behaviour> in XCTest).static let fixture / static func fixture(…) extensions in the test target, never in production code.swift test # SwiftPM, all tests
swift test --filter InvoiceTotalTests # one suite
swift test --enable-code-coverage # coverage (swift test --show-codecov-path)
xcodebuild test -scheme App -destination 'platform=iOS Simulator,name=<an available simulator>'
xcodebuild test -scheme App -only-testing:AppTests/InvoiceTotalTests
swift test --no-parallel only when a suite cannot be fixed to run in parallel — prefer .serialized on that suite.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
3 skills in this plugin
/swift-conventionsSwift language conventions for any Swift codebase: Swift 6 language mode, value types first, optionals without force-unwraps, error handling (throws, typed throws, Result), protocols and generics (some vs any), access control, strict concurrency (async/await, structured tasks, actors, Sendable, @MainActor, default actor isolation and approachable concurrency), memory (ARC, weak/unowned captures), and the Swift API Design Guidelines. Stack-agnostic — referenced by swift-plugin and apple-plugin.
Use this skill to:
- Write Swift that compiles cleanly under the project's language mode and concurrency checking.
- Choose between struct, enum, class and actor.
- Model failures and absence without crashes.
- Name APIs the way the rest of the Swift ecosystem does.
Do NOT use this skill for:
- Package / build / formatter setup — see swift-foundation:swift-tooling.
- Tests — see swift-foundation:swift-testing.
- SwiftUI views and state — see apple-plugin:swiftui-conventions and apple-plugin:swiftui-state.
/swift-toolingSwift project tooling: Package.swift manifests (tools version, platforms, products, targets, dependencies, resources, plugins), dependency constraints and the Package.resolved policy, swift build / test / run, xcodebuild for Xcode projects (schemes, destinations, test plans), Xcode project styles (buildable folders, Tuist, XcodeGen, legacy groups), formatters and linters (swift-format, SwiftFormat, SwiftLint), xcconfig files. Stack-agnostic — referenced by swift-plugin and apple-plugin.
Use this skill to:
- Add a dependency or a target the way the project already manages them.
- Make sure a new file is actually compiled.
- Run the project's own formatter, linter, build and tests the way CI does.
Do NOT use this skill for:
- Language idioms — see swift-foundation:swift-conventions.
- Testing patterns — see swift-foundation:swift-testing.
npx claudepluginhub aratkruglik/claude-sdlc --plugin swift-foundationOther plugins' skills for the same job