Order the steps
Order a ViewModel error-path test.
- Create a fake repository set to fail
- Construct the ViewModel with the fake
- Assert UiState shows the error and isn't loading
- Set Main to a test dispatcher with a rule
- Call
onRefresh()and advance until idle
Choose an answer, then open Show answer below to check it.
Show answer
Answer: D A B E C
- Set Main to a test dispatcher with a rule viewModelScope uses Main.
- Create a fake repository set to fail Controls the error path.
- Construct the ViewModel with the fake Constructor injection makes this easy.
- Call
onRefresh()and advance until idle Run the coroutine. - Assert UiState shows the error and isn't loading Check what the user would see.