Last active
January 19, 2020 21:25
-
-
Save CostaFot/b690f92be527c899f8321d434804430e 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
@ExperimentalCoroutinesApi | |
class CoroutineTestRule( | |
val testDispatcher: TestCoroutineDispatcher = TestCoroutineDispatcher() | |
) : TestWatcher() { | |
val testDispatcherProvider = object : DispatcherProvider { | |
override val io: CoroutineDispatcher = testDispatcher | |
override val ui: CoroutineDispatcher = testDispatcher | |
override val default: CoroutineDispatcher = testDispatcher | |
override val unconfined: CoroutineDispatcher = testDispatcher | |
} | |
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