Swift Test Suite Builder

Swift Testing Standards

by HoangNguyen0403 · MIT license · ★ 569 on GitHub

Swift Testing Standards cover

Write XCTest cases, async tests, and organized test suites in Swift. Use when writing XCTest cases, async tests, or organizing test suites in Swift.

---
name: swift-testing
description: Write XCTest cases, async tests, and organized test suites in Swift. Use when writing XCTest cases, async tests, or organizing test suites in Swift.
metadata:
  triggers:
    files:
    - '**/*Tests.swift'
    keywords:
    - XCTestCase
    - XCTestExpectation
    - XCTAssert
---
# Swift Testing Standards

## **Priority: P0 (CRITICAL)**

## Core Rule Anchors

Overview

See implementation examples for XCTest setup/teardown, async tests, and UI test patterns.

Manual install (npx, ZIP)
Claude Codenpx skills add HoangNguyen0403/agent-skills-standard --skill swift-testing -g -a claude-code
Claude Code (degit)npx degit HoangNguyen0403/agent-skills-standard/skills/swift/swift-testing#develop ~/.claude/skills/swift-testing
Claude.ai / desktopZip the folder and upload it under Settings → Capabilities → Skills.
Codex, Cursor, other agentsPoint them at SKILL.md. The other files are plain text.

Connects with Agent Alley MCP · agentalley.io/mcp

Files included

  • SKILL.md3.1 KB
Read SKILL.md here
HoangNguyen0403/develop1 file shown
SKILL.md
Show the full text62 lines

Swift Testing Standards

Priority: P0 (CRITICAL)

Core Rule Anchors

  • [MOB-TEST-01] Tripartite Naming: Test functions must follow test_method_scenario_expectedBehavior or testMethod_scenario_expectedBehavior.
  • [MOB-TEST-02] State Invariant Rule: Assert state transitions and invariants; ban trivial state mirror tests.
  • [MOB-TEST-03] Entity Invariant & Codable Rule: Test calculations, validations, domain invariants, and non-trivial Codable serialization/parsing or error mapping; ban testing trivial getters or echo tests.
  • [MOB-TEST-04] Contract Testing Rule: Repositories and data sources must be tested for contract compliance and error mapping; ban 1:1 pass-through mock echoing.
  • [MOB-TEST-05] Bug-First Regression Lock: Every PR fixing a bug ticket or with title fix(...) must introduce a test reproducing the defect prior to the fix.

Write XCTest Cases

  • Standard Naming: Test functions must prefixed by 'test' ([MOB-TEST-01], e.g., func test_userLogin_whenValid_isSuccessful()).
  • Setup/Teardown: Use setUpWithError() and tearDownWithError() for environment management.
  • Assertions: Use specific assertions: XCTAssertEqual, XCTAssertNil, XCTAssertTrue, etc.

See implementation examples for XCTest setup/teardown, async tests, and UI test patterns.

Test Async Code

  • Async/Await: Mark test methods as async throws and use try await directly inside them.
  • Expectations: Use XCTestExpectation for callback-based async logic. Call expectation then fulfill() when done; then wait(for: [exp], timeout: 2.0) to block.
  • Timeout: Always set reasonable timeouts for expectations to avoid hanging CI.

Organize Test Suites

  • Unit Tests: Use protocols for dependencies and inject them via constructor (e.g., init(service: ServiceProtocol)). Focus on logic isolation using mocks/stubs.
  • UI Tests: Test user flows using XCUIApplication and accessibility identifiers.
  • Coverage: Coverage is diagnostic and project-configured; verify risk-weighted critical paths rather than padding code for an arbitrary percentage.

Anti-Patterns

  • [MOB-TEST-01..05] Violations: Ban vague names, trivial state mirrors, echo tests, 1:1 mock echoing, and unverified bug fixes.
  • No Thread.sleep: Use expectations or await.
  • No force unwrap in tests: Use XCTUnwrap() for better failure messages.
  • No assertion-free tests: A test that only runs code without asserting contract invariants is not a test.

References

Canonical response anchors

When this skill applies, preserve the following domain terminology or equivalent concrete examples in the answer when relevant:

  • Inject them via constructor
  • Use protocols
  • prefixed by 'test'
1---
2name: swift-testing
3description: Write XCTest cases, async tests, and organized test suites in Swift. Use when writing XCTest cases, async tests, or organizing test suites in Swift.
4metadata:
5 triggers:
6 files:
7 - '**/*Tests.swift'
8 keywords:
9 - XCTestCase
10 - XCTestExpectation
11 - XCTAssert
12---
13# Swift Testing Standards
14 
15## **Priority: P0 (CRITICAL)**
16 
17## Core Rule Anchors
18 
19- **`[MOB-TEST-01]` Tripartite Naming**: Test functions must follow `test_method_scenario_expectedBehavior` or `testMethod_scenario_expectedBehavior`.
20- **`[MOB-TEST-02]` State Invariant Rule**: Assert state transitions and invariants; ban trivial state mirror tests.
21- **`[MOB-TEST-03]` Entity Invariant & Codable Rule**: Test calculations, validations, domain invariants, and non-trivial `Codable` serialization/parsing or error mapping; ban testing trivial getters or echo tests.
22- **`[MOB-TEST-04]` Contract Testing Rule**: Repositories and data sources must be tested for contract compliance and error mapping; ban 1:1 pass-through mock echoing.
23- **`[MOB-TEST-05]` Bug-First Regression Lock**: Every PR fixing a bug ticket or with title `fix(...)` must introduce a test reproducing the defect prior to the fix.
24 
25## Write XCTest Cases
26 
27- **Standard Naming**: Test functions must prefixed by 'test' (`[MOB-TEST-01]`, e.g., `func test_userLogin_whenValid_isSuccessful()`).
28- **Setup/Teardown**: Use `setUpWithError()` and `tearDownWithError()` for environment management.
29- **Assertions**: Use specific assertions: `XCTAssertEqual`, `XCTAssertNil`, `XCTAssertTrue`, etc.
30 
31See [implementation examples](references/implementation.md) for XCTest setup/teardown, async tests, and UI test patterns.
32 
33## Test Async Code
34 
35- **Async/Await**: Mark test methods as `async throws` and use `try await` directly inside them.
36- **Expectations**: Use `XCTestExpectation` for callback-based async logic. Call `expectation` then `fulfill()` when done; then `wait(for: [exp], timeout: 2.0)` to block.
37- **Timeout**: Always set reasonable timeouts for expectations to avoid hanging CI.
38 
39## Organize Test Suites
40 
41- **Unit Tests**: Use protocols for dependencies and inject them via constructor (e.g., `init(service: ServiceProtocol)`). Focus on logic isolation using mocks/stubs.
42- **UI Tests**: Test user flows using `XCUIApplication` and accessibility identifiers.
43- **Coverage**: Coverage is diagnostic and project-configured; verify risk-weighted critical paths rather than padding code for an arbitrary percentage.
44 
45## Anti-Patterns
46 
47- **`[MOB-TEST-01..05]` Violations**: Ban vague names, trivial state mirrors, echo tests, 1:1 mock echoing, and unverified bug fixes.
48- **No Thread.sleep**: Use expectations or await.
49- **No force unwrap in tests**: Use `XCTUnwrap()` for better failure messages.
50- **No assertion-free tests**: A test that only runs code without asserting contract invariants is not a test.
51 
52## References
53 
54- [XCTest Patterns & Async Tests](references/implementation.md)
55 
56## Canonical response anchors
57 
58When this skill applies, preserve the following domain terminology or equivalent concrete examples in the answer when relevant:
59- Inject them via constructor
60- Use protocols
61- prefixed by 'test'
62 
View all files on GitHub →

Details

License
MIT
Stars on the repo
★ 569
Checked
Source
HoangNguyen0403/agent-skills-standard ↗
Creator
HoangNguyen0403 · 21 listings
View creator

Similar skills

See all →
SkillExpo Task Routerexpo/skills · by expoEntry point and router for every Expo or EAS task. Load this skill first — before writing code and before choosing another expo-* / eas-* skill — when the request, PRD, or spec mentions Expo, EAS, Expo Go, or an expo-* package, or the project has an `expo` dependency in `package.json`. Within that gate it also covers app specs and designs to implement (tabs, stacks, maps, lists, navigation, building from a screenshot), and phrasings like 'implement a mobile app', 'make my app look native', 'add navigation', 'fetch some data', 'upgrade my SDK', 'add Expo to my existing native app', 'ship to the App Store', or 'I'm new to Expo, where do I start'. A fully specified request (SDK pinned, libraries named, layout given) still routes through here — the shared setup rules still apply. Do NOT load it when neither signal is present: a bare React Native project with no `expo` dependency is not Expo work. Detects the real goal, routes to the right expo-* / eas-* skill, and owns the shared setup rules.★ 2.7k GitHub starsSkilliOS App Clip Setupexpo/skills · by expoAdd an iOS App Clip target to an Expo app. Use when the user mentions App Clip, AASA, apple-app-site-association, appclips, smart app banner, or wants to ship a lightweight iOS Clip invoked from a URL alongside their parent app.★ 2.7k GitHub starsSkillApp Store Deploy Agentexpo/skills · by expoBuild and submit iOS and Android apps with EAS to TestFlight, the App Store, or Google Play. Supports Expo and other React Native projects, plus existing native apps. Use for eas.json setup, release pipelines, signing, app versions and build numbers, store submissions, and listing metadata. For Expo websites and API routes, use eas-hosting; for adding React Native screens to a native app, use expo-brownfield.★ 2.7k GitHub starsSkillSleek Mobile App Designersleekdotdesign/agent-skills · by sleekdotdesignUse when the user wants to design a mobile app or UI screens, when they mention their Sleek (sleek.design) projects, or when implementing Sleek designs in code (HTML, React Native, SwiftUI).★ 583 GitHub starsSkillReact Native Animation Builderemilkowalski/skills · by emilkowalskiBuild animations in React Native and Expo, making the decisions in the order that determines whether they feel right — should it animate, which thread it runs on, which properties, spring or timing, how the gesture hands off, how it degrades. Writes the implementation with Reanimated, Gesture Handler, Expo Router and expo-haptics. Use when animating anything in an Expo app, adding gestures, sheets, screen transitions, press feedback or haptics, or fixing motion that stutters on device. For web animation use `animate`.★ 40.8k GitHub starsSkillModern Swift Writing Guideemilkowalski/skills · by emilkowalskiHow to write modern Swift well — modeling with value types, Swift 6 data-race safety and approachable concurrency (@concurrent, main-actor-by-default, actors, task groups), protocols and generics (some vs any), API design, performance and ARC, Swift Testing, macros, and the modern language features agents don't know about yet. Use when writing, reviewing, or migrating Swift, or when a concurrency error, a hang, a data race, a retain cycle, or a performance problem needs fixing.★ 40.8k GitHub stars

More from HoangNguyen0403

SkillAndroid Test WriterHoangNguyen0403/agent-skills-standard · by HoangNguyen0403Write Android unit, Compose UI, and Hilt-integrated tests. Use when designing test behavior with MockK or coroutine test utilities; defer database/WorkManager-specific recipes to the owning feature skill.★ 569 GitHub starsSkillArchitecture Diagram DesignerHoangNguyen0403/agent-skills-standard · by HoangNguyen0403Draws architecture diagrams as editable draw.io files with a fixed house style, C4 levels, evidence-tagged shapes, and optional multi-view identity checks. Use when producing a system context, container, component, deployment, data flow, sequence, state, or ERD, or redrawing an ASCII or Mermaid one.★ 569 GitHub starsSkillCode Review ExpertHoangNguyen0403/agent-skills-standard · by HoangNguyen0403Conduct high-quality, persona-driven code reviews. Use when reviewing PRs, critiquing code quality, or analyzing changes for team feedback.★ 569 GitHub starsSkillCybersecurity Framework MapperHoangNguyen0403/agent-skills-standard · by HoangNguyen0403Maintains sparse, reviewable cybersecurity framework edges with versioned IDs, relation, rationale, source, and review status. Use when mapping exercise observations or procedures to NIST, ATT&CK, or another named framework.★ 569 GitHub starsSkillDecision Discipline FrameworkHoangNguyen0403/agent-skills-standard · by HoangNguyen0403Right-size, ground, and gate SDLC decisions with SNC-sized depth, said-vs-assumed write-back, an evidence ledger, honest option cards, recorded approval, and self-review. Use when running brainstorm-feature, plan-feature, design-solution, or system-design-session.★ 569 GitHub starsSkillFlutter Robot Pattern TestsHoangNguyen0403/agent-skills-standard · by HoangNguyen0403Write unit, widget, and integration tests with robot patterns, widget keys, and Patrol in Flutter. Use when implementing test behavior; defer CI-only configuration without test changes.★ 569 GitHub stars