Created
April 12, 2019 00:26
-
-
Save CDRussell/2686c2cfd0df828a0566cc1519c6d291 to your computer and use it in GitHub Desktop.
This file contains 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 ExampleViewModel(private val logger: Logger) : ViewModel() { | |
@VisibleForTesting | |
var job: Job? = null | |
fun handleError() { | |
job = viewModelScope.launch(Dispatchers.IO) { | |
heavyOperation() | |
logger.logErrorEvent() | |
} | |
} | |
} |
This file contains 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 ExampleViewModelTest { | |
private val logger: Logger = mock() | |
private val testee: ExampleViewModel = ExampleViewModel(logger) | |
@Test | |
fun test() = runBlocking { | |
testee.handleError() | |
testee.job?.join() | |
verify(logger).logErrorEvent() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Test passes