Loading...
Loading...
Use when writing tests with Swift Testing (@Test,
npx skill4agent add johnrogers/claude-swift-engineering swift-testing| Macro | Use Case |
|---|---|
| Soft check — continues on failure. Use for most assertions. |
| Hard check — stops test on failure. Use for preconditions only. |
let user = try #require(await fetchUser(id: "123"))
#expect(user.id == "123")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)
}
}| XCTest | Swift Testing |
|---|---|
| |
| |
| |
| |
| |
| |
| |
#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() }@Test("Validates inputs", arguments: zip(
["a", "b", "c"],
[1, 2, 3]
))
func testInputs(input: String, expected: Int) {
#expect(process(input) == expected)
}@Test func testAsync() async throws {
let result = try await fetchData()
#expect(!result.isEmpty)
}@Test func testCallback() async {
await confirmation("callback received") { confirm in
let sut = SomeType { confirm() }
sut.triggerCallback()
}
}extension Tag {
@Tag static var fast: Self
@Tag static var networking: Self
}
@Test(.tags(.fast, .networking))
func testNetworkCall() { }#require#expectzip.serialized#require#require#expect#require@Test(arguments: [a, b], [c, d])ziparguments: zip([a, b], [c, d]).serializedasyncTask { }async/await@Test func testAsync() async throws { }confirmation#expectconfirmation