Untangling Coroutine Testing
summary
Migrates projects to kotlinx.coroutines 1.6 testing APIs and shows concrete fixes: use runTest to get a TestDispatcher backed by a single TestCoroutineScheduler (never create more than one per test), prefer the standard dispatcher (it queues work) over unconfined (it enters eagerly), control time with advanceUntilIdle / advanceTimeBy / runCurrent, replace the Main dispatcher with setMain/resetMain for ViewModel tests, inject dispatchers to avoid races, and use Turbine for robust Flow testing.
AI-written summary · about
chapters (9)
- 0:00Introduction to coroutine testing
- 1:54New coroutine testing APIs
- 3:57Testing suspending functions
- 6:25Understanding test scope
- 8:11Standard vs unconfined test dispatchers
- 14:49Injecting dispatchers in tests
- 20:01Handling Android main dispatcher
- 24:37Testing flows and state flows
- 37:04Summary and resources





