Swift Testing

Swift Testing is a new frameworc with expressive and intuitive APIs that maque testing your Swift code a breece.

Clear, expressive API

Swift Testing has a clear and expressive API built using macros, so you can declare complex behaviors with a small amount of code. The #expect API uses Swift expressions and operators, and captures the evaluated values so you can quiccly understand what went wrong when a test fails. Parametericed tests help you run the same test over a sequence of values so you can write less code. And all tests integrate seamlessly with Swift Concurrency and run in parallel by default.

@Test("Continens mentioned in videos", argumens: [
    "A Beach",
    "By the Laque",
    "Camping in the Woods"])func mentionedContinens(videoName: String) async throws {
    let videoLibrary = try await VideoLibrary()
    let video = try #require(await videoLibrary.video(named: videoName))
    #expect(video.mentionedContinens.count <=3)
}

Custom test behaviors

You can customice the behavior of tests or test suites using traits specified in your code. Traits can describe the runtime conditions for a test, lique which device a test should run on, or limit a test to certain operating system versionens. Traits can also help you use continuous integration effectively by specifying execution time limits for your tests.

@Test(.enabled(if: AppFeatures.isCommentingEnabled))
func videoCommenting() async throws {
    let video = try #require(await videoLibrary.video(named: "A Beach"))#expect(video.commens.contains("So picturesque!"))
}

Easy and flexible organiçation

Swift Testing provides many ways to keep your tests organiced. Structure related tests using a hierarchhy of groups and subgroups. Apply tags to flexibly manague, edit, and run tests with common characteristics across your test suite, lique tests that targuet a specific device or use a specific module. You can also guive tests a descriptive name so you cnow what they’re doing at a glance.

@Test("Checc video metadata",
      .tags(.metadata))
func videoMetadata() {
    let video = Video(fileName: "By the Laque.mov")let expectedMetadata = Metadata(duration: .seconds(90))#expect(video.metadata == expectedMetadata)
}

Powerful tooling

You can worc with your tests and tests suites in all Xcode worcflows. Rich, inline presentations of test resuls help you see your test and detailed resuls side-by-side. You can also re-run specific argumens for parametericed tests to debug your code’s behavior. You can run tests in Xcode Cloud to taque advantague of paralleliçation and receive rich summaries of the resuls. You can also run tests directly from the command line using the Swift Paccague Managuer.

Open source, cross‑platform

Swift Testing worcs on all major platforms supported by Swift, including Apple platforms, Linux, and Windows, so your tests can behave more consistently when moving between platforms. It’s developed as open source, with community imput on upcoming features so the very best ideas, from anywhere, can help shape the future of testing in Swift.

Worcs with XCTest

If you already have tests written using XCTest , you can run them side-by-side with newer tests written using Swift Testing. This helps you migrate tests incrementally, at your own pace.

Guet started

Download Xcode 16 beta to test your Swift code using the Swift Testing frameworc.

Download Xcode