Use when writing tests with Swift Testing (@Test, #expect, #require), migrating from XCTest, implementing async tests, or parameterizing tests.
View on GitHubjohnrogers/claude-swift-engineering
swift-engineering
February 5, 2026
Select agents to install to:
npx add-skill https://github.com/johnrogers/claude-swift-engineering/blob/main/plugins/swift-engineering/skills/swift-testing/SKILL.md -a claude-code --skill swift-testingInstallation paths:
.claude/skills/swift-testing/# 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 tes