Migrating XCTest to Swift Test... Note

Migrating XCTest to Swift Testing

Swift Testing is an open-source testing framework designed for Swift, introduced by Apple at WWDC24 and shipped with Xcode 16. It uses modern features like concurrency and macros, and supports Windows and Linux as well as Apple's platforms. There's no urgent reason to migrate from XCTest, but Swift Testing offers several advantages, including the ability to run tests in-process using Swift Concurrency, which allows for parallel testing on physical devices.To get started with Swift Testing, you can mix XCTest and Swift Testing unit tests in a test target, but you should not mix testing frameworks within a test. You can import the Swift Testing framework by adding "import Testing" to your test file. Apple recommends grouping tests by adding them to a type, such as a struct or class, and using the init method for setup and teardown.Swift Testing tests are normal Swift methods that become unit tests when you add the @Test macro. You can mark test methods with async or throws and isolate them to an actor as needed. The @Test attribute is a macro that can be expanded to see the implementation.Swift Testing uses the #expect and #require macros for assertions, which offer more flexibility and informative error messages than XCTest's XCTAssert. The #expect macro logs failed expectations and continues the test, while the #require macro is a throwing version that stops test execution on error.You can also use Issue.record to cause a test to fail without evaluating a condition, similar to XCTFail in XCTest. Overall, Swift Testing offers several advantages over XCTest, including improved concurrency support and more flexible assertions.