In 2021, Apple released Swift concurrency to an adoring audience — finally, developers could write Swift code to implement concurrency in Swift apps! At WWDC 2024, developers got another game changer — Swift Testing.
By Audrey Tam.
You can assign custom tags to tests that have common characteristics, even if they're in different suites or files, and they appear in the Test navigator. For example, you might tag all tests that validate a specific feature or subsystem. You can assign a tag to a test function or to a test suite:
@Suite(.tags(.formatting))
structMetadataPresentation {
let video =Video(fileName: "By the Lake.mov")
@Testfuncrating() asyncthrows {
#expect(video.contentRating =="G")
}
@TestfuncformattedDuration() asyncthrows {
let videoLibrary =tryawaitVideoLibrary()
let video =try #require(await videoLibrary.video(named: "By the Lake"))
#expect(video.formattedDuration =="0m 19s")
}
}
You can run all the tests with a particular tag and filter them in the Test Report. This can be helpful if it shows that multiple tests with the same tag are failing.
Swift Testing Is Open Source and Cross-Platform
Swift Testing is open source and soon will transition to the recently announced swiftlang organization. It works on all Apple operating systems that support Swift Concurrency, as well as on Linux and Windows. It has a common codebase across all these platforms, so your tests behave much more consistently when moving between platforms, and there will be better functional parity between them.
Swift Testing has an open feature-proposal process, and Apple wants you to get involved by writing or participating in feature proposals, improving the documentation, or filing bug reports.
Download the final projects by clicking the Download Materials button at the top or bottom of this article.
In this article, you learned about Swift Testing building blocks:
I hope you're excited about Swift Testing and will soon have complete test coverage for all your apps!
All videos. All books.
One low price.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.