0PricingLogin
Kotlin Multiplatform Academy · Lesson

Test suspend Functions & Flows

Use runTest and Turbine to assert async behavior.

Async Needs Special Tests

Suspend functions and Flows do not finish instantly, so you need tools that wait for async work before asserting. ⏳

Meet runTest

Wrap async assertions in runTest from the coroutines-test library; it provides a scope and skips virtual delays automatically.

@Test
fun loadsUser() = runTest {
    val u = repo.load(1)
    assertEquals("Sam", u.name)
}

All lessons in this course

  1. kotlin.test in commonTest
  2. Test suspend Functions & Flows
  3. Fake the Ktor Client & Repos
  4. Run Tests on Android & iOS Targets
← Back to Kotlin Multiplatform Academy