swift-testing/SKILL.md
Expert guidance on Swift Testing best practices, patterns, and implementation. Use when developers mention: (1) Swift Testing, @Test, #expect, #require, or @Suite, (2) "use Swift Testing" or "modern testing patterns", (3) test doubles, mocks, stubs, spies, or fixtures, (4) unit tests, integration tests, or snapshot tests, (5) migrating from XCTest to Swift Testing, (6) TDD, Arrange-Act-Assert, or F.I.R.S.T. principles, (7) parameterized tests or test organization.
npx skillsauth add abanoub-ashraf/manus-skills-import swift-testingInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
This skill provides expert guidance on Swift Testing, covering the modern Swift Testing framework, test doubles (mocks, stubs, spies), fixtures, integration testing, snapshot testing, and migration from XCTest. Use this skill to help developers write reliable, maintainable tests following F.I.R.S.T. principles and Arrange-Act-Assert patterns.
@Test, #expect, #require, @Suite) for all new tests, not XCTest.#if DEBUG, not in test targets.#if DEBUG, not in test targets.#expect for soft assertions (continue on failure) and #require for hard assertions (stop on failure).When a developer needs testing guidance, follow this decision tree:
Starting fresh with Swift Testing?
references/test-organization.md for suites, tags, traitsreferences/async-testing.md for async test patternsNeed to create test data?
references/fixtures.md for fixture patterns and placementreferences/test-doubles.md for mock/stub/spy patternsTesting multiple inputs?
references/parameterized-tests.md for parameterized testingTesting module interactions?
references/integration-testing.md for integration test patternsTesting UI for regressions?
references/snapshot-testing.md for snapshot testing setupTesting data structures or state?
references/dump-snapshot-testing.md for text-based snapshot testingMigrating from XCTest?
references/migration-xctest.md for migration guidereferences/migration-xctest.md for XCTest to Swift Testing migrationreferences/async-testing.md for async patterns, confirmation, timeoutsreferences/test-doubles.mdreferences/fixtures.md for fixture patterns with fixed datesreferences/parameterized-tests.md for parameterized testingreferences/integration-testing.md for integration test patternsimport Testing
@Test func basicTest() {
#expect(1 + 1 == 2)
}
@Test("Adding items increases cart count")
func addItem() {
let cart = Cart()
cart.add(item)
#expect(cart.count == 1)
}
@Test func asyncOperation() async throws {
let result = try await service.fetch()
#expect(result.isValid)
}
Structure every test with clear phases:
@Test func calculateTotal() {
// Given
let cart = ShoppingCart()
cart.add(Item(price: 10))
cart.add(Item(price: 20))
// When
let total = cart.calculateTotal()
// Then
#expect(total == 30)
}
Continues test execution after failure:
@Test func multipleExpectations() {
let user = User(name: "Alice", age: 30)
#expect(user.name == "Alice") // If fails, test continues
#expect(user.age == 30) // This still runs
}
Stops test execution on failure:
@Test func requireExample() throws {
let user = try #require(fetchUser()) // Stops if nil
#expect(user.name == "Alice")
}
@Test func throwsError() {
#expect(throws: ValidationError.self) {
try validate(invalidInput)
}
}
@Test func throwsSpecificError() {
#expect(throws: ValidationError.emptyField) {
try validate("")
}
}
| Principle | Description | Application |
|-----------|-------------|-------------|
| Fast | Tests execute in milliseconds | Mock expensive operations |
| Isolated | Tests don't depend on each other | Fresh instance per test |
| Repeatable | Same result every time | Mock dates, network, external deps |
| Self-Validating | Auto-report pass/fail | Use #expect, never rely on print() |
| Timely | Write tests alongside code | Use parameterized tests for edge cases |
Per Martin Fowler's definition:
| Type | Purpose | Verification | |------|---------|--------------| | Dummy | Fill parameters, never used | N/A | | Fake | Working implementation with shortcuts | State | | Stub | Provides canned answers | State | | Spy | Records calls for verification | State | | SpyingStub | Stub + Spy combined (most common) | State | | Mock | Pre-programmed expectations, self-verifies | Behavior |
Important: What Swift community calls "Mock" is usually a SpyingStub.
For detailed patterns, see references/test-doubles.md.
Place test doubles close to the interface, not in test targets:
// In PersonalRecordsCore-Interface/Sources/...
public protocol PersonalRecordsRepositoryProtocol: Sendable {
func getAll() async throws -> [PersonalRecord]
func save(_ record: PersonalRecord) async throws
}
#if DEBUG
public final class PersonalRecordsRepositorySpyingStub: PersonalRecordsRepositoryProtocol {
// Spy: Captured calls
public private(set) var savedRecords: [PersonalRecord] = []
// Stub: Configurable responses
public var recordsToReturn: [PersonalRecord] = []
public var errorToThrow: Error?
public func getAll() async throws -> [PersonalRecord] {
if let error = errorToThrow { throw error }
return recordsToReturn
}
public func save(_ record: PersonalRecord) async throws {
if let error = errorToThrow { throw error }
savedRecords.append(record)
}
}
#endif
Place fixtures close to the model:
// In Sources/Models/PersonalRecord.swift
public struct PersonalRecord: Equatable, Sendable {
public let id: UUID
public let weight: Double
// ...
}
#if DEBUG
extension PersonalRecord {
public static func fixture(
id: UUID = UUID(),
weight: Double = 100.0
// ... defaults for all properties
) -> PersonalRecord {
PersonalRecord(id: id, weight: weight)
}
}
#endif
For detailed patterns, see references/fixtures.md.
+-------------+
| UI Tests | 5% - End-to-end flows
| (E2E) |
+-------------+
| Integration | 15% - Module interactions
| Tests |
+-------------+
| Unit | 80% - Individual components
| Tests |
+-------------+
Load these files as needed for specific topics:
test-organization.md - Suites, tags, traits, parallel executionparameterized-tests.md - Testing multiple inputs efficientlyasync-testing.md - Async patterns, confirmation, timeouts, cancellationmigration-xctest.md - Complete XCTest to Swift Testing migration guidetest-doubles.md - Complete taxonomy with examples (Dummy, Fake, Stub, Spy, SpyingStub, Mock)fixtures.md - Fixture patterns, placement, and best practicesintegration-testing.md - Module interaction testing patternssnapshot-testing.md - UI regression testing with SnapshotTesting librarydump-snapshot-testing.md - Text-based snapshot testing for data structures#if DEBUG guards#if DEBUG guardsdevelopment
Design principles for building polished, native-feeling SwiftUI apps and widgets. Use this skill when creating or modifying SwiftUI views, iOS widgets (WidgetKit), or any native Apple UI. Ensures proper spacing, typography, colors, and widget implementations that look and feel like quality apps rather than AI-generated slop.
data-ai
Design and implement SwiftUI views, components, and app architecture. Use when creating new SwiftUI views, implementing MVVM/TCA patterns, managing state with @Observable, @State, @Binding, or @Environment, designing navigation flows, or structuring iOS app architecture. Triggers on SwiftUI, view model, state management, navigation, coordinator pattern.
development
Implement, review, or improve SwiftUI animations and transitions. Use when adding implicit or explicit animations with withAnimation, configuring spring animations (.smooth, .snappy, .bouncy), building phase or keyframe animations with PhaseAnimator/KeyframeAnimator, creating hero transitions with matchedGeometryEffect or matchedTransitionSource, adding SF Symbol effects (bounce, pulse, variableColor, breathe, rotate, wiggle), implementing custom Transition or CustomAnimation types, or ensuring animations respect accessibilityReduceMotion.
testing
Audit SwiftUI views for accessibility (iOS + macOS) with patch-ready fixes