Skip to content

Instantly share code, notes, and snippets.

@CDRussell
Created April 12, 2019 00:29
Show Gist options
  • Save CDRussell/ba7a0a9be3f191641a9a7694f9086ed2 to your computer and use it in GitHub Desktop.
Save CDRussell/ba7a0a9be3f191641a9a7694f9086ed2 to your computer and use it in GitHub Desktop.
class ExampleViewModel(private val logger: Logger) : ViewModel() {
fun handleError() {
viewModelScope.launch(Dispatchers.IO) {
heavyOperation()
logger.logErrorEvent()
}
}
}
class ExampleViewModelTest {
private val logger: Logger = mock()
private val testee: ExampleViewModel = ExampleViewModel(logger)
@Test
fun test() = runBlocking {
testee.handleError()
verify(logger).logErrorEvent()
}
}
@CDRussell
Copy link
Author

Test fails

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment