https://kotlinlang.org logo
#coroutines
Title
# coroutines
s

streetsofboston

01/09/2018, 8:58 PM
Hi everyone, This goes back to my earlier post about being able to quickly unit-test functions that execute coroutines. Especially if these functions have timeouts or delays and you’d like to run each of your tests in milliseconds and not seconds, I wrote a
CoroutineContext
that allows you to do so. It is very much like the RxJava’s
TestScheduler
and its methods
triggerActions
,
advanceTimeBy
, etc. It does so by implementing a Coroutine Dispatcher (for speeding up (virtual) time) and a Coroutine Exception Handler (for testing thrown exceptions). The main
TestCoroutineContext
class and some unit-tests can be found here: https://gist.github.com/streetsofboston/6ea225c61566e6d349883082fbb9f020
👍🏽 2
metal 2
Note that there may be some issues with this implementation. This gist is an initial draft. The attache Unit-tests all run successfully, but I may have missed something. If you find an issue with the
TestCoroutineContext
, please let me know. Thank you!
6 Views