Starting from Swift 6, a convenient Swift Testing framework has been introduced for testing code.
To explore its capabilities, I migrated my existing test code, which was written using the XCTest framework, to Swift Testing.
Key features applied:
#expect macro, making them clearer and easier to use.async and await syntax for networking code, there’s no need for the old wait-time configurations.@Test to a test function makes it recognizable as a test, and it allows passing multiple arguments as an array, along with various other options.Apple also provides the 🔗 Migrating a test from XCTest guide, and since Swift Testing is the default UnitTest framework when creating a new project, it seems recommended to use it.
I reviewed the async and await syntax, one of the Swift Concurrency features introduced in Swift 5.5.
Traditionally, asynchronous code could be written using completion handlers, DispatchQueue, RxSwift, Combine, etc. The async and await syntax helps write asynchronous code in a synchronous-like manner.
Benefits of using async & await:
throw keyword, error handling becomes simpler.