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.



Open Sourcer

Love podcasts or audiobooks? Learn on the go with our new app.