set
Override the default MainImmediateCoroutineScope factory, for testing or to include a custom CoroutineContext in production code. This may be done in Application.onCreate
Samples
import dispatch.android.espresso.MainImmediateIdlingCoroutineScope
import dispatch.android.viewmodel.ViewModelScopeFactory
import dispatch.core.MainImmediateCoroutineScope
import dispatch.internal.test.Sample5
import dispatch.test.TestProvidedCoroutineScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
fun main() {
//sampleStart
class MyApplication : Application {
override fun onCreate() {
ViewModelScopeFactory.set { MainImmediateCoroutineScope() }
}
}
//sampleEnd
}
import dispatch.android.espresso.MainImmediateIdlingCoroutineScope
import dispatch.android.viewmodel.ViewModelScopeFactory
import dispatch.core.MainImmediateCoroutineScope
import dispatch.internal.test.Sample5
import dispatch.test.TestProvidedCoroutineScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
fun main() {
//sampleStart
class MyEspressoTest {
@Before
fun setUp() {
ViewModelScopeFactory.set { MainImmediateIdlingCoroutineScope() }
}
}
//sampleEnd
}
import dispatch.android.espresso.MainImmediateIdlingCoroutineScope
import dispatch.android.viewmodel.ViewModelScopeFactory
import dispatch.core.MainImmediateCoroutineScope
import dispatch.internal.test.Sample5
import dispatch.test.TestProvidedCoroutineScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
fun main() {
//sampleStart
class MyJvmTest {
@Before
fun setUp() {
ViewModelScopeFactory.set { TestProvidedCoroutineScope() }
}
}
//sampleEnd
}
Parameters
factory
sets a custom CoroutineScope factory to be used for all new instance creations until reset.