swift-testing

Generates and diagnoses XCTest and Swift Testing test code for Swift projects.

Updated Jul 6, 2026
One-click install
npx skills add https://github.com/chenziyang110/launchdeck --skill swift-testing-chenziyang110
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: swift-testing
Source: https://github.com/chenziyang110/launchdeck/tree/main/.claude/skills/swift-testing
Command: npx skills add https://github.com/chenziyang110/launchdeck --skill swift-testing-chenziyang110

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing reliable Swift tests requires choosing the right framework, mocking strategy, and async patterns, and mistakes lead to flaky or incomplete coverage. This Skill guides an agent through a structured workflow for creating, fixing, and improving Swift tests using XCTest or the Swift Testing framework. ## Core Features & Use Cases - Phased Test Generation: Follows a five-phase protocol covering context analysis, strategy selection, test case design, code generation, and verification. - Framework Guidance: Provides decision trees for choosing between XCTest, Swift Testing (@Test, @Suite), XCUITest, and protocol-based manual mocks. - Coverage and CI Support: Includes commands for code coverage with llvm-cov and xccov, plus GitHub Actions CI integration examples. - Use Case: Ask the agent to write unit tests for a Swift networking service, and it will design protocol-based mocks, async/await test methods, boundary cases, and the commands to run and verify them. ## Quick Start Ask the agent to write XCTest unit tests with async coverage and edge cases for a specific Swift class in your package.

Frequently Asked Questions about swift-testing

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

FAQPage Schema
How do I write unit tests in Swift with XCTest?▼

Create an XCTestCase subclass in your Tests directory with testXxx methods using assertions like XCTAssertEqual. Run tests with swift test or filter specific classes using swift test --filter "ClassName".

XCTest vs Swift Testing: which framework should I use?▼

Swift Testing with @Test and @Suite macros is recommended for Swift 6+ greenfield projects, while XCTest remains standard for existing codebases. Swift Testing offers parametrized tests via arguments and #expect assertions instead of XCTAssert functions.

How do I test async code in Swift?▼

Use async throws test methods directly in Swift 5.5+ for async/await code. For legacy callback-based APIs, use XCTestExpectation with wait(for:timeout:) instead of sleep() to avoid flaky synchronization.

How do I mock network calls in Swift tests?▼

Define a protocol for the external dependency and inject a manual mock struct that records calls, such as a MockNotifier capturing sent messages. This avoids real network access and keeps unit tests deterministic.

Why are my Swift UI tests flaky?▼

Flakiness usually comes from hardcoded delays, shared state, or animation timing. Use waitForExistence(timeout:) instead of sleeps, set continueAfterFailure = false, and relaunch the app fresh between tests.

How do I measure code coverage for Swift tests?▼

Run swift test --enable-code-coverage, then generate reports with llvm-cov using the produced profdata file. For Xcode projects, use xcodebuild with -enableCodeCoverage YES and inspect results via xcrun xccov.