Kotlin 内联关键字导致 IntelliJ IDEA 覆盖率报告 0% [英] Kotlin inline keyword causing IntelliJ IDEA Coverage reporting 0%

查看:35
本文介绍了Kotlin 内联关键字导致 IntelliJ IDEA 覆盖率报告 0%的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个非常简单的测试函数,如下所示

I created a very simple test function as below

class SimpleClassTest {

    lateinit var simpleObject: SimpleClass
    @Mock lateinit var injectedObject: InjectedClass


    @Before
    fun setUp() {
        MockitoAnnotations.initMocks(this)
    }

    @Test
    fun testSimpleFunction() {
        simpleObject = lookupInstance()
    }

    inline fun lookupInstance() = SimpleClass(injectedObject)
}

我用 Coverage 运行它...测试覆盖率为 0%.但是如果我删除 inline 关键字,现在会显示测试覆盖率.

I Run it with Coverage... The test coverage number is 0%. But if I remove the inline keyword, the test coverage number shows now.

这是 Kotlin 问题还是 Android IntelliJ IDEA 覆盖问题?(注意:JaCoco 的覆盖面很好).

Is this a Kotlin issue or Android IntelliJ IDEA Coverage issue? (note: JaCoco coverage is good).

注意:我使用的是 Android Studio 2.0 和 Kotlin 1.0.2

Note: I'm using Android Studio 2.0 and Kotlin 1.0.2

推荐答案

编译内联函数时,编译器本质上是将其主体粘贴到调用位置(代替函数调用).这意味着覆盖率分析无法判断它是一个内联函数,因为它实际上并不存在于您定义它的地方.换句话说,这种行为是内联函数意味着什么的自然产物.

When an inlined function is compiled, the compiler essentially pastes its body into the call site (in place of the function call). This means that the coverage analysis can't tell that it's an inlined function because it doesn't really exist where you defined it. In other words, this behavior is a natural artifact of what it means for a function to be inlined.

这篇关于Kotlin 内联关键字导致 IntelliJ IDEA 覆盖率报告 0%的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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