I’m trying to migrate my `runBlockingTest`s into `...
# coroutines
a
I’m trying to migrate my `runBlockingTest`s into
runTest
following this migration guide. I’m struggling to migrate my test code which expects the dispatcher to be unpaused throughout the whole test. Is there a way to do this or do I really have to call
runCurrent()
for every step I want to assert?
n
Sounds like you are looking for
UnconfinedTestDispatcher
which is covered in that migration guide. FYI, I prefer to add
runCurrent
for every step anyways to make my tests more robust. I've had to add
runCurrent
later after tests started failing only because adjusting the implementation changed what the test dispatcher ran automatically.
👍 1
a
Yeah… I thought so too, but
UnconfinedTestDispatcher
doesn’t really work most of the time. You don’t know when it’s not going to work so it seems better to do
runCurrent
as you say 😅 Not having to think about coroutines except for complex cases was so convenient for our team, but now that we update to latest Kotlin that option is deprecated.
s
This is quite late, but I watched this yesterday and it seems like it’s perfect to help you understand what choice you want to make. If you’re still struggling with it I hope it can help.

https://www.youtube.com/watch?v=hzTU0lh-TIw

a
Thank you, watched all of it and it's exactly what I needed to know. The test api migration guide is very confusing compared to this.
s
Heh this was quite an old thread so I thought it wouldn't help you but it did, I'm so glad 🤗
a
And it confirmed the fact that I'm f'd if a library decides to hardcode the io dispatcher. runBlockingTest would work but not this new api, apparently