14

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

Elye
  • 53,639
  • 54
  • 212
  • 474

1 Answers1

3

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.

Mark
  • 1,788
  • 1
  • 22
  • 21
  • 1
    There is no reason that the coverage of others would be all counted as zero, when inline is used. JaCoco is okay, so the above doesn't explain at all. – Elye Jun 06 '17 at 12:19