Skip to content
Skills Library
Programming · Testing

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.

Licence
MIT
Last repository change
18.10.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 18.10.2026, without references to retired models or APIs.

Licence

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

  1. When to use
  2. Core principles
  3. Basic test
  4. expect vs require
  5. Suites and state
  6. Parameterized tests
  7. Async and errors
  8. Traits
  9. Common mistakes checklist
  10. Output format (when reviewing)
Original SKILL.md headings · 126 lines, 429 words
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

RepositoryScoreLicence
This page · laxrajpurohit/swift-skills-pro100MIT
twostraws/swift-testing-agent-skill100MIT
twostraws/swift-testing-agent-skill100MIT

Database snapshot: 13.11.2026 · package version a555b8ee0d7a (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

: harmful content, incorrect descriptions or an author’s removal request.

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.

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.