Loading...
Loading...
Modernize test suites to use modern Swift Testing features or migrate from XCTest.
npx skill4agent add tartinerlabs/skills modernize-testsmeasure { ... }import XCTestimport Testingimport XCTestimport FoundationXCTestCasefinal class FoodTruckTests: XCTestCase { ... }struct FoodTruckTests { ... }override func setUp()init()async throwsoverride func tearDown()deinitdeinitactorfinal classstructdeinitsetUpstruct MyTests {
var fixture = Fixture()
mutating func `Fixture behaves as expected`() {
#expect(fixture.doSomething())
}
}mutatingtest@Testfunc testEngineDoesNotStall() { ... }@Test func () { ... }func testIgnition() { ... }@Test func ignition() { ... }asyncthrowsasync throws@MainActorXCTAssert(x)XCTAssertTrue(x)#expect(x)XCTAssertFalse(x)#expect(!x)XCTAssertNil(x)#expect(x == nil)XCTAssertNotNil(x)#expect(x != nil)XCTAssertEqual(x, y)#expect(x == y)XCTAssertNotEqual(x, y)#expect(x != y)XCTAssertIdentical(x, y)#expect(x === y)XCTAssertNotIdentical(x, y)#expect(x !== y)XCTAssertGreaterThan(x, y)#expect(x > y)XCTAssertGreaterThanOrEqual(x, y)#expect(x >= y)XCTAssertLessThanOrEqual(x, y)#expect(x <= y)XCTAssertLessThan(x, y)#expect(x < y)try XCTUnwrap(x)try #require(x)XCTAssertEqual(_:_:accuracy:)EquatableXCTAssertThrowsError(try f())#expect(throws: (any Error).self) {
try f()
}XCTAssertThrowsError(try f()) { error in
XCTAssertEqual(error, specificError)
}#expect(throws: specificError) {
try f()
}XCTAssertThrowsError(try f()) { error in
// Check error
}let error = #expect(throws: (any Error).self) {
try f()
}
// Check errorXCTAssertNoThrow(try f())#expect(throws: Never.self) {
try f()
}continueAfterFailurecontinueAfterFailure = falseXCTAssertcontinueAfterFailure = falsetry #require(x)#expect(x)try #require(x)throwscontinueAfterFailure = falsesetUptry #require(x)Issue.recordXCTFailIssue.recordXCTFailcontinueAfterFailureguard let object = somethingOptional() else {
Issue.record("Could not get object")
return
}
guard object.isAvailable() else {
Issue.record("Object not available")
return
}
if !object.performOperation() {
Issue.record("Failed to perform operation")
}let object = try #require(somethingOptional(), "Could not get object")
try #require(object.isAvailable())
#expect(object.performOperation())XCTestExpectationfulfill()await fulfillment(of:)confirmation()// Before
let exp = expectation(description: "...")
handler = { exp.fulfill() }
doWork()
await fulfillment(of: [exp])
// After
await confirmation("...") { confirm in
handler = { confirm() }
doWork()
}assertForOverFulfill = falseexpectedFulfillmentCountawait confirmation("...", expectedCount: 10...) { confirm in ... }XCTSkipIfXCTSkipUnlesstry XCTSkipIf(condition)@Test(.disabled(if: condition))try XCTSkipUnless(condition)@Test(.enabled(if: condition))throw XCTSkip("reason")try Test.cancel("reason")@available.enabled(if:)XCTExpectFailure("...", ...) { ... }withKnownIssue("...") { ... }.nonStrict()strict: falseisIntermittent: truewhen:matching:withKnownIssue("...") {
try riskyOperation()
} when: {
shouldExpectFailure
} matching: { issue in
issue.error != nil
}@MainActor@Suite(.serialized)XCTAttachmentself.add(attachment)Attachment.record(value)AttachableCodableNSSecureCodingstructdeinitactorfinal classtest@Test@Test func () { ... }setUpinitXCTFailIssue.record#expect#requiretry #require#expect@MainActor@Test(arguments:)@Suite(.serialized)actorclassstruct#_sourceLocationSourceLocation(fileID:filePath:line:column:)