-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Description
Steps to reproduce
Test this class:
open class TestClass {
open fun testFun(arg1: String, arg2: String = "abc"): String {
return arg2
}
}with this junit test code:
class TestClassTest {
@Test
fun testFun() {
val testClass = TestClass()
assertEquals("abc", testClass.testFun("123"))
assertEquals("def", testClass.testFun("123", "def"))
assertEquals("abc", testClass.testFun("123", "abc"))
}
}and examine the coverage of TestClass
Environment
JaCoCo version: 0.8.4
Operating system: Macos
Tool integration: Gradle
Expected behaviour
TestClass should show complete coverage
Actual behaviour
The synthetic function testFun$default(TestClass, String, String, int, Object) which implements default arguments is shown as missing coverage of one branch and 5 instructions. See image below.
The issue occurs only with open functions. It appears Kotlin inserts additional code which is presumably invoked only when the function is overridden. The particular use-case which led to this is in a Spring Boot environment where annotations such as @Transactional automatically make classes open, rather than the Kotlin default of final.
Metadata
Metadata
Assignees
Type
Projects
Status
Done
Status
Done
