Sorry if this was already asked. There's an way th...
# coroutines
i
Sorry if this was already asked. There's an way that I can ignore the
delays
from coroutines in android espresso testing?
s
If you did inject your CoroutineContexts (through a dependency injection framework), you can replace those with a singleton
TestCoroutineContext
. Then in your tests, you can forward time by calling
advanceTimeBy
or
advanceTimeTo
(or
triggerActions
) on this
TestCoroutineContext
.
👍 3
d
I use the TestCoroutineScope pattern, same thing but a Scope instead of the Context.
i
Hmm I'm not injecting the context. I was searching and found this: https://github.com/Kotlin/kotlinx.coroutines/tree/master/kotlinx-coroutines-test I was thinking in an way to use it. Also, I try this
TestCoroutineContext
in an unit test with mockwebserver, and it gets in a infinite-loop, the test never finishes. (It worked on a simple test with delay)