swift-testing-expert

Guides writing, migrating, and debugging Swift tests using Swift Testing macros, traits, and parameterized suites.

2|Updated Sep 8, 2026
One-click install
npx skills add https://github.com/hanshi-notes/hanshi --skill swift-testing-expert-hanshi-notes
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: swift-testing-expert
Source: https://github.com/hanshi-notes/hanshi/tree/main/.agents/skills/swift-testing-expert
Command: npx skills add https://github.com/hanshi-notes/hanshi --skill swift-testing-expert-hanshi-notes

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Swift developers often struggle with choosing between XCTest and Swift Testing, writing flaky parallel tests, and migrating legacy test suites without losing CI signal. This Skill provides structured expert guidance for modern Swift Testing so tests stay readable, deterministic, and maintainable. ## Core Features & Use Cases - Assertion and expectation guidance: Apply #expect and #require correctly, validate thrown errors, and scope known failures with withKnownIssue. - Suite design and parameterization: Organize tests into struct/actor/class suites, consolidate repetitive tests into @Test(arguments:), and avoid zip and CaseIterable pitfalls. - Parallelization, async, and migration support: Diagnose flaky tests from shared state, bridge completion-handler APIs with continuations, and migrate XCTest suites incrementally while keeping UI and performance tests on XCTest. - Use Case: You inherit an XCTest suite with hundreds of duplicated test methods and intermittent CI failures. Use this Skill to convert assertions to #expect, collapse duplicates into parameterized tests, isolate shared state, and set up tag-based test plans. ## Quick Start Ask the agent to review your Swift test file and modernize it with Swift Testing, for example: convert my XCTest price calculation tests to parameterized Swift Testing tests with proper tags.

Frequently Asked Questions about swift-testing-expert

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I migrate XCTest tests to Swift Testing?▼

Migrate incrementally: convert XCTAssert assertions to #expect first, then replace test class methods with @Test functions, then add parameterization and traits. Swift Testing and XCTest can coexist in the same target, so you never need a full rewrite at once.

When should I use #require instead of #expect in Swift Testing?▼

Use try #require when later assertions depend on a prerequisite value, such as unwrapping an optional before testing its properties. It acts as a guard that fails the test early, while #expect is the default for ordinary assertions.

Should I keep using XCTest for anything after adopting Swift Testing?▼

Yes. Keep XCTest for UI automation with XCUIApplication, performance metrics with XCTMetric, and Objective-C-only test code, since Swift Testing does not cover those scenarios. Everything else can migrate to Swift Testing.

Why are my Swift Testing tests flaky in CI?▼

Flakiness usually comes from shared mutable state, hidden ordering dependencies, or time-based waits, because Swift Testing runs tests in parallel with randomized order. Isolate state per test, use in-memory dependencies, and apply .serialized only as a temporary transition measure.

How do I test completion-handler APIs with Swift Testing?▼

Bridge completion-handler APIs using withCheckedContinuation or withCheckedThrowingContinuation so tests can await results naturally. For event-style callbacks that are not awaitable, use confirmations with explicit expected counts instead of sleeps.

What are the pitfalls of parameterized tests with zip in Swift Testing?▼

zip silently truncates to the shorter collection and breaks if CaseIterable enum cases are reordered, causing missing coverage without any error. Prefer arrays of tuples or dictionaries for paired inputs so each case and its expected value stay co-located.