I got a coroutine test, where I use the `TestScope...
# coroutines
s
I got a coroutine test, where I use the
TestScope
provided inside the
runTest{}
function to pass it to a
launchIn
function to create a hot StateFlow. Problem is, the test this way never ends since the coroutineScope always has something to do therefore
runTest
times out and fails my test. I’ve “fixed” this by adding the line
this.coroutineContext.cancelChildren()
as the last line of my test after everything I’ve asserted was correct and so on. Is this considered okay or should I really be careful with something like this? Feels like I’m doing something in a way which doesn’t solve the root cause but patches it, but could be wrong.
s
Well, that was easy, so glad I asked here! So the idea is that this one is meant to be handling such background work, and is fine to still be running at the end of the test, where it gets cancelled instead of me having to do it right?
d
Yep.
s
Thank you so much Dmitry!