Testing with Coroutines
summary
Shows how kotlinx.coroutines.test makes coroutine tests deterministic by giving runBlockingTest virtual time control and thread blocking so timeouts can be asserted with advanceTimeBy and completableDeferred fakes, explains injecting TestCoroutineScope/TestCoroutineDispatcher so launched coroutines don’t leak, shows Android helpers setMain/resetMain, and demonstrates flow testing patterns (take, collecting in a launched job then cancel). Examples run and the techniques reliably reproduce and assert timing and concurrency behavior.
AI-written summary · about
chapters (16)
- 0:00Start
- 0:45Disclaimer
- 1:12Test a Timeout That Is Implemented Using Co-Routines
- 3:23Fake Api
- 3:43Parameter Injection
- 4:18Test the Timeout
- 4:55Completable Deferred
- 8:25Sequence Diagram
- 12:49Run Blocking Test
- 19:00Diving into Event Loops
- 19:38Event Loop
- 20:46Timeout Test
- 21:07Delay Fake Api
- 23:17When To Use this Library versus Other Ways To Write Tests
- 27:33Testing Flow
- 31:16Infinite Loop

