How would I write unit tests for this? ```Coroutin...
# announcements
b
How would I write unit tests for this?
Copy code
CoroutineScope(Dispatchers.Main).launch {
    withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
        // do something here
    }
}
It always stops after withContext(Dispatchers.IO), im adding the TestCoroutineDispatcher @rule but it still does not work.
a
try injecting the dispatchers
c
you need to inject a scope and testdispatcher in order to control the corotuines. This is a great article for getting started. It has some Android specifics in there but you can ignore those. https://medium.com/@daptronic/kotlin-coroutines-android-how-to-unit-test-lifecyclecoroutinescope-654ab324f3e7