Get coverage report for the TEST code

38 views
Skip to first unread message

Xiang Liao

unread,
Aug 11, 2022, 2:15:48 AM8/11/22
to JaCoCo and EclEmma Users
Hi,
Jacoco seems only to have a coverage report for the main classes. What if I want to get the coverage report for the tests?
For example, if I have a Test Class 
public class ExampleTest { 
  @Test 
  public void test1() { 
      new Example().doSomething(1); 
   }
and a Main Class
public Class Example{
 public void doSomething(int p){
   ...
}
}
Of course, the report will contain the coverage in Example.java, but it doesn't show the coverage in ExampleTest.java even though I ran this test. Can I get it through Jacoco?

Marc Hoffmann

unread,
Aug 11, 2022, 11:01:03 AM8/11/22
to JaCoCo and EclEmma Users
Hi,

JaCoCo as such is framework agnostic and calculates coverage for all Java classes executed in a VM.

Specific integrations only consider certain parts of your code (e.g. Maven only src/main/java).

How do you create your coverage report?

Regards,
-marc


--
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/554f128f-3264-4c3c-967c-6d27786f49a1n%40googlegroups.com.

Xiang Liao

unread,
Aug 11, 2022, 11:08:01 AM8/11/22
to JaCoCo and EclEmma Users
Hi, 

Thank you for your answer.

I'm using JaCoCo in a Maven project. I have all my test files in src/test/java. 

When I'm using surefire to run a command like `mvn -Dtest=testClass#testMethod", I will get the JaCoCo report in target/site/jacoco.

So, since you say that in maven, the JaCoCo only considers code in src/main/java, is it possible to modify the code or do the other things to make it possible to evaluate the code in src/test/java?

Marc Hoffmann

unread,
Aug 11, 2022, 11:15:40 AM8/11/22
to jac...@googlegroups.com
Hi,

our maven goal uses the standard Maven project setup. I don’t think this can be easily changed (unless you move your test code to src/main/java).

What you can do is to use the Ant report task (with the maven-antrun-plugin) which can be configured to your needs.

Cheers,
-marc


Reply all
Reply to author
Forward
0 new messages