swift-testing-pro
/swift-testing-pro
Use when writing tests with the Swift Testing framework (@Test, #expect, #require, traits, parameterized tests, @Suite) or migrating tests from XCTest.
- Author
- laxrajpurohit ↗
- Repository
- swift-skills-pro ↗
- Licence
- MIT
- Last repository change
- 18.10.2026
Assessment and security
- Files in this package
- 1
- Scripts
- 0
- HTML comments
- 0
- URLs in SKILL.md
- 0
No signals detected. Repository changed on 18.10.2026, without references to retired models or APIs.
MIT, open: use and modify while retaining author attribution.
What it does and when to use it
Use when writing tests with the Swift Testing framework (@Test, #expect, #require, traits, parameterized tests, @Suite) or migrating tests from XCTest.
Original author description
Use when writing tests with the Swift Testing framework (@Test, #expect, #require, traits, parameterized tests, @Suite) or migrating tests from XCTest.
How it works
- When to use
- Core principles
- Basic test
- expect vs require
- Suites and state
- Parameterized tests
- Async and errors
- Traits
- Common mistakes checklist
- Output format (when reviewing)
SKILL.md preview
---
name: swift-testing-pro
description: Use when writing tests with the Swift Testing framework (@Test, #expect, #require, traits, parameterized tests, @Suite) or migrating tests from XCTest.
license: MIT
metadata:
author: Lax Rajpurohit
version: "1.0.0"
---
# Swift Testing Pro
Write clear, fast tests with the Swift Testing framework. Prefer it over XCTest for new
code.
## When to use
- Writing new unit/integration tests.
- Migrating XCTest cases to Swift Testing.
- Adding parameterized or trait-gated tests.
Trigger: `/swift-testing-pro`.
## Core principles
- `@Test` functions, not `test`-prefixed `XCTestCase` methods.
- `#expect` for soft assertions; `#require` to stop the test on failure.
- Group with `@Suite` (struct/actor) — a fresh instance per test gives isolation.
- Use `async`/`throws` directly; no expectation-fulfillment dance.
## Basic test
❌ XCTest
```swift
import XCTest
final class MathTests: XCTestCase {
func testAdd() { XCTAssertEqual(add(2, 3), 5) }
}
```
✅ Swift Testing
```swift
import Testing
@Test func add() {
#expect(add(2, 3) == 5)
}
```
## #expect vs #require
- `#expect(x == y)` records a failure but continues.
- `try #require(value)` unwraps/asserts and **halts** the test if it fails — use before
dereferencing.
✅
```swift
@Test func parsesUser() throws {
let user = try #require(User(json: sample)) // stop if nil
#expect(user.name == "Ada")
}
```
## Suites and state
```swift
@Suite struct CartTests {
let cart = Cart() // fresh per test — no shared state
@Test func startsEmpty() { #expect(cart.items.isEmpty) }
@Test func addsItem() {
cart.add(.sample)
#expect(cart.items.count == 1)
}
}
```
Don't reuse mutable state across tests (no XCTest `setUp` shared singletons).
## Parameterized tests
Replace copy-pasted near-identical tests with `arguments:`.
❌
```swift
@Test func evenTwo() { #expect(isEven(2)) }
@Test func evenFour() { #expect(isEven(4)) }
```
✅
```swift
@Test(arguments: [2, 4, 100])
func even(_ n: Int) { #expect(isEven(n)) }
```
Cross-product with multiple `arguments:` collections; use `zip` for paired inputs.
## Async and errors
```swift
@Test func loadsFeed() async throws {
let feed = try await api.feed()
#expect(!feed.isEmpty)
}
@Test func throwsOnBadInput() {
#expect(throws: ParseError.self) {
try parse("")
}
}
```
## Traits
- `.tags(.network)` to group/filter.
- `.enabled(if:)` / `.disabled("reason")` to gate.
- `.timeLimit(.minutes(1))` for runaway protection.
- `.bug("JIRA-123")` to link issues.
```swift
@Test(.disabled("flaky on CI — FIX-42"))
func flakyThing() { ... }
```
Prefer `.disabled("reason")` over commenting tests out — it stays visible and tracked.
## Common mistakes checklist
- [ ] Still subclassing `XCTestCase` for new tests.
- [ ] `#expect` before a force-unwrap that should be `try #require`.
- [ ] Shared mutable state across tests in a suite.
- [ ] Copy-pasted tests that should be `arguments:` parameterized.
- [ ] Commented-out tests instead of `.disabled("reason")`.
- [ ] `XCTestExpectation` where plain `async`/`await` works.
## Output format (when reviewing)
Per issue: file:line, rule, before/after. Flag missing coverage of error paths and edge
cases.
Versions
| Repository | Score | Licence |
|---|---|---|
| This page · laxrajpurohit/swift-skills-pro | 100 | MIT |
| twostraws/swift-testing-agent-skill | 100 | MIT |
| twostraws/swift-testing-agent-skill | 100 | MIT |
Database snapshot: 13.11.2026 · package version a555b8ee0d7a (SHA-256 digest of the entire package)
Downloads in the last 30 days: 0 · ranking
Similar skills
- 95swift-testing
Write and migrate tests using the Swift Testing framework with @Test, @Suite, #expect, #require, confirmation, parameterized tests, test tags, traits, withKnownIssue, XCTest UI testing, XCUITest, test plan, mocking, test doubles, testable architecture, snapshot testing, async… - 100swift-testing
Use when developers mention - (1) Swift Testing, @Test, expect, require, or @Suite, (2) "use Swift Testing" or "modern testing patterns", (3) test doubles, mocks, stubs, spies, or fixtures, (4) unit tests, integration tests, or snapshot tests, (5) migrating from XCTest to Swift Testing, (6) TDD… - 90swift-testing-expert
Use when writing new Swift tests, modernizing XCTest suites, debugging flaky tests, or improving test quality and maintainability in Apple-platform or Swift server projects. Expert guidance for Swift Testing - test structure, expect/#require macros, traits and tags, parameterized tests, test… - 90swift-testing-code-review
Reviews Swift Testing code for proper use of #expect/#require, parameterized tests, async testing, and organization. Use when reviewing .swift files with import Testing, @Test, #expect, @Suite, or confirmation patterns. - 90Swift Unit Testing Skill
Design, write, migrate, and review Swift unit and integration tests using Swift Testing by default, with XCTest retained for UI automation, performance metrics, Objective-C interoperability, and legacy suites. Use for @Test, #expect, #require, parameterized tests, async tests,… - 100swift-testing
Write XCTest cases, async tests, and organized test suites in Swift. Use when writing XCTest cases, async tests, or organizing test suites in Swift.