Intro to unit testing coroutines with Kotest & MockK
summary
Demonstrates unit testing Kotlin coroutines with Kotest (StringSpec/BehaviorSpec), MockK, Turbine and JUnit5 by building real tests: a mapper assertion that uses assertSoftly for multiple property checks, a fetch-news use case where a mocked Retrofit suspend function returns 10 fake articles (coEvery) and the in-memory DB update is verified with MockK verify (exact counts); covers error path (mock throws → returns empty list), injects test dispatchers, and records StateFlow emissions via a small “VRobot” collector to get green tests.
AI-written summary · about
chapters (7)
- 0:00Introduction to coroutine testing
- 5:14Testing a mapper with Kotest
- 19:58Testing a use case with behavior spec
- 41:40Mocking dependencies with MockK
- 1:01:03Testing a ViewModel with flows
- 1:14:40Using ViewRobot for state assertions
- 1:28:15Q&A and closing remarks






