What's the alternative to XCTExpectation in Swift Testing?
Asked on 2025-07-10
1 search
In Swift Testing, the alternative to XCTExpectation
is the use of the expect
and require
macros. These macros allow you to pass in ordinary expressions and language operators to validate conditions. The expect
macro is used for general expectations, while the require
macro is used for required expectations that will halt the test if the condition fails. This approach simplifies the testing process by reducing the need for multiple specialized functions and allows for more expressive and concise test code.
For more details, you can refer to the session Meet Swift Testing (03:07) where expectations are discussed.

Meet Swift Testing
Introducing Swift Testing: a new package for testing your code using Swift. Explore the building blocks of its powerful new API, discover how it can be applied in common testing workflows, and learn how it relates to XCTest and open source Swift.

Go further with Swift Testing
Learn how to write a sweet set of (test) suites using Swift Testing’s baked-in features. Discover how to take the building blocks further and use them to help expand tests to cover more scenarios, organize your tests across different suites, and optimize your tests to run in parallel.

What’s new in Swift
Join us for an update on Swift. We’ll briefly go through a history of Swift over the past decade, and show you how the community has grown through workgroups, expanded the package ecosystem, and increased platform support. We’ll introduce you to a new language mode that achieves data-race safety by default, and a language subset that lets you run Swift on highly constrained systems. We’ll also explore some language updates including noncopyable types, typed throws, and improved C++ interoperability.