gpt4 book ai didi

kotlin-coroutines - Kotest 与 kotlinx-coroutines-test 集成

转载 作者:行者123 更新时间:2023-12-05 09:30:43 27 4
gpt4 key购买 nike

我在 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com