with the new swift testing, how do i do expectations (old `wait for fulfillment`)
Asked on 12/09/2024
1 search
In the new Swift Testing framework, expectations are handled differently compared to the old wait for fulfillment
approach in XCTest. Instead of using multiple specialized functions, Swift Testing introduces two basic macros: expect
and require
. These macros allow you to pass in ordinary expressions and language operators to set expectations. For example, you can use ==
to check for equality or >
to compare values. You can also negate any expectation using the opposite operator.
To handle asynchronous conditions, Swift Testing integrates with Swift concurrency, allowing you to use async
and await
in your test functions. This means you can write tests that wait for asynchronous operations to complete using the same concurrency features as in your production code.
For more details, you can refer to the session Meet Swift Testing (18:19) where these concepts are discussed.

Platforms State of the Union
Discover the newest advancements on Apple platforms.

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.