runBlockingTest

fun runBlockingTest(context: CoroutineContext = EmptyCoroutineContext, testBody: suspend TestCoroutineScope.() -> Unit)(source)

Deprecated

Use `runTest` instead to support completing from other dispatchers. Please see the migration guide for details: https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-test/MIGRATION.md

Executes a testBody inside an immediate execution dispatcher.

This method is deprecated in favor of runTest. Please see the migration guide for an instruction on how to update the code for the new API.

This is similar to runBlocking but it will immediately progress past delays and into launch and async blocks. You can use this to write tests that execute in the presence of calls to delay without causing your test to take extra time.

@Test
fun exampleTest() = runBlockingTest {
val deferred = async {
delay(1_000)
async {
delay(1_000)
}.await()
}

deferred.await() // result available immediately
}

This method requires that all coroutines launched inside testBody complete, or are cancelled, as part of the test conditions.

Unhandled exceptions thrown by coroutines in the test will be re-thrown at the end of the test.

Parameters

context

additional context elements. If context contains CoroutineDispatcher or CoroutineExceptionHandler, then they must implement DelayController and TestCoroutineExceptionHandler respectively.

testBody

The code of the unit-test.

Throws

If the testBody does not complete (or cancel) all coroutines that it launches (including coroutines suspended on join/await).


Deprecated

Use `runTest` instead to support completing from other dispatchers. Please see the migration guide for details: https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-test/MIGRATION.md

Convenience method for calling runBlockingTest on an existing TestCoroutineScope.

This method is deprecated in favor of runTest, whereas TestCoroutineScope is deprecated in favor of TestScope. Please see the migration guide for an instruction on how to update the code for the new API.


fun TestScope.runBlockingTest(block: suspend TestScope.() -> Unit)(source)

Deprecated

Use `runTest` instead to support completing from other dispatchers.

Convenience method for calling runBlockingTestOnTestScope on an existing TestScope.


Deprecated

Use `runTest` instead to support completing from other dispatchers. Please see the migration guide for details: https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-test/MIGRATION.md

Convenience method for calling runBlockingTest on an existing TestCoroutineDispatcher.

This method is deprecated in favor of runTest, whereas TestCoroutineScope is deprecated in favor of TestScope. Please see the migration guide for an instruction on how to update the code for the new API.