~/talk

Unit Testing Kotlin Channels & Flows

Talkat Android Worldwide April 2021 · on Tuesday, 2021-04-27· [testing, kotlin]
speakerdeck:heyitsmohit
slides:none on file

Practical guide to testing Kotlin coroutines with focused examples: uses runBlockingTest and a TestCoroutineDispatcher to control virtual time, shows advancing time (advanceUntilIdle / advanceTimeBy) to exercise delays and retries, and injects a test dispatcher into viewmodel scope via setMain and a JUnit rule. Recommends Square’s Turbine for fluent assertions (expectItem, expectError, expectComplete) and explains pitfalls: rendezvous channels and sharedFlow never completing can leave jobs active unless tests advance the correct dispatcher and consume buffered events.

AI-written summary · about

  1. 0:00Start
  2. 2:33Run Blocking Test
  3. 8:06Types of Channels
  4. 14:35Flow Collector
  5. 14:56Result Type
  6. 16:20Delays
  7. 16:43Example of a Delay in a Curve in a Suspending Method
  8. 17:16Virtual Time
  9. 21:58Use Case for Having Delays inside of a Flow
  10. 26:23Jetpackviewmodel
  11. 27:26Shared Flow
  12. 35:44Resources
  13. 38:51Do You Have any Preferred Method or Is It Different To Test Combined Flows
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.