user1728119
user1728119

Reputation: 387

Jacoco-IntegrationTests code coverage

I am not able to get over this issue- I have 3 classes A B and C.

A is a integration test class which tests classes B and C together.

B and C are classes in another package(w.r.t class A)

Now when i run integration test class A i want the code coverage to show what parts of B and C are covered.I am not getting the required output.

What i am getting as the output is that no classes are instrumented.

So no test coverage for the two classes...If i write a sample code in src/main/java in the same module as A is in..It recognizes the class and instruments it.

Why cant it do the same for classes outside its package.

Kindly help.Thanks

Upvotes: 4

Views: 2511

Answers (1)

ddewaele
ddewaele

Reputation: 22603

This can be caused by a number of problems :

1. Classes not being triggered according to the jacoco agent

The first thing you need to check if your classes B and C have been triggered by the jacoco agent. This can be done by generating a jacoco report and clicking on the sessions link (top right corner).

If your class B or C is not listed here, it means that there is a problem with your jacoco agent, and it wasn't attached to the correct JVM that triggers class B / C , or no code in class B/C was triggered.

2. Classes triggered according to the jacoco agent but no source/class files available

If your class B or C is listed here, but it's not clickable, it means that your class B / C was triggered and detected by the jacoco agent, but it wasn't able to link it.

Keep in mind that during report generation, jacoco needs to have the class files and source files available in order to generate a report. (if you're using maven, it expects the class files in the project.build.outputDirectory and the sources in project.build.sourceDirectory

3. Classes triggered according to the jacoco agent but wrong class files available

If your class B or C is deployed on an appserver, it is possible that the appserver also instruments the bytecode of those classes during deployment, creating a situation where the class files in your local project are not the same as the class files detected by the jacoco agent (See this topic for a discussion on that : https://groups.google.com/forum/?fromgroups=#!topic/jacoco/GjSlBoFTRrc). In that case, Jacoco offers a classdumpdir param that can be set to a folder where jacoco will dump the classes it has detected during your test run. You need to use these classes during your report generation.

References

Upvotes: 2

Related Questions