17

Kotlin functions marked with inline keyword are, well, inlined during the compilation and it seems that code coverage tools (like JaCoCo) fail to properly calculate code coverage. What is the usual approach to overcoming this issue? Is there a way to make the test somehow avoid the inlining step and invoke the tested methods directly? Is it possible to skip report generation of all inlined methods (via Gradle task, for example) without excluding whole classes?

Czyzby
  • 2,999
  • 1
  • 22
  • 40
  • For anyone interested, there is a long running open issue for this on GitHub https://github.com/jacoco/jacoco/issues/654 – Jake Aug 09 '23 at 13:43

3 Answers3

5

I don't believe it is possible to turn off inlining since some functions may not make any sense if they are not inlined. These include functions with reified types (since the inlining creates the availability of type information) and functions with lambdas as parameters, since they can affect the control flow of the method they are inlined in.

Kiskae
  • 24,655
  • 2
  • 77
  • 74
5

Kotlin team has introduced the Kover plugin with the goal of supporting all language constructs including inline functions.

Czyzby
  • 2,999
  • 1
  • 22
  • 40
  • Unfortunately, even two years later, this project is still in alpha stage. I might be tempted to use it regardless, but unfortunately for me, it has no Maven support. – Jake Aug 09 '23 at 13:44
2

There is the bug in the JetBrains Java Coverage tools, see https://youtrack.jetbrains.com/issue/KT-12605 .

So, just wait until bug will be fixed (or vote on it, to speedup development)

Manushin Igor
  • 3,398
  • 1
  • 26
  • 40
  • 2
    It was marked as duplicated of [this other bug](https://youtrack.jetbrains.com/issue/IDEA-185485) and it is already fixed. – Diego Malone Jan 16 '20 at 14:37