https://kotlinlang.org logo
#coroutines
Title
# coroutines
m

Marc Knaup

12/22/2020, 4:23 PM
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

Giorgos Neokleous

12/22/2020, 4:38 PM
What are you trying to test?
m

Marc Knaup

12/22/2020, 4:41 PM
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

Giorgos Neokleous

12/22/2020, 4:44 PM
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

Marc Knaup

12/22/2020, 5:01 PM
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 ❤️
4 Views