Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kotlin inline keyword causing IntelliJ IDEA Coverage reporting 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)
}

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

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

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

like image 926
Elye Avatar asked May 24 '16 06:05

Elye


1 Answers

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.

like image 102
Mark Avatar answered Nov 05 '22 02:11

Mark