https://kotlinlang.org logo
Title
m

Maciek

03/25/2020, 8:08 PM
I've got a test with
runBlockingTest
function. From this test I'm running code that launches coroutine from
MainScope
object that is suppose to have
TestCoroutineDispatcher
but I can't seem to run
delay
function inside that coroutine because I'm getting
UncompletedCoroutinesError
exception. Is my test setup wrong or I just can't test a code that has
delay
functions? I don't really need that delay but was just wondering why it doesn't work, I thought that runBlocking and TestCoroutineDispatcher will take care of such cases
I think I've got a problem with junit5 extension (rule in junit4), I'm running the code to replace the dispatcher but that doesn't have desired effect..
d

Dennis

03/25/2020, 9:31 PM
do you have some code to show?
l

liminal

03/26/2020, 1:47 AM
Which
runBlockingTest
are you using? You may be running into this issue https://craigrussell.io/2019/11/unit-testing-coroutine-suspend-functions-using-testcoroutinedispatcher/
👍 1
m

Maciek

03/26/2020, 6:25 AM
very nice article, thanks James!
@Dennis that's the code that fails
oh, it does work correctly with
TestCoroutineDispatcher.runBlockingTest
but now I can't use my test extension from junit5 because it's not like junit4 rule where you're defining it as a class member
I can use it in an old fashion way with a class member thanks to
@RegisterExtension
field, now everything works, thanks!