ScopeFactory
Class used to create the TestProvidedCoroutineScope used in CoroutineTestExtension.
In order to provide a custom implementation of TestProvidedCoroutineScope:
Create a custom factory which has a default constructor and extends this
ScopeFactory
Annotate your test class with CoroutineTest and pass your custom factory's
KClass
in as its parameter.
Samples
import dispatch.test.CoroutineTest
import dispatch.test.CoroutineTestExtension
import dispatch.test.TestProvidedCoroutineScope
import io.kotest.matchers.shouldNotBe
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.Job
import kotlinx.coroutines.runBlocking
import org.junit.jupiter.api.Test
fun main() {
//sampleStart
class CoroutineTestNamedFactorySample {
class TestCoroutineScopeWithJobFactory : CoroutineTestExtension.ScopeFactory() {
override fun create(): TestProvidedCoroutineScope {
return TestProvidedCoroutineScope(context = Job())
}
}
@CoroutineTest(TestCoroutineScopeWithJobFactory::class)
class CustomFactorySample(val testScope: TestProvidedCoroutineScope) {
@Test
fun `injected scope should have a Job context`() = runBlocking {
testScope.coroutineContext[Job] shouldNotBe null
}
}
}
//sampleEnd
}
Constructors
Functions
Link copied to clipboard
Creates an instance of TestProvidedCoroutineScope. Uses the no-arg factory by default.