Skip to content

Instantly share code, notes, and snippets.

@Jeff-Soares
Last active December 28, 2021 01:33
Show Gist options
  • Save Jeff-Soares/0b51fa04bafca289b8e3a4db70ce9b1e to your computer and use it in GitHub Desktop.
Save Jeff-Soares/0b51fa04bafca289b8e3a4db70ce9b1e 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()
}
}
class UnitTest {
@get:Rule
var coroutinesTestRule = CoroutineTestRule()
@Test
fun test() {
TODO()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment