Swift Testing: macro-based #expect and traits, bundled with the Swift 6 toolchain
A modern, expressive testing package for Swift
At a glance
- What is it?
- swiftlang/swift-testing is the Testing module that ships inside Swift 6 and Xcode 16. This article covers its macros, traits, tags, parameterized tests, platform table and the limits of building it from source.
- Who is it for?
- Teams on Swift 6 or Xcode 16 can adopt Swift Testing today without adding a dependency, and can keep their XCTest files while they migrate. Teams that must test on Wasm, Android or OpenBSD should check the platform table first, because those targets are experimental.
- Can I use it commercially?
- Yes. Apache-2.0 is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 1 day ago.
- What is it written in?
- Mainly Swift, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 25, 2026, and from our analysis. They are not legal advice.
Star history
- swiftlang/swift-testing2,180 ★ · +7
| Repository | 2026-10-08 | 2026-11-25 |
|---|---|---|
| swiftlang/swift-testing | 2.2k | 2.2k |
7 Stars in the last 48 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
A failed #expect prints the evaluated operands, not just false
Swift Testing builds its assertions on macros. Inside a function marked @Test, #expect takes an ordinary Swift expression with ordinary operators, and when the expression fails the macro reports the values it evaluated along the way. That is the difference a reader notices first: the failure message shows both sides of the comparison instead of a bare boolean.
The example from the repository shows the shape of the output in a trailing comment:
import Testing
@Test func helloWorld() {
let greeting = "Hello, world!"
#expect(greeting == "Hello") // Expectation failed: (greeting → "Hello, world!") == "Hello"
}The variable name greeting is paired with its runtime value, and the literal on the right stays as written. A test author does not pick between a family of assertion functions for equality, inequality or comparison. One macro covers them all, and the expression itself is the documentation of intent.
There is a companion macro, #require, which appears in the later examples with try. It unwraps an optional or stops the test when the value is missing, so the lines after it can use the unwrapped value directly. The README project description calls the API expressive, and the macro design is where that claim is concrete.
Traits attach runtime conditions and time limits to a single test
Behavior that XCTest would put in setUp or in an early return lives in the test declaration here, as traits. The repository describes traits that state which device a test should run on, traits that limit a test to certain operating system versions, and traits that set an execution time limit so continuous integration does not hang on a stuck test.
The example uses the enabled trait with a condition:
@Test(.enabled(if: AppFeatures.isCommentingEnabled))
func videoCommenting() async throws {
let video = try #require(await videoLibrary.video(named: "A Beach"))
#expect(video.comments.contains("So picturesque!"))
}When AppFeatures.isCommentingEnabled is false, the test is switched off by its own declaration rather than failing or being deleted. The same function also shows that tests can be async and throwing, and that #require accepts an awaited call.
Traits can be applied to a whole suite as well as to one test. The README names the capability but lists only the three uses above, so the full set of built-in traits has to be read from the hosted documentation on the Swift Package Index. A reader who wants a specific trait, such as a retry or a bug link, will not find it confirmed in the repository front page.
Tags cut across suites, and backtick names replace display strings
Two organizing tools sit side by side. Groups and subgroups give a hierarchy. Tags give a second axis that ignores the hierarchy: a tag such as metadata can be attached to tests in different suites, then used to manage, edit and run only those tests. The README gives device-specific and module-specific tests as examples of what a tag might mark.
Naming works through the language rather than a string argument:
@Test(.tags(.metadata))
func `Check video metadata`() {
let video = Video(fileName: "By Lake Tahoe.mov")
let expectedMetadata = Metadata(duration: .seconds(90), filmingLocation: "California")
#expect(video.metadata == expectedMetadata)
}The function name is written with backticks, so the readable sentence is the name. The result is that test reports and source agree on what a test is called, with no display-name string to drift out of date.
One cost follows from this. The .metadata tag in the example has to be declared somewhere in the project before .tags(.metadata) compiles, and the README does not show that declaration. Teams adopting tags need to read the Documentation folder or the hosted guides for the tag declaration syntax.
Parameterized tests run in parallel, so shared state breaks them
Passing arguments to @Test runs the same function once per input. The example feeds three video names into one test body:
@Test(arguments: [
"Weekend at Big Sur",
"By Lake Tahoe",
"Camping in Muir Woods"
])
func `California vacation videos have locations`(videoName: String) async throws {
let videoLibrary = try await VideoLibrary()
let video = try #require(await videoLibrary.video(named: videoName))
#expect(video.metadata.filmingLocation == "California")
}Each case is its own run, so a failure on one name does not hide the other two. The README states that all tests integrate with Swift Concurrency and run in parallel by default.
Parallel by default has a consequence the README does not spell out: a test that writes to a shared file, a global variable or a single database will see interference from tests running at the same moment. Anyone moving serial XCTest suites that relied on execution order has to find those dependencies first. The README gives no opt-out switch on its front page, so the place to look is the documentation hosted on the Swift Package Index. Note also that the example constructs VideoLibrary inside the test, which keeps each case independent of the others.
No package dependency is needed, and building from source needs a main-branch snapshot
For ordinary use, import Testing is the whole setup:
import TestingSwift Testing is included with the Swift 6 toolchain and Xcode 16, so a Swift package or Xcode project does not add it as a dependency. The repository still carries a Package.swift, a CMakeLists.txt, a cmake directory and a Toolsets directory, which are for people building the library itself.
That second path is narrower than it looks. The README carries an important note that the library depends on upcoming language and compiler features, and that the main branch of the repository requires a recent main-branch development snapshot toolchain. A released Swift toolchain is not enough to build main. The Dockerfile makes the same point in container form: it starts from swiftlang/swift:nightly-main-jammy, then creates a build-user account with group and user ID 998 to mirror the Swift.org CI system, and sets /home/build-user as the working directory.
The practical result is a split. Consumers get the version that matches their toolchain. Contributors and anyone testing unreleased behavior need nightly toolchains, and a pinned Swift 6.4 install will not compile main.
Wasm, Android and OpenBSD are experimental, and two of them are only built in CI
The platform table is explicit about three levels of support. Apple platforms, Linux, FreeBSD and Windows are Supported with Automated qualification, which the README footnote defines as continuous integration verifying that the project builds and passes all tests.
Wasm and Android are Experimental, with qualification marked Automated (Build Only). Continuous integration confirms that the code compiles for those targets, and nobody runs the test suite there automatically. OpenBSD is Experimental with Manual qualification, linked to a manual_build_openbsd.yml workflow that a person has to start.
A developer shipping a Swift library to Android or Wasm therefore gets a testing library that compiles on their target without a stated guarantee that its own tests pass there. The footnote says full automated qualification is the goal for all supported platforms, and that some platforms presently rely on manual test or manual build and test. It gives no dates for closing that gap.
FreeBSD appears in the Supported rows alongside Linux and Windows, which is useful to know for server-side Swift teams, because it is not a platform most testing libraries name at all.
XCTest files keep running next to new tests, but no migration tool is documented
Existing XCTest tests can run side by side with Swift Testing tests in the same project. The README presents this as incremental migration at the team's own pace, which means a codebase does not have to convert in one pull request.
That is the extent of the migration material in the repository front page. There is no converter command, no script that rewrites XCTAssertEqual into #expect, and no guidance on which tests to move first. The README does not document how the two frameworks report results together or how a test run is filtered across both. Those questions are answered, if at all, in the Documentation directory and on the hosted documentation.
On the questions people search, the README makes no performance claim and mentions no other Swift testing library by name, so comparisons with XCTest speed or with Quick and Nimble have no support in the repository front page. The project's last push was on 2026-10-25, and the most recent release listed is swift-6.4.2-RELEASE, dated 2026-10-30, which follows swift-6.4.1-RELEASE on 2026-10-14 and swift-6.4.0-RELEASE on 2026-09-15. The release names track Swift toolchain versions, not an independent version line for the library.
Editorial conclusion
Teams on Swift 6 or Xcode 16 can adopt Swift Testing today without adding a dependency, and can keep their XCTest files while they migrate. Teams that must test on Wasm, Android or OpenBSD should check the platform table first, because those targets are experimental. Anyone planning to build the package from source should confirm they can install a main-branch development snapshot toolchain before starting.
Frequently asked questions
What is the Swift Testing framework?
Swift Testing is a package of macro-based APIs for testing Swift code, with #expect for assertions and @Test for declaring tests. It is included in officially supported Swift toolchains for Apple platforms, Linux and Windows.
How do you use Swift Testing in a project?
Write import Testing and mark functions with @Test. No package dependency is needed because Swift Testing ships with the Swift 6 toolchain and Xcode 16.
What is Swift Testing?
Swift Testing is the Apache-2.0 licensed testing package from the swiftlang organization. It offers traits, tags, parameterized tests and parallel execution, and it can run alongside existing XCTest tests.
Official sources
Where developers are discussing it
Posts on Hacker News, dev.to and Lobsters that link to this repository, found by our scan of those communities. 1 in the last 30 days; newest first.
- Swift Testing vs XCTest in 2026: Migrating Real iOS Projects to Modern Testingdev.to · Nov 23, 2026 · 4 points · 0 comments
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/swiftlang-swift-testing)Star history chart for your README
[](https://hysenlabs.com/projects/swiftlang-swift-testing)Was this useful?