Coroutine Testing
Test suspend functions.
Why Coroutine Testing is Special
Coroutines run asynchronously and may use delays. Tests need controlled time and a way to wait for suspend functions to finish.
The kotlinx-coroutines-test library provides exactly this.
Adding the Test Library
Add the coroutines test artifact to your test dependencies.
dependencies {
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.8.1")
}All lessons in this course
- Writing Tests with JUnit5
- Assertions
- Mocking with MockK
- Coroutine Testing