Skip to content
Skills Library
Programming · Testing

swift-testing

/swift-testing

Generates unit, view-model, and snapshot tests for Swift/SwiftUI iOS and macOS projects, using Swift Testing (@Test/#expect) for new code and XCTest where it already exists. Tests the ObservableObject/@Observable view model directly rather than trying to introspect a SwiftUI view's private tree. Use when the user asks to write Swift or SwiftUI tests, test a ViewModel/@Observable class, or mentions .xcodeproj, Package.swift, XCTest, Swift Testing, @Test, or swift-snapshot-testing.

Repository
test-kit ↗
Licence
MIT
Last repository change
20.08.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
7
Scripts
1
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 20.08.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What to check before installing
  • 1 scripts in this package. Review them before installing, as Claude may execute them.

Scripts: scripts/detect_stack.sh

What it does and when to use it

Generates unit, view-model, and snapshot tests for Swift/SwiftUI iOS and macOS projects, using Swift Testing (@Test/#expect) for new code and XCTest where it already exists. Tests the ObservableObject/@Observable view model directly rather than trying to introspect a SwiftUI view's private tree. Use when the user asks to write Swift or SwiftUI tests, test a ViewModel/@Observable class, or mentions .xcodeproj, Package.swift, XCTest, Swift Testing, @Test, or swift-snapshot-testing.

Original author description

Generates unit, view-model, and snapshot tests for Swift/SwiftUI iOS and macOS projects, using Swift Testing (@Test/#expect) for new code and XCTest where it already exists. Tests the ObservableObject/@Observable view model directly rather than trying to introspect a SwiftUI view's private tree. Use when the user asks to write Swift or SwiftUI tests, test a ViewModel/@Observable class, or mentions .xcodeproj, Package.swift, XCTest, Swift Testing, @Test, or swift-snapshot-testing.

How it works

  1. Progress checklist
  2. Step 1 — Detect stack
  3. Step 2 — Audit project structure
  4. Step 3 — Ask the user what to test (never assume)
  5. Step 4 — State the plan before generating
  6. Step 5 — Generate
  7. Step 6 — Report what was written, then offer to verify
  8. Step 7 — Only if the user asks: run and verify
  9. Reference
  10. Scripts
Original SKILL.md headings · 175 lines, 1,379 words
SKILL.md preview
---
name: swift-testing
description: Generates unit, view-model, and snapshot tests for Swift/SwiftUI iOS and macOS projects, using Swift Testing (@Test/#expect) for new code and XCTest where it already exists. Tests the ObservableObject/@Observable view model directly rather than trying to introspect a SwiftUI view's private tree. Use when the user asks to write Swift or SwiftUI tests, test a ViewModel/@Observable class, or mentions .xcodeproj, Package.swift, XCTest, Swift Testing, @Test, or swift-snapshot-testing.
license: MIT
compatibility: Requires Xcode / the Swift toolchain (xcodebuild or swift test) available. Requires a .xcodeproj, .xcworkspace, or Package.swift.
metadata:
  platform: swift
  report-source: testing-methodologies-deep-research-report.txt Part 5 and Part 8
allowed-tools: Read, Write, Edit, Grep, Glob, Bash
paths:
  - "**/*.swift"
  - "Package.swift"
---

# Swift / SwiftUI Testing

Writes unit, view-model, and snapshot tests for Swift/SwiftUI projects.
The central pattern: SwiftUI has no public view-tree introspection, so
business logic is tested via the view model, not the view — see
[reference/view-model-testing.md](reference/view-model-testing.md) before
generating anything against a view file directly. **Writing the test files
is the deliverable.** Running the suite and verifying it — including the
fault-injection self-check — is a separate, optional step this skill
offers but never runs without being asked. See
[Step 6](#step-6--report-what-was-written-then-offer-to-verify).

## Progress checklist

Copy this into your response and check items off as you go:

```
- [ ] 1. Detect stack + existing test framework (scripts/detect_stack.sh)
- [ ] 2. Audit project structure and existing conventions
- [ ] 3. Ask the user what to test (layer + scope) — do not assume
- [ ] 4. State the test plan explicitly
- [ ] 5. Generate tests following AAA, boundary-only mocking/fakes
- [ ] 6. Report what was written; offer to run + verify — do not run yet
- [ ] 7. Only if asked: run tests, fault-injection self-check, report results
```

## Step 1 — Detect stack

Run `scripts/detect_stack.sh` from the project root. It confirms this is a
Swift project (`.xcodeproj`/`.xcworkspace`/`Package.swift`) and reports
whether Swift Testing (`@Test`), XCTest, or both are already in use, plus
`swift-snapshot-testing`, `ViewInspector`, and Core Data/SwiftData
presence.

If a test framework is already in use, follow it even if a different tool
is this skill's default recommendation (Swift Testing for new code). Never generate
an `XCTAssert*` call inside a `@Test` function or vice versa — see
[reference/swift-testing-vs-xctest.md](reference/swift-testing-vs-xctest.md);
the two frameworks are not cross-compatible and a misplaced assertion
silently never registers as a failure.

## Step 2 — Audit project structure

Before writing anything:
- Classify the target: a plain type/service (fully testable in isolation)
  vs a view model (`ObservableObject`/`@Observable` — test this directly,
  never the view) vs a SwiftUI view itself (needs extraction or
  `ViewInspector` — see
  [reference/view-model-testing.md](reference/view-model-testing.md)) vs
  UI automation/performance (XCTest-only, Swift Testing does not cover
  these — see
  [reference/swift-testing-vs-xctest.md](reference/swift-testing-vs-xctest.md)).
- Match the existing test target/file naming convention.
- Flag critical paths — authentication, payment/billing, any data-write
  operation — for elevated rigor even if the user's request was narrower.
  State this flag out loud; do not silently expand scope.
- **Known gap, say so rather than guessing**: this skill does not have
  reliable, researched guidance on testing on-device AI features built on
  Apple's Foundation Models framework. If asked to test one, say plainly
  that this is an under-researched area rather than presenting invented
  conventions as established practice.

## Step 3 — Ask the user what to test (never assume)

Ask a single message with two questions before generating anything:

1. **Layer**: unit/view-model tests only / snapshot tests only / UI
   automation (XCTest) / a mix appropriate to what's being tested.
2. **Scope**: does the user want the whole app tested, one feature/screen
   tested end-to-end, or just specific file(s)/type(s)? Do not assume — ask
   explicitly and wait for the answer. If the user's original request
   already named specific files or a feature, confirm that scope back to
   them rather than silently re-asking, but still confirm it.

Only skip re-asking if the user's original request already unambiguously
answered both questions.

## Step 4 — State the plan before generating

State explicitly: which layer(s), which type(s)/file(s) are in scope,
whether an extraction (view logic → view model) is being proposed and why,
what will be faked vs exercised for real (in-memory Core Data/SwiftData
store, not the real on-disk store; mock only true I/O boundaries), and the
specific edge cases planned. This is the checkpoint for the user to
redirect before any code exists.

If the confirmed scope is large — the whole app, a big feature, more
types/files than fit comfortably in one pass — say so and propose a
prioritized, batched plan instead of attempting to generate everything at
once. State the first batch, confirm it, then continue rather than
silently truncating or silently attempting all of it in one shot.

## Step 5 — Generate

- Follow the project's existing naming and setup patterns from Step 1-2.
- Structure every test as Arrange/Act/Assert, one Act per test.
- Every unit under test gets at minimum: one happy-path case, one boundary/
  empty case, one error-path case — unless the user scoped it narrower.
- Prefer Swift Testing (`@Test`/`#expect`) for new tests; match XCTest only
  where the project already uses it for that target.
- View-model testing pattern: [reference/view-model-testing.md](reference/view-model-testing.md).
- Snapshot tests and in-memory persistence: [reference/snapshot-and-persistence.md](reference/snapshot-and-persistence.md)
  — scope snapshots to small, stable components, not full screens.
- Comments are the exception, not the default. Start each generated file
  with one short header comment stating what the file covers (e.g.
  `// Tests for CartViewModel: total calculation, empty cart, checkout
  error handling.`) — this is the only comment every file gets. Beyond
  that, add an inline comment only when the reason for a specific setup
  value or edge case genuinely isn't obvious from the test name and code
  itself, never to narrate what a line does. Most files should end up
  with just the header and zero or one inline comments total.
- Before reporting anything, re-read every assertion you just wrote and
  flag or strengthen any that don't check a specific value or state — an
  `#expect` that only confirms something didn't throw without checking
  its result, a snapshot with no accompanying explicit assertion. This
  costs nothing (no execution required, just rereading what was just
  generated) and is the highest-leverage check against the failure mode
  this plugin exists to prevent. Note in Step 6 if anything was
  strengthened during this pass.

## Step 6 — Report what was written, then offer to verify

This step always happens, and on its own it completes the task. List the
file(s) written or edited, and for each test summarize in one line what it
covers (happy path / boundary / error path / interaction). Note any
assertion strengthened during the Step 5 self-review. Do **not** run
the tests yet and do **not** claim anything passed — nothing has been
executed.

Then offer, in the same message, without running anything automatically:
*"Want me to run these and verify them — including a fault-injection check
on the business-logic tests — before you review them?"*

If the user doesn't ask for verification (here or in a later message), the
task is complete. Never silently run the suite anyway, and never present a
pass/fail claim for tests that were not actually executed.

## Step 7 — Only if the user asks: run and verify

Do this only when the user explicitly asks you to run, verify, or check
the tests — in this turn or a follow-up one.

1. Run the new test(s) against the real implementation at least twice in a
   row (three times for anything touching timing, randomness, or async
   state) to catch non-determinism empirically before considering it
   green — not just once. A test that's red against correct code is a
   wrong test — fix the test, do not change working code to satisfy it.
2. For every business-logic or critical-path test (view models,
   authentication, payment logic): run the fault-injection self-check in
   [reference/verification.md](reference/verification.md) exactly as
   written — mandatory within this verification pass, not optional. Any
   test that stays green against deliberately broken code must be
   rewritten before being counted as passing coverage.
3. Check for accidental non-determinism: real network calls, an on-disk
   store instead of an in-memory one, unpinned simulator/locale/timezone
   affecting a snapshot, order-dependence on other tests. Fix in place.
4. Report specifically: which layer(s) were run, which edge cases were
   covered, what was intentionally left out of scope and why, whether any
   test was flagged and rewritten, and the coverage delta if measurable.
   Never claim "fully tested" or "all done" without this detail.

## Reference

- Swift Testing vs XCTest, translation table, coexistence rules: [reference/swift-testing-vs-xctest.md](reference/swift-testing-vs-xctest.md)
- View-model-first testing pattern, ViewInspector as secondary, async/Combine: [reference/view-model-testing.md](reference/view-model-testing.md)
- swift-snapshot-testing usage and scope, in-memory Core Data/SwiftData: [reference/snapshot-and-persistence.md](reference/snapshot-and-persistence.md)
- Fault-injection self-check procedure — run only if the user asks for verification, follow verbatim when you do: [reference/verification.md](reference/verification.md)

## Scripts

Run `scripts/detect_stack.sh` from the project root before generating any
test — it confirms the Swift project type and prints which test framework,
snapshot library, and persistence layer are already in use.
Files in this package (7)
  • SKILL.md 10 KB
  • evals/evals.json 7 KB
  • reference/snapshot-and-persistence.md 2 KB
  • reference/swift-testing-vs-xctest.md 3 KB
  • reference/verification.md 3 KB
  • reference/view-model-testing.md 3 KB
  • scripts/detect_stack.sh 3 KB

Versions

RepositoryScoreLicence
This page · jyotiraditya-chauhan/test-kit100MIT
HoangNguyen0403/agent-skills-standard100MIT
velimirmueller/ai-development-skills100MIT
JordanCoin/ios-skills-collection95MIT

Identical content appears in 1 other GitHub folders. We show one copy with the highest score.

Database snapshot: 13.11.2026 · package version 90483ca0ee6e (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100swift-test-scaffold
    Use when adding Swift tests, creating test targets, scaffolding ViewModel or service tests, or choosing Swift Testing over XCTest.
  • 100test-generator
    Generate test templates for unit tests, integration tests, and UI tests using Swift Testing and XCTest. Use when adding tests to iOS/macOS apps.
  • 90Swift Unit Testing Skill
    Design, write, migrate, and review Swift unit and integration tests using Swift Testing by default, with XCTest retained for UI automation, performance metrics, Objective-C interoperability, and legacy suites. Use for @Test, #expect, #require, parameterized tests, async tests,…
  • 100swiftui-expert
    Use when working in a native iOS/SwiftUI project - *.swift files, an *.xcodeproj or Package.swift, Xcode schemes, or mentions of SwiftUI, Swift 6, @Observable, SwiftData, NavigationStack, actors, or Swift Testing. Builds views and features, wires Observation-based state, fixes…
  • 100swift-testing-pro
    Use when writing tests with the Swift Testing framework (@Test, #expect, #require, traits, parameterized tests, @Suite) or migrating tests from XCTest.
  • 90swift-testing-expert
    Use when writing new Swift tests, modernizing XCTest suites, debugging flaky tests, or improving test quality and maintainability in Apple-platform or Swift server projects. Expert guidance for Swift Testing - test structure, expect/#require macros, traits and tags, parameterized tests, test…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.