https://kotlinlang.org logo
Title
p

pablisco

12/07/2018, 2:21 PM
Good asynchronous people. Do we have a way to not use the Android Dispatcher for
Dispatchers.Main
when running on the test configuration (e.g. Unit tests)
s

streetsofboston

12/07/2018, 2:23 PM
For now, although it is deprecated and will be modified to integrate better in structured concurrency, you could use the
TestCoroutineContext
. E.g. instead of
SuperviserJob() + Dispatcher.Main
you could do
SuperviserJob() + testCoroutineContext
, where
testCoroutineContext
is a singleton instance of
TestCoroutineContext
and you can control it in your unit-test code.
p

pablisco

12/07/2018, 2:37 PM
Yeah, I was hopping to use the default
Dispatcher.Main
as that one should be ok for the test I'm running instead of the one that is injected by services for android... I'm trying to remove the dependency to
coroutines-android
for the test configuration 🤔
v

Vsevolod Tolstopyatov [JB]

12/07/2018, 4:18 PM
There will be
coroutines-test
in 1.1 🙂
👍 2
s

streetsofboston

12/07/2018, 4:23 PM
@Vsevolod Tolstopyatov [JB] How will the
TestCoroutineContext
, or its replacement, fit into this, since it is marked as obsolete/deprecated?
v

Vsevolod Tolstopyatov [JB]

12/07/2018, 4:24 PM
Replacement of
TestCoroutineContext
will be part of this module, but not in 1.1