Unit Testing Kotlin Flows
summary
Unit tests use concrete practices not platitudes: use runBlockingTest to get a test dispatcher that advances virtual time and cancels leftover coroutines, mock upstreams with channels (remember to close them) or with SharedFlow(replay=1) to replay the last event, prefer Turbine for asserting order with expectItem/expectComplete, and test StateFlow conflation, subscriberCount, and whileSubscribed/eager/lazy behaviors so emitted events actually reach consumers.
AI-written summary · about
chapters (8)
- 0:00Unit testing Kotlin Flows intro
- 1:23Kotlin Flows testing foundations
- 9:11Libraries for testing Flows
- 15:34StateFlow and SharedFlow
- 22:38Mocking Flow repositories
- 26:51Combining Flows in tests
- 33:10Advanced Flow conversions
- 37:09Conclusion & Q&A








