Is there any way / workaround to test `kotlinx-cor...
# coroutines
m
Is there any way / workaround to test
kotlinx-coroutines-reactive
-based coroutines using
runBlockingTest
? The related issue (https://github.com/Kotlin/kotlinx.coroutines/issues/1204) and pull request (https://github.com/Kotlin/kotlinx.coroutines/pull/1206) seem to be abandoned for a long time.
g
What are you trying to test?
m
I've wrapped an RxJava based API as a coroutines based API using said library. However I cannot test any code where that API is involved because the coroutine testing dispatcher doesn't seem to support it.
g
If you are wrapping to Flows, I recommend Turbine. I also I found this article extremely useful for understanding how to go about testing Flows.
m
Interesting 🙂 But I’m not testing any
Flow
here though.
Found an ugly workaround 😅
Copy code
launch { delay(100); repeat(100) { Thread.sleep(10); yield() } }
right before calling my reactive-based coroutines. That gives these coroutines a chance to complete their work before the test dispatcher is responsive again, which avoids the problem.
runBlocking {}
also helps ❤️