MainTestDispatcherExtension

class MainTestDispatcherExtension(dispatcherFactory: () -> TestDispatcher = { StandardTestDispatcher() }) : BeforeEachCallback, AfterEachCallback

Installs Dispatchers.Main with a TestDispatcher for each test method.

Use with @ExtendWith(MainTestDispatcherExtension::class) or @MainTestDispatcher. Access the active dispatcher via dispatcher when the extension is registered as a field:

@ExtendWith(MainTestDispatcherExtension::class)
class MyViewModelTest {
@RegisterExtension
@JvmField
val main = MainTestDispatcherExtension()

@Test
fun loads() = runTest(main.dispatcher) { … }
}

Constructors

Link copied to clipboard
constructor(dispatcherFactory: () -> TestDispatcher = { StandardTestDispatcher() })

Properties

Link copied to clipboard
lateinit var dispatcher: TestDispatcher

Functions

Link copied to clipboard
open override fun afterEach(context: ExtensionContext)
Link copied to clipboard
open override fun beforeEach(context: ExtensionContext)