CoroutineTestRule

open class CoroutineTestRule(testDispatcherBuilder: (TestCoroutineScheduler) -> TestDispatcher = { StandardTestDispatcher(it) }, context: CoroutineContext = EmptyCoroutineContext)

Helper class for unit Tests that sets up dispatchers with a TestDispatcherConfig on every test run.

Also, Dispatchers.Main is set to a TestScope.

This rule allows for e.g. setup methods with @Before which need access to the TestScope.

Use the runTest method provided by this rule instead of the one provided by the coroutines library.

You can also access the testScope and testDispatcher in case you need them to e.g. launch some background process during each test.

Inheritors

Constructors

Link copied to clipboard
constructor(testDispatcherBuilder: (TestCoroutineScheduler) -> TestDispatcher = { StandardTestDispatcher(it) }, context: CoroutineContext = EmptyCoroutineContext)

Properties

Link copied to clipboard
val testDispatcher: TestDispatcher
Link copied to clipboard
val testScope: TestScope

Functions

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open fun runTest(block: suspend TestScope.() -> Unit): TestResult