swift-testing — independently scanned and version-tracked by SaferSkills.
SaferSkills independently audited swift-testing (Agent Skill) and scored it 100/100 (green). The audit ran 55 deterministic rules across Security, Supply Chain, Maintenance, Transparency, and Community; it found 0 high-severity and 0 lower-severity findings. The full rule-by-rule trace and per-finding evidence are below. Free, methodology-open.
Findings & checks · 0 flagged
Every scanned point with the score it earned and what moved between them.
First recorded scan — no prior version to compare against.
The primary manifest — the file an agent reads to learn what this artifact does.
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:
references/test-organization.md for suites, tags, traitsreferences/async-testing.md for async test patternsreferences/fixtures.md for fixture patterns and placementreferences/test-doubles.md for mock/stub/spy patternsreferences/parameterized-tests.md for parameterized testingreferences/integration-testing.md for integration test patternsreferences/snapshot-testing.md for snapshot testing setupreferences/dump-snapshot-testing.md for text-based snapshot testingreferences/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)
}
}
#endifPlace 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.
+-------------+
| 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:
#if DEBUG guards#if DEBUG guards~30 seconds. Free. No account. Every finding cites a rule and a line of evidence.