swift-testing
Skill7 starsChanged 15 days agoMITView on GitHub
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…
9 other projects use a version of this, 2 of them edited.
Adopted by
Most recently taken up by
- memi-design/design-skillstheir own version, first seen Nov 8, 2026
- VelimirMueller/claude-skillsword for word, first seen Nov 1, 2026
- thienqo/ios-skillstheir own version, first seen Oct 11, 2026
- Fe2-O3/swift-field-guidetheir own version, first seen Sep 9, 2026
- fiveonecode/agent-skillstheir own version, first seen Sep 6, 2026
- ozgurakkaya90/claude-skillsedited, first seen Aug 2, 2026
Other versions9 projects use a version of this.
Word for word · 1
- VelimirMueller/claude-skills★ 7100% same
Edited · 2
- bocato/swift-testing-agent-skill★ 8097% same
- ozgurakkaya90/claude-skills★ 097% same
Wrote their own version · 6
- Prisma-Labs-Dev/apple-skills★ 336same name
- fiveonecode/agent-skills★ 20same name
- pluginagentmarketplace/custom-plugin-swift★ 9same name
- memi-design/design-skills★ 7same name
- thienqo/ios-skills★ 4same name
- Fe2-O3/swift-field-guide★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository156 other files it gives its agents.
- skills/swift/swiftui-design-principles/AGENTS.mdAGENTS.md
- skills/swift/ios-code-audit/CLAUDE.mdCLAUDE.md
- skills/swift/swift-focusengine-pro/llms.txtllms.txt
- build-llm-seamSkill
- build-mcp-serverSkill
- build-rag-pipelineSkill
- secure-llm-featuresSkill
- set-up-llm-evalsSkill
- build-nextjs-backendSkill
- build-supabase-edge-functionSkill
- configure-backend-testsSkill
- design-http-apiSkill
- harden-backendSkill
- scaffold-fastapi-serviceSkill
- scaffold-go-serviceSkill
- scaffold-hono-serviceSkill
- secure-supabase-rlsSkill
- set-up-backend-authSkill
- set-up-background-jobsSkill
- set-up-databaseSkill
- set-up-nextjs-supabase-authSkill
- set-up-observabilitySkill
- set-up-supabaseSkill
- build-cliSkill
- release-cliSkill
- set-up-dev-toolchainSkill
- audit-securitySkill
- audit-toolchainSkill
- extend-skillsetSkill
- promote-releaseSkill
- set-up-stack-profileSkill
- write-commit-messagesSkill
- write-pull-requestsSkill
- analyze-complexitySkill
- apply-algorithmsSkill
- apply-design-patternsSkill
- apply-design-principlesSkill
- apply-solidSkill
- choose-data-structureSkill
- debug-systematicallySkill
- enforce-dependency-ruleSkill
- refactor-safelySkill
- slice-and-estimateSkill
- write-clean-testsSkill
- write-readable-codeSkill
- clean-frontend-scaffoldingSkill
- configure-accessibilitySkill
- configure-analyticsSkill
- configure-ciSkill
- configure-error-trackingSkill
- configure-lintingSkill
- configure-test-stackSkill
- configure-typescriptSkill
- create-moduleSkill
- optimize-performanceSkill
- scaffold-frontend-projectSkill
- set-up-authSkill
- set-up-design-systemSkill
- set-up-document-headSkill
- set-up-error-boundariesSkill
- The first 60 shown.
The file
Show its rules and text
We split this skill into the rules it gives an agent
28 rules. 0 are common, 9 are distinctive, and 19 are very specific to this project.
0
Common
Most of the 7 edited versions we read keep these.
9
Distinctive
This author's own choices. Worth a look.
19
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 13
Use Swift Testing framework (@Test, #expect, #require, @Suite) for all new tests, not XCTest.
- Distinctive: line 14
Always structure tests with clear Arrange-Act-Assert phases.
- Distinctive: line 15
Follow F.I.R.S.T. principles: Fast, Isolated, Repeatable, Self-Validating, Timely.
- Distinctive: line 16
Use proper test double terminology per Martin Fowler's taxonomy (Dummy, Fake, Stub, Spy, SpyingStub, Mock).
- Very specific: line 17
Place fixtures close to models with #if DEBUG, not in test targets.
- Very specific: line 18
Place test doubles close to interfaces with #if DEBUG, not in test targets.
- Distinctive: line 19
Prefer state verification over behavior verification - simpler, less brittle tests.
- Very specific: line 20
Use #expect for soft assertions (continue on failure) and #require for hard assertions (stop on failure).
- Distinctive: line 24
When a developer needs testing guidance, follow this decision tree:
- Very specific: line 27
Read references/test-organization.md for suites, tags, traits
- Very specific: line 28
Read references/async-testing.md for async test patterns
- Very specific: line 31
Read references/fixtures.md for fixture patterns and placement
- Very specific: line 32
Read references/test-doubles.md for mock/stub/spy patterns
- Very specific: line 35
Read references/parameterized-tests.md for parameterized testing
- Very specific: line 38
Read references/integration-testing.md for integration test patterns
- Very specific: line 41
Read references/snapshot-testing.md for snapshot testing setup
- Very specific: line 44
Read references/dump-snapshot-testing.md for text-based snapshot testing
- Very specific: line 47
Read references/migration-xctest.md for migration guide
- Very specific: line 52
Use references/migration-xctest.md for XCTest to Swift Testing migration
- Very specific: line 54
Use references/async-testing.md for async patterns, confirmation, timeouts
- Very specific: line 56
Check F.I.R.S.T. principles, use proper mocking per references/test-doubles.md
- Very specific: line 58
Use references/fixtures.md for fixture patterns with fixed dates
- Very specific: line 60
Use references/parameterized-tests.md for parameterized testing
- Very specific: line 62
Use references/integration-testing.md for integration test patterns
- Distinctive: line 185
Place test doubles close to the interface, not in test targets:
- Distinctive: line 219
Place fixtures close to the model:
- Distinctive: line 288
Test names describe behavior, not implementation
- Distinctive: line 290
Test doubles are minimal (only stub what's needed)
“Common” is measured: kept by at least 6 in 10 of the 7 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Swift Testing
Overview
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.
Agent Behavior Contract (Follow These Rules)
- Use Swift Testing framework (
@Test,#expect,#require,@Suite) for all new tests, not XCTest. - Always structure tests with clear Arrange-Act-Assert phases.
- Follow F.I.R.S.T. principles: Fast, Isolated, Repeatable, Self-Validating, Timely.
- Use proper test double terminology per Martin Fowler's taxonomy (Dummy, Fake, Stub, Spy, SpyingStub, Mock).
- Place fixtures close to models with
#if DEBUG, not in test targets. - Place test doubles close to interfaces with
#if DEBUG, not in test targets. - Prefer state verification over behavior verification - simpler, less brittle tests.
- Use
#expectfor soft assertions (continue on failure) and#requirefor hard assertions (stop on failure).
Quick Decision Tree
When a developer needs testing guidance, follow this decision tree:
- Starting fresh with Swift Testing?
- Read
references/test-organization.mdfor suites, tags, traits - Read
references/async-testing.mdfor async test patterns
- Read
- Need to create test data?
- Read
references/fixtures.mdfor fixture patterns and placement - Read
references/test-doubles.mdfor mock/stub/spy patterns
- Read
- Testing multiple inputs?
- Read
references/parameterized-tests.mdfor parameterized testing
- Read
- Testing module interactions?
- Read
references/integration-testing.mdfor integration test patterns
- Read
- Testing UI for regressions?
- Read
references/snapshot-testing.mdfor snapshot testing setup
- Read
- Testing data structures or state?
- Read
references/dump-snapshot-testing.mdfor text-based snapshot testing
- Read
- Migrating from XCTest?
- Read
references/migration-xctest.mdfor migration guide
- Read
Triage-First Playbook (Common Errors -> Next Best Move)
- "XCTAssertEqual is unavailable" / need to modernize tests
- Use
references/migration-xctest.mdfor XCTest to Swift Testing migration
- Use
- Need to test async code
- Use
references/async-testing.mdfor async patterns, confirmation, timeouts
- Use
- Tests are slow or flaky
- Check F.I.R.S.T. principles, use proper mocking per
references/test-doubles.md
- Check F.I.R.S.T. principles, use proper mocking per
- Need deterministic test data
- Use
references/fixtures.mdfor fixture patterns with fixed dates
- Use
- Need to test multiple scenarios efficiently
- Use
references/parameterized-tests.mdfor parameterized testing
- Use
- Need to verify component interactions
- Use
references/integration-testing.mdfor integration test patterns
- Use
Core Syntax
Basic Test
import Testing
@Test func basicTest() {
#expect(1 + 1 == 2)
}Test with Description
@Test("Adding items increases cart count")
func addItem() {
let cart = Cart()
cart.add(item)
#expect(cart.count == 1)
}Async Test
@Test func asyncOperation() async throws {
let result = try await service.fetch()
#expect(result.isValid)
}Arrange-Act-Assert Pattern
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)
}Assertions
#expect - Soft Assertion
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
}#require - Hard Assertion
Stops test execution on failure:
@Test func requireExample() throws {
let user = try #require(fetchUser()) // Stops if nil
#expect(user.name == "Alice")
}Error Testing
@Test func throwsError() {
#expect(throws: ValidationError.self) {
try validate(invalidInput)
}
}
@Test func throwsSpecificError() {
#expect(throws: ValidationError.emptyField) {
try validate("")
}
}F.I.R.S.T. Principles
| 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 |
Test Double Quick Reference
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.
Test Double Placement
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)
}
}
#endifFixtures
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)
}
}
#endifFor detailed patterns, see references/fixtures.md.
Test Pyramid
+-------------+
| UI Tests | 5% - End-to-end flows
| (E2E) |
+-------------+
| Integration | 15% - Module interactions
| Tests |
+-------------+
| Unit | 80% - Individual components
| Tests |
+-------------+Reference Files
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
Best Practices Summary
- Use Swift Testing for new tests - Modern syntax, better features
- Follow Arrange-Act-Assert - Clear test structure
- Apply F.I.R.S.T. principles - Fast, Isolated, Repeatable, Self-Validating, Timely
- Place fixtures near models - With
#if DEBUGguards - Place test doubles near interfaces - With
#if DEBUGguards - Prefer state verification - Simpler, less brittle than behavior verification
- Use parameterized tests - For testing multiple inputs efficiently
- Follow test pyramid - 80% unit, 15% integration, 5% UI
Verification Checklist (When You Write Tests)
- Tests follow Arrange-Act-Assert pattern
- Test names describe behavior, not implementation
- Fixtures use sensible defaults, not random values
- Test doubles are minimal (only stub what's needed)
- Async tests use proper patterns (async/await, confirmation)
- Tests are fast (mock expensive operations)
- Tests are isolated (no shared state)
- Tests are repeatable (no flaky date/time dependencies)
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

