Hello! how can I make a test fail, even if it pass...
# coroutines
w
Hello! how can I make a test fail, even if it passed, when an exception happened on a coroutine/flow (Silent exceptions)? I tries passing the TestScope, and yes it fails but when there are no exceptions it hangs the test forever (because of .collect i guess)?
j
You should use structured concurrency so exceptions bubble up the right scope, so passing the test scope was a good idea. Regarding the hanging problem, instead of passing the test scope directly, you could use backgroundScope if you need long-running coroutines that should be canceled at the end of the test. Also, I think the new version of
runTest
actually fails on uncaught exceptions by default now (coroutines 1.7.0).
w
hahah ma man you saved the day coroutines 1.7.0 failed like a boss from the exception. Thank you so very much 💯
j
Happy to help 🙂