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

查看:526
本文介绍了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 %。但是,如果我删除内联关键字,现在会显示测试覆盖率。

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天全站免登陆