CoroutineTest
open class CoroutineTest( context: CoroutineContext = EmptyCoroutineContext, 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
Constructors
Link copied to clipboard
constructor(context: CoroutineContext = EmptyCoroutineContext, testDispatcherBuilder: (TestCoroutineScheduler) -> TestDispatcher = { StandardTestDispatcher(it) })
Functions
Link copied to clipboard
Collects a flow in the background.
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
In addition to running the test this also disposes the attachedDisposables (useful with collectFlow).