How can I get jacoco coverage on methods called by reflection?

22 views
Skip to first unread message

Nicolas Baumann

unread,
May 11, 2024, 5:03:18 AMMay 11
to jac...@googlegroups.com
Hello 

I'm using jacoco version 0.8.12.

I'm using a vendor library which calls the code that I want to test.

The vendor library instantiates the class from a package I have registered in the application as a client package by performing a Class.forName(myClientPackage + "path.to.Handler") and calling the method handle(...) from my implementation of vendor interface Handler.

I'd like to know how to gain coverage from such methods called by reflection.

It works well inside Eclipse. The code called by reflection is highlighted in green.

I might be missing a special option from jacoco that is disabled by default.

I use gradle to generate the jacoco report:

```lang-groovy
apply plugin: 'jacoco'

jacoco {
  toolVersion = '0.8.12'
}

task javaCodeCoverageReport(type: JacocoReport, dependsOn: test) {
  sourceDirectories = files(['src/main/java'])
  classDirectories = files(['build/classes/main'])
  executionData = files('build/jacoco/test.exec')
  reports {
    xml.enabled = true
    html.enabled = true
  }
}
```

Question originally posted on stackoverflow:

Regards,
Nicolas.
Reply all
Reply to author
Forward
0 new messages