Daily iOS
Testing

Testing async code

How do you test an async/await API in a unit test?

How would an interviewer hear this answer? You'll see whether they'd move on, dig in, or say no, and which sentences would trip you up. Your score doesn't change.
See the short answer

Since Xcode 13 you declare the test method async throws, await it like let result = try await sut.load(), and assert right after. Remove time dependence by injecting a Clock, and don't wait with sleep.

Share a question