没有涵盖Kotlin方法的报道 [英] No coverage report for inlined Kotlin methods

查看:116
本文介绍了没有涵盖Kotlin方法的报道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标记为 inline 关键字的Kotlin函数在编译过程中很好地被内联,似乎代码覆盖工具(比如)未能正确计算代码覆盖率。克服这个问题的常用方法是什么?有没有办法让测试以某种方式避免内联步骤并直接调用被测试的方法?是否有可能跳过所有内联方法的报告生成(例如通过 Gradle 任务),而不排除整个类?

解决方案

我不认为有可能关闭内联,因为如果某些函数没有内联,它们可能没有任何意义。这些包括 reified 类型的函数(因为内联创建类型信息的可用性)并且函数使用lambdas作为参数,因为它们可以影响它们内联方法的控制流in。


Kotlin functions marked with inline keyword are, well, inlined during the compilation and it seems that code coverage tools (like JaCoCo) fail to properly calculate code coverage. What is the usual approach to overcoming this issue? Is there a way to make the test somehow avoid the inlining step and invoke the tested methods directly? Is it possible to skip report generation of all inlined methods (via Gradle task, for example) without excluding whole classes?

解决方案

I don't believe it is possible to turn off inlining since some functions may not make any sense if they are not inlined. These include functions with reified types (since the inlining creates the availability of type information) and functions with lambdas as parameters, since they can affect the control flow of the method they are inlined in.

这篇关于没有涵盖Kotlin方法的报道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆