Unit Testing Kotlin Channels & Flows
summary
Shows how to test real coroutine code: using runBlockingTest and TestCoroutineDispatcher to advance virtual time for delays, using turbine to assert individual Flow emissions and expectComplete, stubbing a Flow to throw to verify retry logic and using advanceTimeBy to exercise two retries, wrapping errors in a Result type instead of expectError, and testing ViewModel state by setting the main dispatcher and observing mutableStateFlow’s conflation (suggests mutableSharedFlow for non‑conflated events).
AI-written summary · about
chapters (11)
- 0:00Start
- 0:43Use Cases for Testing Flows
- 1:45Simple Implementation
- 2:43Test the Simple Flow
- 14:16Design Pattern for Injecting Your Dispatchers
- 16:21Test Errors
- 17:30Result Type
- 19:19Do Tests Retry
- 27:29Immutable State Flow
- 28:00How Immutable State Flow Works
- 28:20Launch in View Model Scope








