I'm writing some unit tests for my Android app written in Kotlin, and I'm getting errors from the included inlined collection functions, in this case specifically sortedBy

 override fun onDaysSelected(dayOfWeekList: ArrayList<DayOfWeek>) {
        view.userRoutingRule.days = dayOfWeekList.sortedBy { it.dayOfWeek }
        renderRule()
 }

This is the error I'm getting when I run my unit tests with coverage

-IntelliJ Idea Coverage Runner-采样.包括图案: com.mypackage..* 排除模式:[2019.02.02 14:49:40](Coverage):不包含类数据 已提取: com.mypackage\myfile$onDaysSelected$$inlined$sortedBy$1: java.lang.Throwable

Process finished with exit code 0

我的单元测试都相应地通过了,但当我go 查看覆盖率报告时,它几乎完全是空的,因为这个错误阻止了它的完成.

Is there any solution to this at this point? It's hard to know if I missed some condition if I can't just look at the report.

推荐答案

计算使用lambdas的imline方法的覆盖率是一个已知的问题.(见No coverage report for inlined Kotlin methodshttps://discuss.kotlinlang.org/t/inline-functions-coverage/5366)

如果想在当前状态下运行覆盖率,需要使用其他方法,例如在DayOfWeek中实现Comparable接口和使用.sorted()方法.

Kotlin相关问答推荐

API迁移到Spring Boot 3后,Spring Security无法工作

Android Jetpack编写androidx.compose.oundation.lazy.grid.Items

有没有一种简单的方法来识别物体?

Kotlin 函数名后面的大括号是什么意思?

限制通用Kotlin枚举为特定类型

如何将 `when` 与 2 个密封类一起使用并获取内部值?

返回 kotlin 中的标签和 lambda 表达式

验证构造函数中的值组合

如何在 Kotlin 中使用 volatile

retrofit 响应代码 405 并带有消息method not allowed here

包括登录Elvis operator?

Kotlin 有 array.indexOf 但我无法弄清楚如何做 array.indexOfBy { lambda }

Dagger2 Qualifier 不适用于 Kotlin?

Kotlin 中的内联构造函数是什么?

封闭 lambda 的隐式参数被shadowed

Kotlin 的 Double.toInt() 中使用了哪种方法,舍入还是截断?

这是 Kotlin 中的错误还是我遗漏了什么?

如何在 Gradle Kotlin DSL 中使用来自 gradle.properties 的插件版本?

Kotlin var lazy init

Kotlin 的数据类 == C# 的 struct ?