//reactivestate-core-test/com.ensody.reactivestate.test/CoroutineTest
CoroutineTest¶
open class CoroutineTest(testDispatcherBuilder: (TestCoroutineScheduler) -> TestDispatcher = { StandardTestDispatcher(it) }) : CoroutineTestRule, AttachedDisposables
Base class for unit testing coroutine based code.
On every test run this class automatically sets MainScope
and dispatchers to use a TestCoroutineDispatcher
.
Internally, this uses a CoroutineTestRule which does the actual dispatchers and Dispatchers.setMain()
setup. This allows accessing e.g. the testScope in your @Before
setup method.
Moreover, this provides an attachedDisposables attribute and a collectFlow helper, so you can activate SharingStarted.WhileSubscribed based flows created with derived, for example.
Inheritors¶
EventNotifierTest |
Constructors¶
CoroutineTest | [common] constructor(testDispatcherBuilder: (TestCoroutineScheduler) -> TestDispatcher = { StandardTestDispatcher(it) }) |
Properties¶
Name | Summary |
---|---|
attachedDisposables | [common] open override val attachedDisposables: DisposableGroup |
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 |
---|---|
collectFlow | [common] fun <T> TestScope.collectFlow(flow: Flow<T>, collector: suspend (T) -> Unit = {}) Collects a flow in the background. |
dispose | [common] open override fun dispose() |
enterCoroutineTest | [common] fun enterCoroutineTest() |
exitCoroutineTest | [common] fun exitCoroutineTest() |
runBlockingTest | [common] open fun ~~runBlockingTest~~(block: suspend TestScope.() -> Unit): TestResult |
runTest | [common] open override fun runTest(block: suspend TestScope.() -> Unit): TestResult In addition to running the test this also disposes the attachedDisposables (useful with collectFlow). |