tynn
tynn

Reputation: 39853

Directly call an inline fun within Kotlin - Instead of inlining it

Consider following simple method:

inline fun foo(crossinline bar: () -> Unit) = foo(2) { bar() }

Now I'm trying to test this implementation:

@Test
fun `test foo`() {
    val action = mock<() -> Unit>()
    foo(action)
    verify(action)()
}

Since this test is written in Kotlin as well, the compiler inlines foo and with test coverage enabled the foo() Java method appears as not covered.

Now I'm wondering, how to configure the environment or the test to not inline functions in such cases?

Upvotes: 1

Views: 384

Answers (1)

yole
yole

Reputation: 97178

You can't do that. Inline functions are always inlined; many of their features depend on that, and you can't simply decide not to inline them.

The correct fix for this issue is to implement support for Kotlin inline functions in the coverage framework that you're using, so that it would realize that the function was indeed invoked. The .class files generated by the Kotlin compiler contain enough information for this.

The corresponding issue for jacoco is here.

Upvotes: 4

Related Questions