MainDispatcherFixture
Replaces Dispatchers.Main with dispatcher between install and reset, from shared code.
This is the multiplatform counterpart of the JUnit MainDispatcherRule, for tests in a commonTest source set that run on iOS as well as the JVM. Pair the two calls with kotlin.test's @BeforeTest and @AfterTest:
private val main = MainDispatcherFixture()
@BeforeTest fun setUp() = main.install()
@AfterTest fun tearDown() = main.reset()
@Test fun loads() = runTest(main.dispatcher) { ... }Content copied to clipboard
Prefer runTestWithMain when one test body is all that needs the dispatcher.