sách gpt4 ai đã đi

kotlin-coroutines - Tích hợp Kotest với kotlinx-coroutines-test

In lại 作者:行者123 更新时间:2023-12-05 09:30:43 28 4
mua khóa gpt4 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 Còn hơn là kotlinx.coroutines.CoroutineScope 的实例?或者为什么这没有意义?

1 Câu trả lời

从 Kotest 5.0 开始,内置了对 TestCoroutineDispatcher 的支持。参见 đây

简单地:

class MyTest : FunSpec(
{
test("do your thing").config(testCoroutineDispatcher = true) {
}
}
)

关于kotlin-coroutines - Kotest 与 kotlinx-coroutines-test 集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69417255/

28 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com