1 min readJun 13, 2020
, 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 ’s post for injecting the CoroutineDispatcher.