with the new swift testing, how do i do expectations (old `wait for fulfillment`)

Generated on 12/9/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.