Get the FREE Ultimate OpenClaw Setup Guide →

swift-testing-expert

npx machina-cli add skill AvdLee/Swift-Testing-Agent-Skill/swift-testing-expert --openclaw
Files (1)
SKILL.md
4.8 KB

Swift Testing

Overview

Use this skill to write, review, migrate, and debug Swift tests with modern Swift Testing APIs. Prioritize readable tests, robust parallel execution, clear diagnostics, and incremental migration from XCTest where needed.

Agent behavior contract (follow these rules)

  1. Prefer Swift Testing for Swift unit and integration tests, but keep XCTest for UI automation (XCUIApplication), performance metrics (XCTMetric), and Objective-C-only test code.
  2. Treat #expect as the default assertion and use #require when subsequent lines depend on a prerequisite value.
  3. Default to parallel-safe guidance. If tests are not isolated, first propose fixing shared state before applying .serialized.
  4. Prefer traits for behavior and metadata (.enabled, .disabled, .timeLimit, .bug, tags) over naming conventions or ad-hoc comments.
  5. Recommend parameterized tests when multiple tests share logic and differ only in input values.
  6. Use @available on test functions for OS-gated behavior instead of runtime #available checks inside test bodies; never annotate suite types with @available.
  7. Keep migration advice incremental: convert assertions first, then organize suites, then introduce parameterization/traits.
  8. Only import Testing in test targets, never in app/library/binary targets.

First 60 seconds (triage template)

  • Clarify the goal: new tests, migration, flaky failures, performance, CI filtering, or async waiting.
  • Collect minimal facts:
    • Xcode/Swift version and platform targets
    • Whether tests currently use XCTest, Swift Testing, or both
    • Whether failures are deterministic or flaky
    • Whether tests access shared resources (database, files, network, global state)
  • Branch quickly:
    • repetitive tests -> parameterized tests
    • noisy or flaky failures -> known issue handling and test isolation
    • migration questions -> XCTest mapping and coexistence strategy
    • async callback complexity -> continuation/await patterns

Routing map (read the right reference fast)

  • Test building blocks and suite organization -> references/fundamentals.md
  • #expect, #require, and throw expectations -> references/expectations.md
  • Traits, tags, and Xcode test-plan filtering -> references/traits-and-tags.md
  • Parameterized test design and combinatorics -> references/parameterized-testing.md
  • Default parallel execution, .serialized, isolation strategy -> references/parallelization-and-isolation.md
  • Test speed, determinism, and flakiness prevention -> references/performance-and-best-practices.md
  • Async waiting and callback bridging -> references/async-testing-and-waiting.md
  • XCTest coexistence and migration workflow -> references/migration-from-xctest.md
  • Test navigator/report workflows and diagnostics -> references/xcode-workflows.md
  • Index and quick navigation -> references/_index.md

Common pitfalls -> next best move

  • Repetitive testFooCaseA/testFooCaseB/... methods -> replace with one parameterized @Test(arguments:).
  • Failing optional preconditions hidden in later assertions -> try #require(...) then assert on unwrapped value.
  • Flaky integration tests on shared database -> isolate dependencies or in-memory repositories; use .serialized only as a transition step.
  • Disabled tests that silently rot -> prefer withKnownIssue for temporary known failures to preserve signal.
  • Unclear failure values for complex types -> conform type to CustomTestStringConvertible for focused test diagnostics.
  • Test-plan include/exclude by names -> use tags and tag-based filters instead.

Verification checklist

  • Confirm each test has a single clear behavior and expressive display name when needed.
  • Confirm prerequisites use #require where failure should stop the test.
  • Confirm repeated logic is parameterized instead of duplicated.
  • Confirm tests are parallel-safe or intentionally serialized with rationale.
  • Confirm async code is awaited and callback APIs are bridged safely.
  • Confirm migration keeps unsupported XCTest-only scenarios on XCTest.

References

  • references/_index.md
  • references/fundamentals.md
  • references/expectations.md
  • references/traits-and-tags.md
  • references/parameterized-testing.md
  • references/parallelization-and-isolation.md
  • references/performance-and-best-practices.md
  • references/async-testing-and-waiting.md
  • references/migration-from-xctest.md
  • references/xcode-workflows.md

Source

git clone https://github.com/AvdLee/Swift-Testing-Agent-Skill/blob/main/swift-testing-expert/SKILL.mdView on GitHub

Overview

Guides writing, reviewing, migrating, and debugging Swift tests using modern APIs. Emphasizes readable tests, parallel-safe execution, clear diagnostics, and incremental XCTest migration for Apple platforms and Swift server projects.

How This Skill Works

Defaults to #expect assertions with #require for prerequisites, organizes tests with traits and tags, and uses parameterized tests when logic is shared across inputs. It promotes gradual migration from XCTest, applies parallelization with .serialized when safe, and keeps OS gating via @available on test functions.

When to Use It

  • Writing new Swift unit or integration tests with modern APIs
  • Modernizing legacy XCTest suites and migrating to Swift Testing
  • Debugging flaky or nondeterministic tests and isolating dependencies
  • Improving test speed, determinism, and maintainability through parallel execution and isolation
  • Configuring OS-gated behavior and test plans for CI with proper tagging

Quick Start

  1. Step 1: Clarify goal (new tests, migration, or flaky debugging) and gather environment details
  2. Step 2: Convert assertions to #expect, annotate prerequisites with #require when needed, and apply traits
  3. Step 3: Introduce parameterized tests and parallelization gradually, migrating from XCTest as needed

Best Practices

  • Prefer #expect as the default assertion, using #require for prerequisite values
  • Apply parameterized tests when multiple cases share logic and only differ by inputs
  • Use traits and tags for metadata and test-plan filtering over naming tricks
  • Isolate shared state and rely on .serialized as a transition, not a default
  • Migrate incrementally: first assertions, then suite organization, then parameterization/traits; keep XCTest coexistence where needed

Example Use Cases

  • Migrating XCTest suites to Swift Testing incrementally in an Apple platform project
  • Replacing repetitive testFooCaseA/testFooCaseB with a parameterized test using @Test(arguments:)
  • Introducing traits like .enabled/.disabled and .timeLimit to CI-filter tests
  • Isolating database access with in-memory repositories to reduce flakiness
  • Implementing async waiting with continuation/await patterns in async tests

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers