Effective Unit testing with Kotlin
summary
Forty minutes of live coding shows concrete recipes: replace JUnit asserts with Kluent assertions, prefer Mockito-Kotlin or MockK / Mockito-Kotlin for cleaner mocks and coroutine helpers like verifyBlocking or co-verify, and avoid global coroutines in tests. Coroutines testing uses runBlockingTest / the new runBlockingTest builder, a test coroutine dispatcher to advance virtual time (advanceTimeBy, triggerActions), capture and rethrow parallel exceptions, and override Dispatchers.Main during setup; several example classes (Tournament, Game, ImageFilter) get built and the fixes make the tests reliable.
AI-written summary · about
chapters (13)
- 0:00Live coding intro
- 1:07Kotlin unit testing basics
- 10:24Testing exceptions with JUnit 5
- 12:30Mocking in Kotlin
- 15:20Coroutines testing intro
- 17:30Challenges with suspend functions
- 20:39Blocking vs non-blocking coroutine tests
- 23:28Testing coroutine cancellation
- 26:36Test coroutine context
- 30:07Structured concurrency testing
- 38:07Coroutine dispatcher tests
- 41:00Future of coroutine testing
- 42:52Summary
related talks
42mUnit Testing Kotlin Channels & Flows
01h 29mIntro to unit testing coroutines with Kotest & MockK
28mTesting Out Kotlin
22mUnit Testing with KotlinFlow
32mTesting with Kotlin
47mFew Tools: How To Write And Understand! Coroutines Tests
38mUnit Testing Kotlin Flows
36mBest Practices for Unit Testing in Kotlin
