我在 kotest 中使用了 Funspec 测试风格,我得到了一个由框架自动注入(inject)的 coroutineScope,如下所示。
class MyTestSpec: FunSpec() {
init {
test("test event loop") {
mySuspendedFunction() // a coroutineScope is already injected by the test framework here
}
}
}
如何配置 Kotest 框架以在我的测试中使用 kotlinx.coroutines.test.TestCoroutineScope
而不是 kotlinx.coroutines.CoroutineScope
的实例?或者为什么这没有意义?
最佳答案
从 Kotest 5.0 开始,内置了对 TestCoroutineDispatcher
的支持。参见 here
简单地:
class MyTest : FunSpec(
{
test("do your thing").config(testCoroutineDispatcher = true) {
}
}
)
关于kotlin-coroutines - Kotest 与 kotlinx-coroutines-test 集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69417255/