Jacoco showing 0% for already instrumented classes in Multi Module Architecture.

37 views
Skip to first unread message

Ashish Ranjan Sinha

unread,
May 28, 2024, 5:31:44 AMMay 28
to JaCoCo and EclEmma Users
Hi,

I am using Jacoco 0.8.11 for OpenJDK17. We are using Runtime instrumentation for instrumenting the .class files under the multiple packages. I am attaching the java agent to the JVM and restarting my system. Then running my Junits which is integrated test running separately on Jenkins pipeline. Once the Junits are run, jacoco.exec is flushed with executable data collected during junits. I am generating the report using the Jacoco cli command and storing the report under coverage/index.html.

However, I observe some of the classes having 0% despite the associated Junit test running against it. When compared with Cobertura coverage report, the jacoco report shows very less coverage for the same set of classes and Junits. 


Need some guidance as what I am doing wrong here.


Regards,
Ashish.

Marc Hoffmann

unread,
May 29, 2024, 1:57:15 PMMay 29
to JaCoCo and EclEmma Users
Hi Ashish,

our FAQ contains some information about this. Did you already check?

Regards,
-marc

Why does a class show as not covered although it has been executed?

First make sure execution data has been collected. For this select the Sessions link on the top right corner of the HTML report and check whether the class in question is listed. If it is listed but not linked the class at execution time is a different class file. Make sure you're using the exact same class file at runtime as for report generation. Note that some tools (e.g. EJB containers, mocking frameworks) might modify your class files at runtime. Please see the chapter about class ids for a detailed discussion.




--
You received this message because you are subscribed to the Google Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jacoco+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/c7eb0406-d655-477d-a1c0-41c5ddf8117en%40googlegroups.com.

Ashish Ranjan Sinha

unread,
Jun 1, 2024, 3:27:20 AMJun 1
to JaCoCo and EclEmma Users
Hi Marc,

I see the class is already part of the session page. However I am still getting the 0% code coverage for it.

2024-06-01_12-46-59.png

2024-06-01_12-46-35.png

The same test and class files are used for Cobertura and I could see the coverage is high for these classes. FYI - I am using openJDK17 with RHEL 8.9. I am using runtime instrumentation for the classes. 


Regards,
Ashish

Marc Hoffmann

unread,
Jun 3, 2024, 11:39:57 AMJun 3
to JaCoCo and EclEmma Users
Hi Ashish,

this looks good so far. At least a few lines are marked as covered. So execution data seems to be collected correctly.

What I would do next is to add some proof that the code in question ist actually executed during the JaCoCo test run. For example add logging of throw an exception.

Regards,
-marc

On 1. Jun 2024, at 09:27, Ashish Ranjan Sinha <ashishra...@gmail.com> wrote:

Hi Marc,

I see the class is already part of the session page. However I am still getting the 0% code coverage for it.

<2024-06-01_12-46-59.png>
To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/e3bcd9be-41a4-41e1-84f3-6bbc8b12c0c7n%40googlegroups.com.
<2024-06-01_12-46-35.png><2024-06-01_12-46-59.png>

Ashish Ranjan Sinha

unread,
Jun 3, 2024, 1:02:12 PMJun 3
to jac...@googlegroups.com
Hi Marc,

Thank you for your reply 

What I observe during weekend is if my build is having cobertura and jacoco code coverage, some of the classes are listed as picked by jacoco but the coverage is 0%. Where as if the build only have cobertura the same class which was picked by jacoco is not picked any more and the coverage is 0%. I am guessing something is wrong with cobertura or sap ssws. 


Regards,
Ashish 

Marc Hoffmann

unread,
Jun 3, 2024, 1:56:01 PMJun 3
to jac...@googlegroups.com
Hi Ashish,

JaCoCo as well as Cobertura is based on bytecode instrumentation. Having both instrumenting tools in the same build means that one tool instruments classes which have already been instrumented by the other tool. I do definitely not recommend this setup. Please run one tool or the other during a single build.

Regards,
-marc

Ashish Ranjan Sinha

unread,
Jun 5, 2024, 12:00:48 AMJun 5
to JaCoCo and EclEmma Users
Hi Marc-

Thank you for your swift reply.

Even after removing cobertura, I am observing the subclasses are not getting picked even though the super classes are picked by Jacoco. I am able to see the coverage for the super class whereas for the subclasses the coverage is still 0%.

Regards,
Ashish

Marc Hoffmann

unread,
Jun 6, 2024, 1:28:27 PMJun 6
to JaCoCo and EclEmma Users
Hi Ahish,

so what happens if you add something like this in one of the subclasses where you miss coverage:

throw new RuntimeException(“Here I am!”);

Will the exception break your tests?

Regards,
-marc


Message has been deleted

Ashish Ranjan Sinha

unread,
Jun 7, 2024, 8:55:15 AMJun 7
to JaCoCo and EclEmma Users
Hi Marc-

I thoroughly checked and found the class- Accumulator.java is not picked by the Jacoco when I am using Jacoco alone. While it was picked when there was cobertura configured along with Jacoco. 

Below Screeshot is from build where we had cobertura and Jacoco configured. 

2024-06-01_12-46-35.png


In my config, we are creating 20 VMs and each VM runs some set of Test over the packages. I researched and found a similar issue chat where u suggested the test would be executed in another VM. So I ran all the 20 VMs and generated the report from it. Still I am observing 0% for those subclass. Please note I am using openjdk17 with Junit 3.8.2

Snippet of my Accumulator.java:
2024-06-07_18-22-29.png

Regards,
Ashish
Reply all
Reply to author
Forward
0 new messages