modernize-tests
Skill234 starsChanged 4 months agoMITView on GitHub
Modernize test suites to use modern Swift Testing features or migrate from XCTest.
3 other projects use a version of this, 3 of them edited.
Adopted by
Most recently taken up by
- artemnovichkov/xcode-skillsedited, first seen Sep 9, 2026
- guillevc/skillsedited, first seen Jun 29, 2026
- aaronbrethorst/claude-skillsedited, first seen Jan 31, 2026
Other versions3 projects use a version of this.
Word for word · 0
None found.
Edited · 3
- artemnovichkov/xcode-skills★ 2688% same
- aaronbrethorst/claude-skills★ 488% same
- guillevc/skills★ 088% same
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository6 other files it gives its agents.
The file
Show its rules and text
We split this skill into the rules it gives an agent
21 rules. 3 are common, 1 is distinctive, and 17 are very specific to this project.
3
Common
Most of the 3 edited versions we read keep these.
1
Distinctive
This author's own choices. Worth a look.
17
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 10
Do not apply when: user asks to write new tests from scratch (without existing XCTest code), user asks about XCTest features only, user …
- Very specific: line 20
When removing import XCTest, check whether the file uses Foundation types (URL, CharacterSet, ProcessInfo, Data, etc.).
- Very specific: line 25
Remove XCTestCase inheritance.
- Very specific: line 44
Avoid pulling instance variables into function bodies.
- Very specific: line 45
If the test mutates an instance variable with value semantics, you may need to mark the test function mutating.
- Very specific: line 55
Test functions can be async, throws, or async throws, and can be isolated to a global actor with @MainActor.
- Common: line 59
When migrating a test from XCTest to Swift Testing, apply these mappings:
- Very specific: line 79
When the error type is Equatable and the exact value is known, prefer to check the specific error value.
- Very specific: line 132
When a test method sets continueAfterFailure = false, all subsequent assertions need to be try #require(x) instead of #expect(x) to …
- Very specific: line 135
When continueAfterFailure = false is set in setUp, the conversion to try #require(x) must apply to all assertions in all test methods in …
- Very specific: line 200
When a skip checks OS version or platform availability, replace it with an @available attribute on the test function instead of …
- Common: line 233
When migrating from XCTest, migrate one test class at a time.
- Very specific: line 234
Prefer struct for suites unless deinit (tearDown) is needed, in which case use actor or final class.
- Very specific: line 235
Remove the test prefix from method names when adding @Test.
- Common: line 238
Use raw identifier syntax only for multi-word names that read like a sentence.
- Very specific: line 239
When migrating setUp, convert implicitly-unwrapped optional properties to non-optional properties initialized in-place, or in init if …
- Very specific: line 240
Look for explicit XCTFail/Issue.record calls that could be converted to #expect or #require
- Very specific: line 241
Do not change try #require calls into #expect.
- Very specific: line 242
Add @MainActor only to tests that explicitly relied on XCTest's implicit main-actor isolation.
- Very specific: line 243
Look for tests that loop over inputs or many repeated tests with the same logic and convert them to parameterized tests using …
- Very specific: line 245
Do not use underscore-prefixed symbols such as #_sourceLocation.
“Common” is measured: kept by at least 6 in 10 of the 3 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Modernize Tests
Apply when: user asks to modernize, update, migrate, supercharge, or convert their tests. XCTest should be migrated to Swift Testing when possible, existing Swift Testing tests should be evaluated to see if they could be better structured adopting newer features.
Do not apply when: user asks to write new tests from scratch (without existing XCTest code), user asks about XCTest features only, user only asks about test results or test running, user is asking to update tests to cover new functionality rather than updating the tests themselves, user is debugging test failures without mentioning migration, user has UI automation tests using XCUI* APIs (these cannot be migrated to Swift Testing).
Migration Reference
Imports
Replace import XCTest with import Testing. A file can import both if it contains mixed test content during incremental migration.
When removing import XCTest, check whether the file uses Foundation types (URL, CharacterSet, ProcessInfo, Data, etc.). XCTest re-exports
Foundation, so add import Foundation if needed.
Test Classes to Suites
Remove XCTestCase inheritance. Prefer struct over class:
final class FoodTruckTests: XCTestCase { ... }->struct FoodTruckTests { ... }
setUp/tearDown to init/deinit
Replace override func setUp() with init() (can be async throws). Replace override func tearDown() with deinit. If deinit is needed, use
actor or final class instead of struct (since structs have no deinit). Change stored properties to not use implicitly-unwrapped optional
types, and move their initial assignment from setUp to either be initialized inline or, if the initialization is complex, in an initializer.
struct MyTests {
var fixture = Fixture()
mutating func `Fixture behaves as expected`() {
#expect(fixture.doSomething())
}
}Avoid pulling instance variables into function bodies; this can cause noise. Swift Testing reinvokes the initializer fresh before each test runs.
If the test mutates an instance variable with value semantics, you may need to mark the test function mutating.
Test Methods
Replace the test name prefix with the @Test attribute. If the resulting test name includes multiple camelCase words,
use a raw identifier with the test name in sentence case.
func testEngineDoesNotStall() { ... }->@Test funcEngine does not stall() { ... }func testIgnition() { ... }->@Test func ignition() { ... }
Test functions can be async, throws, or async throws, and can be isolated to a global actor with @MainActor.
Assertions to Expectations
When migrating a test from XCTest to Swift Testing, apply these mappings:
XCTAssert(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)
There is no direct equivalent for XCTAssertEqual(_:_:accuracy:); use floating point math directly.
Errors
When the error type is Equatable and the exact value is known, prefer to check the specific error value.
XCTAssertThrowsError(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()
}continueAfterFailure
By default continueAfterFailure is true, which means expectations do not halt the test run.
Some XCTestCases set continueAfterFailure = false, which means the XCTAssert family of functions
will throw Objective-C exceptions that halt the test execution.
When a test method sets continueAfterFailure = false, all subsequent assertions need to be try #require(x)
instead of #expect(x) to preserve this behavior. When adding try #require(x), add throws to the affected methods.
When continueAfterFailure = false is set in setUp, the conversion to try #require(x) must apply
to all assertions in all test methods in that class.
Promote Issue.record/XCTFail to expectations
Wherever it is not disruptive, convert usage of Issue.record or XCTFail to #expect or #require,
depending if the test exits after (taking continueAfterFailure into account).
In some cases, the source of the expectation itself is sufficient to explain the failure, and the comment would be redundant.
For example, the following structures should be converted as such:
guard 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())Asynchronous Expectations to Confirmations
Replace XCTestExpectation + fulfill() + await fulfillment(of:) with confirmation():
// Before
let exp = expectation(description: "...")
handler = { exp.fulfill() }
doWork()
await fulfillment(of: [exp])
// After
await confirmation("...") { confirm in
handler = { confirm() }
doWork()
}For assertForOverFulfill = false with an expectedFulfillmentCount, use a range:
await confirmation("...", expectedCount: 10...) { confirm in ... }
Skipping Tests
Replace XCTSkipIf/XCTSkipUnless with traits on the test or suite:
try XCTSkipIf(condition)->@Test(.disabled(if: condition))try XCTSkipUnless(condition)->@Test(.enabled(if: condition))
Replace throw XCTSkip("reason") mid-test with try Test.cancel("reason").
When a skip checks OS version or platform availability, replace it with an @available attribute on the test function instead of .enabled(if:).
Known Issues
Replace XCTExpectFailure("...", ...) { ... } with withKnownIssue("...") { ... }.
For intermittent failures, replace .nonStrict() option (or the shorthand strict: false parameter) with isIntermittent: true.
For conditional/matching: use when: and matching: parameters:
withKnownIssue("...") {
try riskyOperation()
} when: {
shouldExpectFailure
} matching: { issue in
issue.error != nil
}Concurrency and Serial Execution
XCTest runs synchronous tests on the main actor and sequentially within a suite by default. Swift Testing runs all test functions on an arbitrary task
and in parallel. Add @MainActor only if a test explicitly relied on main-actor isolation in its XCTest form, and add @Suite(.serialized) if
tests depend on shared state.
Attachments
Replace XCTAttachment + self.add(attachment) with Attachment.record(value). The attached type must conform to Attachable (automatic for
Codable and NSSecureCoding types when Foundation is imported).
Modernization Guidelines
- When migrating from XCTest, migrate one test class at a time. A file can contain both XCTest and Swift Testing tests during migration.
- Prefer
structfor suites unlessdeinit(tearDown) is needed, in which case useactororfinal class. - Remove the
testprefix from method names when adding@Test. For lengthier test names which read like a sentence, use raw identifier syntax to improve readability, e.g.@Test funcAuthenticate, fetch summary, then check count() { ... }. - Also check existing
@Testfunctions for multi-word camelCase names and convert those to sentence-case raw identifiers. - Use raw identifier syntax only for multi-word names that read like a sentence.
- When migrating
setUp, convert implicitly-unwrapped optional properties to non-optional properties initialized in-place, or ininitif initialization is complex, may throw, or is async. - Look for explicit
XCTFail/Issue.recordcalls that could be converted to#expector#require - Do not change
try #requirecalls into#expect; this changes the behavior of tests. - Add
@MainActoronly to tests that explicitly relied on XCTest's implicit main-actor isolation. Do not add it unnecessarily. - Look for tests that loop over inputs or many repeated tests with the same logic and convert them to parameterized tests using
@Test(arguments:). - For suites with shared mutable state between tests, add
@Suite(.serialized)and consider usingactororclassinstead ofstruct. - Do not use underscore-prefixed symbols such as
#_sourceLocation; only use public API. For source locations, always use the fullSourceLocation(fileID:filePath:line:column:)initializer.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

