~/talk

Intro to unit testing coroutines with Kotest & MockK

Talkat droidcon Berlin 2023 · 2023-07-05..07-07· [testing, kotlin]
links:none on file
slides:none on file

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

  1. 0:00Introduction to coroutine testing
  2. 5:14Testing a mapper with Kotest
  3. 19:58Testing a use case with behavior spec
  4. 41:40Mocking dependencies with MockK
  5. 1:01:03Testing a ViewModel with flows
  6. 1:14:40Using ViewRobot for state assertions
  7. 1:28:15Q&A and closing remarks
~/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.