Swift testing pro
Skill laxrajpurohit/swift-skills-pro/swift-testing-pro/skills/swift-testing-pro
Modern, original agent skills for Swift and Apple-platform development
npx -y skills add laxrajpurohit/swift-skills-pro --skill swift-testing-proAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 5 stars5 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
Use when writing tests with the Swift Testing framework (@Test, #expect, #require, traits, parameterized tests, @Suite) or migrating tests from XCTest.
The file declares its own license as MIT. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.
SKILL.md
3.2 KB, as published. Nobody here has run it
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
@Testfunctions, nottest-prefixedXCTestCasemethods.#expectfor soft assertions;#requireto stop the test on failure.- Group with
@Suite(struct/actor) — a fresh instance per test gives isolation. - Use
async/throwsdirectly; no expectation-fulfillment dance.
Basic test
❌ XCTest
import XCTest
final class MathTests: XCTestCase {
func testAdd() { XCTAssertEqual(add(2, 3), 5) }
}
✅ Swift Testing
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.
✅
@Test func parsesUser() throws {
let user = try #require(User(json: sample)) // stop if nil
#expect(user.name == "Ada")
}
Suites and state
@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:.
❌
@Test func evenTwo() { #expect(isEven(2)) }
@Test func evenFour() { #expect(isEven(4)) }
✅
@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
@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.
@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
XCTestCasefor new tests. -
#expectbefore a force-unwrap that should betry #require. - Shared mutable state across tests in a suite.
- Copy-pasted tests that should be
arguments:parameterized. - Commented-out tests instead of
.disabled("reason"). -
XCTestExpectationwhere plainasync/awaitworks.
Output format (when reviewing)
Per issue: file:line, rule, before/after. Flag missing coverage of error paths and edge cases.