Untangling Coroutine Testing
summary
Shows concrete results with kotlinx.coroutines 1.6 testing APIs: use runTest, create a single test scheduler shared by all test dispatchers, prefer StandardTestDispatcher (queues) over UnconfinedTestDispatcher (eager start) for real concurrency, and advance the scheduler or call advanceUntilIdle to make launches run. Demonstrates Dispatchers.setMain/resetMain and a JUnit rule, using backgroundScope to auto-cancel collectors, and explains why StateFlow-plus-stateIn needs a fake collector or explicit awaiting to observe updates.
AI-written summary · about
chapters (8)
- 0:00Introduction
- 1:16Calling suspending functions
- 5:35Testing APIs
- 13:40Injecting Dispatchers
- 20:02Injecting Test Dispatchers
- 25:08Flows
- 31:45State flows
- 38:53Questions




