Hello guys anyone here knows if there’s a way to ...
# coroutines
v
Hello guys anyone here knows if there’s a way to test coroutines with espresso I mean is not detecting the async process as usually espresso does, so is going forward into the testing code without await ?
l
@vitrox1 I'd use
Copy code
runBlocking {
    ...//your test with async code that you await
}
from kotlinx.coroutines
👍 1
v
thanks i’ll try it then!
s
I used this to not use
runBlocking
and have my tests finish quickly
l
@streetsofboston Not using
runBlocking
or similar means any exception in your tests that happens async or after any suspension point don't get caught silently! 🚨
s
That’s true. But sometimes you can’t have your test-suite take seconds go run, especially when using
delay
and such. I wonder if it is possible to catch exceptions when not using runBlocking when creating your own CoroutineContext.
l
@streetsofboston The long tests are not meant to be run on each build or each modification. Also, IIRC, there's test duration hint annotations for Android (which seems to be what you're using)
Also, if you test your code, it's that you have doubts 🤔 🧌 More seriously, it's important to make sure your tests are right and don't pass silently ignoring unexpected failures. Flaky tests are worst than no tests
s
Yes, you’re right that you can annotate your tests, but for some things you’d like your tests to run as fast as possible, much like when your code under test encounters Rx Java. I’ll look if I can modify my
TestCoroutineContext
to catch any thrown exception and have it report it.
l
@streetsofboston FYI,
runBlocking { … }
has seen performance improvements in a very recent update (0.20 IIRC)