runBlockingProvided

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

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

The resultant CoroutineContext will use a BlockingEventLoop as its default ContinuationInterceptor.

If the context does not contain a DispatcherProvider, a TestDispatcherProvider will be created using the kotlinx.coroutines.BlockingEventLoop interceptor.

Samples

import dispatch.internal.test.Sample5
import dispatch.test.TestProvidedCoroutineScope
import dispatch.test.runBlockingProvided
import dispatch.test.testProvided
import io.kotest.matchers.shouldBe
import kotlinx.coroutines.ExperimentalCoroutinesApi
import org.junit.jupiter.api.Test
fun main() { 
   //sampleStart 
   @Test
fun someTest() = runBlockingProvided {

  val subject = SomeClass(this)

  val myData = Data()

  subject.dataDeferred()
    .await() shouldBe myData
} 
   //sampleEnd
}

See also

runBlocking

Parameters

context

The base CoroutineContext which will be modified to use a TestCoroutineDispatcher and TestDispatcherProvider. EmptyCoroutineContext is used if one is not provided.

block

the action to be performed

Sources

Link copied to clipboard