is there a way to introduce a delay that can be skipped in a test?
I tried using
Copy code
runBlocking {
delay(10000)
}
and then testing it with
runBlockingTest
, but since it’s in another
runBlocking
block the delay is not being skipped and my test is, in fact, hanging for 10 secs.
I’d like to test that the delay is indeed executed but without really having to wait for it to expire
f
Francois Stiennon
12/11/2020, 1:57 PM
if you have dependency injection you can inject a mocked instance with the duration of the delay
m
Mattia Tommasone
12/11/2020, 1:57 PM
yep that’s kind of my last resort but i was hoping for something less invasive 🙂
g
gildor
12/11/2020, 2:49 PM
Only setting dispatcher will help
But in general it's already problematic to test properly if you use runBlocking, test suspend, non blocking functions is a lot easier
m
Mattia Tommasone
12/11/2020, 2:54 PM
i know, but it’s a camel message handler and they don’t play well with suspend
g
gildor
12/11/2020, 3:14 PM
Injecting test dispatcher and use it for runBlocking should work