Testing Asynchronous Code in Swift 5.5
summary
Refactors a Combine-based app to Swift 5.5 concurrency, showing concrete testable changes: replacing completion handlers with async/await, using withCheckedContinuation to test existing Combine or escaping-completion code without changing it, mocking network calls via AsyncStream plus a URLProtocol interceptor, and a reusable timeout Task that phases out waitForExpectations. Demonstrates parsing 999 meme templates down to ~799, running async let/sink let to observe effects, and when tests hang how to cancel or finish continuations so failures are meaningful.
AI-written summary · about
chapters (9)
- 0:00Introduction and background
- 1:44Refactoring from Combine to async/await
- 6:08Testing structured concurrency basics
- 9:22Challenges with async/await in XCTest
- 14:14Testing tasks and cancellation
- 19:41Using task continuation for legacy code
- 20:02Mocking network calls with async stream
- 27:49Implementing timeout for async tests
- 29:55Final thoughts and future of async testing
related talks
31mFuture of Swift: A Sneak Peek at async / await
31mTesting SwiftUI and Combine: The State of the Art
47mManaging Combine, your existing code, and async/await
02h 42mSwift Structured Concurrency
30mUnlocking the Power of Swift Testing: Modern Approaches to Testing iOS Apps
32mVenturing Into the world of RxSwift unit testing
34mSwift Testing: A testing framework for modern Swift
31mIs structured concurrency worth the effort?
