Adam Hurwitz
1 min readJun 13, 2020

--

Lukasz Kalnik, similar to the CoroutineDispatcher, CoroutineScope needs to be injected into the ViewModel (VM) for testing.

The viewModelScope is created within the VM. Therefore, the CoroutineScope is only passed as an argument for test VMs, otherwise the default argument is set to null, and the scope provider extension function created uses the VM's viewModelScope.

Here is how I injected CoroutineScope. I recommend Craig Russell’s post for injecting the CoroutineDispatcher.

--

--

Adam Hurwitz

An account about nothing | Researcher and product consultant