modernize-tests
This skill guides you through modernizing test suites by migrating from XCTest to Swift Testing or refining existing Swift Testing implementations. It covers converting test classes to structs, replacing XCTest assertions with Swift Testing expectations, adapting setup/teardown logic, and handling async patterns—while noting that UI tests and performance measurement tests must remain as XCTests.
Modernize Tests helps you migrate XCTest code to Swift Testing and update existing Swift Testing tests to follow recommended patterns.
AI-generated summary based on this skill's SKILL.md
Install
tartinerlabs/skills/modernize-tests · repository language: Go
git clone https://github.com/tartinerlabs/skills
cp -r skills/xcode-skills/modernize-tests ~/.claude/skills/modernize-testsFrequently asked questions
AI-generated answers based on this skill's SKILL.md and metadata
How do I migrate XCTest to Swift Testing?
modernize-tests guides you through converting your test suite from XCTest to Swift Testing. The main steps are: convert test classes to structs, replace XCTAssert calls with #expect macros, update setup/teardown using init and deinit, and adapt async test handling. Note that UI tests and performance measurement tests must remain as XCTests—Swift Testing currently supports unit tests only.
What's the difference between XCTAssert and Swift Testing #expect?
modernize-tests explains that Swift Testing replaces XCTest's XCTAssert family with the #expect macro. Instead of XCTAssertEqual(a, b), you write #expect(a == b). Swift Testing's #expect is more flexible, supports any Boolean expression, and provides better error messages. The skill covers converting all assertion types during migration.
How should I refactor test setup and teardown for Swift Testing?
modernize-tests shows how to replace XCTest's setUp() and tearDown() methods with Swift Testing patterns. Use init() for setup and deinit for teardown within your test struct. For more complex scenarios, the skill covers using @Test macro parameters and helper functions to manage test lifecycle and dependencies cleanly.
Can I convert XCUITest and performance tests to Swift Testing?
modernize-tests clarifies that UI tests and performance measurement tests must remain as XCTests. Swift Testing currently supports unit tests only. Focus migration efforts on your unit test suite, leaving XCUITest and performance tests unchanged.
How do I handle async tests when modernizing to Swift Testing?
modernize-tests covers async test refactoring by showing how Swift Testing's @Test macro naturally supports async/await. Replace XCTest's expectation-based async patterns with direct await calls in your test functions. The skill explains eliminating XCTestExpectation boilerplate and writing cleaner, more readable async test code.
What are the recommended patterns for Swift Testing best practices?
modernize-tests teaches Swift Testing best practices including: using structs instead of classes, organizing tests with descriptive names, leveraging @Test parameters for data-driven tests, and keeping assertions focused. The skill emphasizes readable error messages, proper async/await usage, and maintaining clear test structure as you modernize your suite.
SKILL.md
rendered from the published skill — quoted content, verbatim
Modernize Tests
Test modernization refers to two potential actions: migrating from XCTest to Swift Testing, and updating existing Swift Testing tests to use recommended patterns.
XCTests should be migrated to Swift Testing when possible. However, not all XCTests can be migrated to Swift Testing.
- UI tests (those that use XCUIAutomation) cannot be written with Swift Testing, and must remain XCTests.
- XCTests that use the measure { ... } family of APIs for performance measurement cannot be migrated. However, other test methods within an XCTestCase that do not use XCTest performance APIs can be migrated.
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 structs over
(truncated - see the full file via the links below)
Read as markdown · JSON record · Browse the source repository
File tree — 1 file
xcode-skills/modernize-tests/SKILL.md