Skip to content

//reactivestate-core-test/com.ensody.reactivestate.test/CoroutineTestRule

CoroutineTestRule

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

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

CoroutineTest

Constructors

CoroutineTestRule [common]
constructor(testDispatcherBuilder: (TestCoroutineScheduler) -> TestDispatcher = { StandardTestDispatcher(it) })

Properties

Name Summary
mainScope [common]
val ~~mainScope~~: CoroutineScope
testCoroutineDispatcher [common]
val ~~testCoroutineDispatcher~~: TestDispatcher
testCoroutineScope [common]
val ~~testCoroutineScope~~: TestScope
testDispatcher [common]
val testDispatcher: TestDispatcher
testScope [common]
val testScope: TestScope

Functions

Name Summary
enterCoroutineTest [common]
fun enterCoroutineTest()
exitCoroutineTest [common]
fun exitCoroutineTest()
runBlockingTest [common]
open fun ~~runBlockingTest~~(block: suspend TestScope.() -> Unit): TestResult
runTest [common]
open fun runTest(block: suspend TestScope.() -> Unit): TestResult