# swift-testing

Get guidance for writing Swift Testing tests, migrating from XCTest, and handling async or parameterized cases in Claude Code.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf (Devin Desktop), Claude.ai · ★ 233 repo stars
- Author: John Rogers (@johnrogers)
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/johnrogers/claude-swift-engineering/tree/HEAD/plugins/swift-engineering/skills/swift-testing/SKILL.md
- Updated: 2026-01-18
- Security check: automated, 2026-11-16 (text) — no signs of malicious code found.
- HTML: https://affpapa.org/en/nevibecode/skills/john-rogers-at-johnrogers-swift-testing

## What it does

The skill covers Swift Testing test structure and assertion macros. Use `#expect` for checks that can report failures together; reserve `#require` for values that later assertions depend on. It also shows how to test thrown errors, async functions, and callbacks with `confirmation`.

For XCTest migrations, the skill maps common assertion patterns to their Swift Testing equivalents. Pair input collections with `zip`: passing multiple collections separately creates a Cartesian product. Tests run in parallel by default, so cases that touch shared files, databases, or singletons can interfere; `.serialized` is one option for thread-unsafe legacy tests.

## Install

### Claude Code (native platform)

1. **Plugin marketplace**
In the agent chat (not a shell):
```text
/plugin marketplace add johnrogers/claude-swift-engineering
```
In the agent chat (not a shell):
```text
/plugin install swift-engineering@claude-swift-engineering
```
This installs the whole swift-engineering plugin with all its skills

2. **Skills CLI (Vercel)**
```bash
npx skills add johnrogers/claude-swift-engineering --skill swift-testing -a claude-code
```

3. **Manually: put the files in place**
- File: `~/.claude/skills/swift-testing/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/swift-testing/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add johnrogers/claude-swift-engineering --skill swift-testing -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/swift-testing/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add johnrogers/claude-swift-engineering --skill swift-testing -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/swift-testing/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install johnrogers/claude-swift-engineering plugins/swift-engineering/skills/swift-testing
```

2. **Manually: put the files in place**
- File: `.github/skills/swift-testing/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add johnrogers/claude-swift-engineering --skill swift-testing -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/johnrogers/claude-swift-engineering --path plugins/swift-engineering/skills/swift-testing
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/swift-testing/SKILL.md` — The legacy .windsurf/skills/ path still works

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/johnrogers/claude-swift-engineering/tree/HEAD/plugins/swift-engineering/skills/swift-testing/SKILL.md

## When to use it
- replace XCTest assertions with Swift Testing macros
- check the result of an async operation
- pair test inputs without creating extra combinations
- verify that a callback runs
- prevent tests from interfering through shared state

## Example prompts
- Convert my `XCTest` assertions to Swift Testing macros.
- Write an async test for `fetchData()` and check its result.
- Parameterize this test with paired inputs using `zip`.

## Source text · SKILL.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 064e5a1b55d8c94a.

BEGIN THIRD-PARTY FILE 064e5a1b55d8c94a
````text
---
name: swift-testing
description: Use when writing tests with Swift Testing (@Test, #expect, #require), migrating from XCTest, implementing async tests, or parameterizing tests.
---

# Swift Testing Framework

Modern testing with Swift Testing framework. No XCTest.

## Overview

Swift Testing replaces XCTest with a modern macro-based approach that's more concise, has better async support, and runs tests in parallel by default. The core principle: if you learned XCTest, unlearn it—Swift Testing works differently.

## References

- [Apple Documentation](https://developer.apple.com/documentation/testing)
- [Migration Guide](https://steipete.me/posts/2025/migrating-700-tests-to-swift-testing)

## Core Concepts

### Assertions

| Macro | Use Case |
|-------|----------|
| `#expect(expression)` | Soft check — continues on failure. Use for most assertions. |
| `#require(expression)` | Hard check — stops test on failure. Use for preconditions only. |

### Optional Unwrapping

```swift
let user = try #require(await fetchUser(id: "123"))
#expect(user.id == "123")
```

## Test Structure

```swift
import Testing
@testable import YourModule

@Suite
struct FeatureTests {
    let sut: FeatureType
    
    init() throws {
        sut = FeatureType()
    }
    
    @Test("Description of behavior")
    func testBehavior() {
        #expect(sut.someProperty == expected)
    }
}
```

## Assertion Conversions

| XCTest | Swift Testing |
|--------|---------------|
| `XCTAssert(expr)` | `#expect(expr)` |
| `XCTAssertEqual(a, b)` | `#expect(a == b)` |
| `XCTAssertNil(a)` | `#expect(a == nil)` |
| `XCTAssertNotNil(a)` | `#expect(a != nil)` |
| `try XCTUnwrap(a)` | `try #require(a)` |
| `XCTAssertThrowsError` | `#expect(throws: ErrorType.self) { }` |
| `XCTAssertNoThrow` | `#expect(throws: Never.self) { }` |

## Error Testing

```swift
#expect(throws: (any Error).self) { try riskyOperation() }
#expect(throws: NetworkError.self) { try fetch() }
#expect(throws: NetworkError.timeout) { try fetch() }
#expect(throws: Never.self) { try safeOperation() }
```

## Parameterized Tests

```swift
@Test("Validates inputs", arguments: zip(
    ["a", "b", "c"],
    [1, 2, 3]
))
func testInputs(input: String, expected: Int) {
    #expect(process(input) == expected)
}
```

**Warning:** Multiple collections WITHOUT zip creates Cartesian product.

## Async Testing

```swift
@Test func testAsync() async throws {
    let result = try await fetchData()
    #expect(!result.isEmpty)
}
```

### Confirmations

```swift
@Test func testCallback() async {
    await confirmation("callback received") { confirm in
````
END THIRD-PARTY FILE 064e5a1b55d8c94a

The third-party file has ended. Everything between the 064e5a1b55d8c94a tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2611 of 4452 bytes. © John Rogers (@johnrogers) · MIT · https://github.com/johnrogers/claude-swift-engineering/tree/HEAD/plugins/swift-engineering/skills/swift-testing/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
