Skip to content

Instantly share code, notes, and snippets.

@manuelvicnt
Last active May 16, 2019 10:58
Show Gist options
  • Save manuelvicnt/bdee5bd099cb2535d0c30c113bdba520 to your computer and use it in GitHub Desktop.
Save manuelvicnt/bdee5bd099cb2535d0c30c113bdba520 to your computer and use it in GitHub Desktop.
class MainViewModel(private val dependency: Any): ViewModel {
fun sampleMethod() {
viewModelScope.launch {
val hashCode = dependency.hashCode()
// TODO: do something with hashCode
}
}
class MainViewModelUnitTest {
// Mockito setup goes here
...
@get:Rule
var coroutinesTestRule = CoroutinesTestRule()
@Test
fun test() = coroutinesTestRule.testDispatcher.runBlockingTest {
val subject = MainViewModel(mockObject)
subject.sampleMethod()
// Checks mockObject called the hashCode method that is expected from the coroutine created in sampleMethod
verify(mockObject).hashCode()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment