Skip to content

Instantly share code, notes, and snippets.

@manuelvicnt
Last active September 12, 2023 07:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manuelvicnt/049ce057fa6b5e5c785ec9fff7c22a7c to your computer and use it in GitHub Desktop.
Save manuelvicnt/049ce057fa6b5e5c785ec9fff7c22a7c to your computer and use it in GitHub Desktop.
@ExperimentalCoroutinesApi
class CoroutinesTestRule(
val testDispatcher: TestCoroutineDispatcher = TestCoroutineDispatcher()
) : TestWatcher() {
override fun starting(description: Description?) {
super.starting(description)
Dispatchers.setMain(testDispatcher)
}
override fun finished(description: Description?) {
super.finished(description)
Dispatchers.resetMain()
testDispatcher.cleanupTestCoroutines()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment