Skip to content

Instantly share code, notes, and snippets.

@zsmb13
Last active June 29, 2022 12:13
Show Gist options
  • Save zsmb13/954caffc3309b3743ed2bb6fb93df0df to your computer and use it in GitHub Desktop.
Save zsmb13/954caffc3309b3743ed2bb6fb93df0df to your computer and use it in GitHub Desktop.
// Copyright 2022 Google LLC.
// SPDX-License-Identifier: Apache-2.0
class MainDispatcherRule(
- val testDispatcher: TestCoroutineDispatcher = TestCoroutineDispatcher(),
+ val testDispatcher: TestDispatcher = UnconfinedTestDispatcher(),
) : 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