Migrating tests from XCTest to Swift Testing revealed a challenge: verifying ordered callback sequences. XCTestExpectation handled this well, but Swift Testing's confirmation API has nesting issues and no built-in ordering guarantees. The solution uses AsyncStream to capture events as they occur, with custom AsyncSequence extensions (collect and collectUntil) to retrieve and verify event sequences. A lightweight EventStream wrapper type reduces boilerplate and handles stream termination and sentinel values. The post also addresses when a simpler array-based approach works and when it doesn't, particularly around actor isolation and non-deterministic timing.
Table of contents
ExpectationsConfirmationsA StreamPartial ResultsRoom for ImprovementAn Array?Small, but Nice2 Impressions