kotlin-coroutines - Kotest 和 kotlinx-coroutines-test 集成
问题描述
我在 kotest 中使用了 Funspec 测试风格,我得到了一个由框架自动注入的 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
而不是 a kotlinx.coroutines.CoroutineScope
?或者有没有理由为什么这没有意义?
解决方案
从 Kotest 5.0 开始,内置了对TestCoroutineDispatcher
. 看这里
简单地:
class MyTest : FunSpec(
{
test("do your thing").config(testCoroutineDispatcher = true) {
}
}
)
推荐阅读
- php - 将徽标上的 php 链接更改为外部站点
- mysql - 从 wordpress 帖子中选择自定义帖子字段 (ACF)
- java - 作为 maven 构建的一部分,如何从 pom.xml 中的依赖项中读取所有资源文件
- javascript - 在没有外部服务器的情况下显示来自“睡眠”PWA/ServiceWorker 的通知 (PushAPI)
- r - 如何分隔行内的多个字符值?
- reactjs - bootstrap-switch-button-react :更改语言时如何将 onLabel 和 offLabel 值更新为不同的语言
- flutter - 在 Flutter 中放置一个使用剩余空间但不是 slivers 列表中的最后一个小部件的可滚动列表
- sql - 将数据组织成多列 SQL
- ios - 在嵌入式控制器中使用 UICollectionView 在 UIPageViewController 中跳转布局
- redirect - 在 WooCommerce 应用程序中重定向产品 URL