Untangling Coroutine Testing
summary
Explains concrete migration to kotlinx.coroutines 1.6 testing APIs with runnable examples: use runTest to call suspending functions, inject dispatchers to avoid flakiness, and replace Main with a test dispatcher for viewmodel scope; shows that a 1s delay becomes instantaneous under the test scheduler and how to drive queued coroutines with advanceUntilIdle. Compares queuing standard test dispatcher versus eager unconfined test dispatcher, demos Flow testing (hot sharedFlow, Turbine) and when to cancel collectors.
AI-written summary · about
chapters (17)
- 0:00Introduction
- 3:01Testing suspending functions
- 4:51Testing Dispatcher changes
- 5:53Testing new coroutines
- 9:38Standard TestDispatcher
- 13:26UnconfinedTestDispatcher
- 15:57Injecting dispatchers
- 22:00Keeping track of coroutines
- 24:44Handling the Main dispatcher
- 28:30Using TestDispatchers in the test
- 29:52Using TestDispatchers outside the test
- 31:16Creating test objects
- 37:19Flows with Turbine
- 39:00StateFlows
- 41:52Summary
- 42:24Resources
- 42:52Untangling Coroutine Testing





