TestCoroutineDispatcher

CoroutineDispatcher that performs both immediate and lazy execution of coroutines in tests and uses a TestCoroutineScheduler to control its virtual clock.

By default, TestCoroutineDispatcher is immediate. That means any tasks scheduled to be run without delay are immediately executed. If they were scheduled with a delay, the virtual clock-time must be advanced via one of the methods on the dispatcher's scheduler.

When switched to lazy execution using pauseDispatcher any coroutines started via launch or async will not execute until a call to DelayController.runCurrent or the virtual clock-time has been advanced via one of the methods on DelayController.

See also

Constructors

TestCoroutineDispatcher
Link copied to clipboard
fun TestCoroutineDispatcher(scheduler: TestCoroutineScheduler = TestCoroutineScheduler())

Properties

scheduler
Link copied to clipboard
open override val scheduler: TestCoroutineScheduler

The scheduler that this dispatcher is linked to.

Extensions

runBlockingTest
Link copied to clipboard
fun TestCoroutineDispatcher.runBlockingTest(block: suspend TestCoroutineScope.() -> Unit)

Convenience method for calling runBlockingTest on an existing TestCoroutineDispatcher.