TestCoroutineScope

interface TestCoroutineScope : CoroutineScope

A scope which provides detailed control over the execution of coroutines for tests.

Functions

cleanupTestCoroutines
Link copied to clipboard
abstract fun cleanupTestCoroutines()

Called after the test completes.

Properties

testScheduler
Link copied to clipboard
abstract val testScheduler: TestCoroutineScheduler

The delay-skipping scheduler used by the test dispatchers running the code in this scope.

Extensions

advanceTimeBy
Link copied to clipboard
fun TestCoroutineScope.advanceTimeBy(delayTimeMillis: Long)

Advances the testScheduler by delayTimeMillis and runs the tasks up to that moment (inclusive).

advanceUntilIdle
Link copied to clipboard

Advances the testScheduler to the point where there are no tasks remaining.

currentTime
Link copied to clipboard

The current virtual time on testScheduler.

pauseDispatcher
Link copied to clipboard
suspend fun TestCoroutineScope.pauseDispatcher(block: suspend () -> Unit)
resumeDispatcher
Link copied to clipboard
runBlockingTest
Link copied to clipboard
fun TestCoroutineScope.runBlockingTest(block: suspend TestCoroutineScope.() -> Unit)

Convenience method for calling runBlockingTest on an existing TestCoroutineScope.

runCurrent
Link copied to clipboard

Run any tasks that are pending at the current virtual time, according to the testScheduler.

runTest
Link copied to clipboard
fun TestCoroutineScope.runTest(dispatchTimeoutMs: Long = DEFAULT_DISPATCH_TIMEOUT_MS, block: suspend TestCoroutineScope.() -> Unit): TestResult

Runs a test in a TestCoroutineScope based on this one.

uncaughtExceptions
Link copied to clipboard
val TestCoroutineScope.uncaughtExceptions: List<Throwable>

List of uncaught coroutine exceptions, for backward compatibility.