Package dispatch.test

Types

Link copied to clipboard
@ExperimentalCoroutinesApi
class TestDispatcherProvider(default: CoroutineDispatcher, io: CoroutineDispatcher, main: CoroutineDispatcher, mainImmediate: CoroutineDispatcher, unconfined: CoroutineDispatcher) : DispatcherProvider

DispatcherProvider implementation for testing, where each property defaults to a TestCoroutineDispatcher.

Link copied to clipboard
@ExperimentalCoroutinesApi
interface TestProvidedCoroutineScope : TestCoroutineScope, DefaultCoroutineScope, IOCoroutineScope, MainCoroutineScope, MainImmediateCoroutineScope, UnconfinedCoroutineScope

A polymorphic testing CoroutineScope interface.

Functions

Link copied to clipboard
fun DefaultDispatcherProvider.reset()

Resets the singleton DispatcherProvider instance to the true default. This default instance delegates to the Dispatchers singleton object properties.

Link copied to clipboard
@ExperimentalCoroutinesApi
fun runBlockingProvided(context: CoroutineContext = EmptyCoroutineContext, block: suspend CoroutineScope.() -> Unit)

Delegates to runBlocking, but injects a DispatcherProvider into the created CoroutineScope.

Link copied to clipboard
@ExperimentalCoroutinesApi
fun TestBasicDispatcherProvider(): TestDispatcherProvider

"Basic" TestDispatcherProvider which mimics production behavior, without the automatic time control of TestCoroutineDispatcher and without the need for Dispatchers.setMain

Link copied to clipboard
@ExperimentalCoroutinesApi
fun TestDispatcherProvider(dispatcher: CoroutineDispatcher): TestDispatcherProvider

Convenience factory function for TestDispatcherProvider, creating an implementation where all properties point to the same underlying TestCoroutineDispatcher.

Link copied to clipboard
@ExperimentalCoroutinesApi
fun TestProvidedCoroutineScope.testProvided(testBody: suspend TestProvidedCoroutineScope.() -> Unit)
@ExperimentalCoroutinesApi
fun testProvided(context: CoroutineContext = EmptyCoroutineContext, testBody: suspend TestProvidedCoroutineScope.() -> Unit)

Delegates to runBlockingTest, but injects a DispatcherProvider into the created TestCoroutineScope.

Link copied to clipboard
@ExperimentalCoroutinesApi
fun TestProvidedCoroutineScope(dispatcher: TestCoroutineDispatcher = TestCoroutineDispatcher(), dispatcherProvider: TestDispatcherProvider = TestDispatcherProvider(dispatcher), context: CoroutineContext = EmptyCoroutineContext): TestProvidedCoroutineScope

Creates a TestProvidedCoroutineScope implementation with optional parameters of TestCoroutineDispatcher, TestDispatcherProvider, and a generic CoroutineContext.