testProvided

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

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

If the context's ContinuationInterceptor is not a TestCoroutineDispatcher, then a new TestCoroutineDispatcher will be created.

If the context does not contain a DispatcherProvider, a TestDispatcherProvider will be created using the TestCoroutineDispatcher.

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() = testProvided {

  val subject = SomeClass(this)

  val myData = Data()

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

See also

runBlockingTest

Parameters

context

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

testBody

the action to be performed


@ExperimentalCoroutinesApi
fun TestProvidedCoroutineScope.testProvided(testBody: suspend TestProvidedCoroutineScope.() -> Unit)

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

If the context's ContinuationInterceptor is not a TestCoroutineDispatcher, then a new TestCoroutineDispatcher will be created.

If the context does not contain a DispatcherProvider, a TestDispatcherProvider will be created using the TestCoroutineDispatcher.

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() = testProvided {

  val subject = SomeClass(this)

  val myData = Data()

  subject.dataDeferred()
    .await() shouldBe myData
} 
   //sampleEnd
}
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 
   val scope = TestProvidedCoroutineScope()

@Test
fun someTest() = scope.testProvided {

  val subject = SomeClass(this)

  val myData = Data()

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

See also

runBlockingTest