public class TestCoroutineContextKt
| Modifier and Type | Method and Description |
|---|---|
static void |
withTestContext(TestCoroutineContext testContext,
kotlin.jvm.functions.Function1<? super kotlinx.coroutines.test.TestCoroutineContext,kotlin.Unit> testBody)
Executes a block of code in which a unit-test can be written using the provided
class TestCoroutineContext. The provided
class TestCoroutineContext is available in the testBody as the this receiver. |
public static void withTestContext(TestCoroutineContext testContext, kotlin.jvm.functions.Function1<? super kotlinx.coroutines.test.TestCoroutineContext,kotlin.Unit> testBody)
Executes a block of code in which a unit-test can be written using the provided class TestCoroutineContext. The provided
class TestCoroutineContext is available in the testBody as the this receiver.
The testBody is executed and an AssertionError is thrown if the list of unhandled exceptions is not empty and contains any exception that is not a CancellationException.
If the testBody successfully executes one of the TestCoroutineContext.assertAllUnhandledExceptions,
TestCoroutineContext.assertAnyUnhandledException, TestCoroutineContext.assertUnhandledException or
TestCoroutineContext.assertExceptions, the list of unhandled exceptions will have been cleared and this method will
not throw an AssertionError.
Note: This API will become obsolete in future updates due to integration with structured concurrency. See https://github.com/Kotlin/kotlinx.coroutines/issues/541.
testContext - The provided class TestCoroutineContext. If not specified, a default class TestCoroutineContext will be
provided instead.testBody - The code of the unit-test.class TestCoroutineContext,
class TestCoroutineContext,
AssertionError,
TestCoroutineContext.assertAllUnhandledExceptions,
TestCoroutineContext.assertAnyUnhandledException,
TestCoroutineContext.assertUnhandledException,
TestCoroutineContext.assertExceptions,
AssertionError,
https://github.com/Kotlin/kotlinx.coroutines/issues/541