Created
January 12, 2020 00:04
-
-
Save RBusarow/81b38ec01904d64500137bfccad30d62 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 CoroutineTestRule : TestRule, | |
TestPolymorphicCoroutineScope by TestPolymorphicCoroutineScope() { | |
val dispatcher = coroutineContext[ContinuationInterceptor] as TestCoroutineDispatcher | |
override fun apply( | |
base: Statement, description: Description? | |
) = object : Statement() { | |
override fun evaluate() { | |
@Throws(Throwable::class) | |
override fun evaluate() { | |
Dispatchers.setMain(dispatcher) | |
base.evaluate() | |
cleanupTestCoroutines() | |
Dispatchers.resetMain() | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment