# Coroutine Testing

DevFeed: [Coroutine Testing](<https://devfeed.tech/articles/coroutine-testing-25239.md>)

Original publisher: [Read original article](<https://kau.sh/blog/coroutine-testing/>)

Author: Kaushik Gopal

Published: 2024-08-25T07:00:45Z

Content type: tutorial

Language: en

Sources: [Kaushik Gopal's Site](<https://devfeed.tech/sources/kaushik-gopal-s-site.md>)

Topics: [Coroutines](<https://devfeed.tech/topics/coroutines.md>), [Testing](<https://devfeed.tech/topics/testing.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Concurrency](<https://devfeed.tech/topics/concurrency.md>), [LineageOS](<https://devfeed.tech/topics/lineageos.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [concurrency](<https://devfeed.tech/tags/concurrency.md>), [coroutine](<https://devfeed.tech/tags/coroutine.md>), [coroutine-testing](<https://devfeed.tech/tags/coroutine-testing.md>), [coroutines](<https://devfeed.tech/tags/coroutines.md>), [dispatcher](<https://devfeed.tech/tags/dispatcher.md>), [flaky](<https://devfeed.tech/tags/flaky.md>), [junit](<https://devfeed.tech/tags/junit.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [migration-guide](<https://devfeed.tech/tags/migration-guide.md>), [testing](<https://devfeed.tech/tags/testing.md>), [time](<https://devfeed.tech/tags/time.md>), [tutorials](<https://devfeed.tech/tags/tutorials.md>)

## AI overview

A tutorial series on testing Kotlin coroutines in Android applications. It discusses changes to Kotlin testing APIs, unreliable virtual-time advancement, flaky tests, dispatchers, background scopes, and controlling time.

## Source excerpt

When the #androiddevs transitioned from Rx to coroutines the topic of testing didn't get as much attention in this new world of concurrency. It didn't help that there was a seismic change in Kotlin's testing apis with 1.6.0. A whole bunch of online resources and tutorials are now defunct courtesy this change.1 My journey in the matter started because I simply couldn't understand why test apis like advanceTimeBy wouldn't work reliably for me. The name made sense... but my time wasn't being advanced in any meaningful way. Then there's the issue of flaky tests. Here's an example: flaky test code on github Run each test individually and it will pass; run them together as one test suite and test2 alone will fail. test1 passes but it takes a full 3s to run the test. If I have 300 of these in my app, are my tests going to take 15 minutes to run? I needed to understand many core concepts in order to confidently explain all the above phenomena. I'd like to share my learnings from going down the rabbit hole, in this series of posts: series This is part of a series of posts on Coroutine Testing: <- Picking the right Dispatcher Never ending tests & backgroundscope Controlling time Helpful @Junit TestRule extension (coming soon) Full USF example for Android (coming soon) If you're looking for the most current and useful resources on coroutine testing today: Untangling Coroutine Testing - Marton Braun jetbrains official docs developer.android.com docs 1.6.0 Coroutines test migration guide ↩︎