curioustechizen
01/30/2019, 3:34 PMansman
01/30/2019, 3:42 PMrunBlocking
(you create a new one) and your view model. If you do runBlocking(viewModel)
it might workcurioustechizen
01/30/2019, 3:43 PMcurioustechizen
01/30/2019, 3:44 PMansman
01/30/2019, 3:44 PMrunBlocking
ansman
01/30/2019, 3:48 PMTestCoroutineContext
into a property and pass that to runBlocking
curioustechizen
01/30/2019, 3:51 PMrunBlocking(testCoroutineContext)
did the trick.streetsofboston
01/30/2019, 3:53 PMDispatchers.Unconfined
instead of the testCoroutineContext
?curioustechizen
01/30/2019, 3:55 PMTestCoroutineContext
curioustechizen
01/30/2019, 3:56 PMdelay
- instead our suspend function wraps an existing callback-based API. It looks like this solution of using the same context for runBlocking
as in the viewModel
is the right solution in that casecurioustechizen
01/30/2019, 3:57 PMansman
01/30/2019, 3:57 PMstreetsofboston
01/30/2019, 4:04 PMTestCoroutineContext
in your test-case instead of a plain `Dispatchers.Unconfined`…. I wrote the TestCoroutineContext
class. The class is not very useful when you don’t need to call triggerActions
, advanceTimeBy
or advanceTimeTo
on it.curioustechizen
01/30/2019, 4:06 PMDispatchers.Unconfined
but ran into some nullability exception. I guess if I spend some more time on it I can figure out how to use it too.streetsofboston
01/30/2019, 4:08 PMEmptyCoroutineContext
?curioustechizen
01/30/2019, 4:29 PMEmptyCoroutineContext
I also have the test failing. It doesn't make sense to me because the way I understand it - everything should work as long as the same coroutine context is sharedstreetsofboston
01/30/2019, 4:33 PMTestCoroutineContext
works, that’s great! 🙂
I would love to know why, though. It probably has something to do with the internal Dispatcher of the TestCoroutineContext, but the Unconfined or EmptyCoroutineContext should have similar behavior…..curioustechizen
01/31/2019, 8:23 AMTestCoroutineContext
and updated the github repo. I'll leave it there in case anyone wants to take a look, or try to dig into ways to achieve it using Unconfined
or EmptyCorutineContext