Last active
May 16, 2019 10:58
-
-
Save manuelvicnt/bdee5bd099cb2535d0c30c113bdba520 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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