Skip to content

Instantly share code, notes, and snippets.

@CDRussell
Created April 12, 2019 00:02
Show Gist options
  • Save CDRussell/527e44d83e3c508ffd422dadbb801981 to your computer and use it in GitHub Desktop.
Save CDRussell/527e44d83e3c508ffd422dadbb801981 to your computer and use it in GitHub Desktop.
class ErrorHandler(private val logger: Logger) {
fun handleError() {
GlobalScope.launch(Dispatchers.IO) {
heavyOperation()
logger.logErrorEvent()
}
}
@Test
fun test() = runBlocking<Unit> {
val testee = ErrorHandler(logger)
testee.handleError()
verify(logger).logErrorEvent()
}
@CDRussell
Copy link
Author

Example of a failing unit test.

This test will fail because the unit test will complete before the coroutine will have had a change to launch and execute.

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