Unable to check to code coverage threshold value per module

48 views
Skip to first unread message

rre...@tibco.com

unread,
Mar 14, 2019, 11:55:18 AM3/14/19
to JaCoCo and EclEmma Users
Hi Team ,

I'm doing the code coverage with jacoco plugin . I have multiple projects and I'm able to generate single jacoco.exe but issue is I'm unable to set the threshold value separately for each module . I wanted to set the threshold value for each module.

Here is my jacoco configuration.
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-prepare-agent-integration</id>
<goals>
<goal>prepare-agent-integration</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>default-report-integration</id>
<goals>
<goal>report-integration</goal>
</goals>
</execution>
<execution>
<id>default-check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<haltOnFailure>true</haltOnFailure>
<!-- the build will fail if any rule check fails -->
<!--
* Check configuration used to specify rules on element types (BUNDLE,
* PACKAGE, CLASS, SOURCEFILE or METHOD) with a list of limits. Each limit
* applies to a certain counter (INSTRUCTION, LINE, BRANCH, COMPLEXITY,
* METHOD, CLASS) and defines a minimum or maximum for the corresponding
* value (TOTALCOUNT, COVEREDCOUNT, MISSEDCOUNT, COVEREDRATIO, MISSEDRATIO).
* If a limit refers to a ratio the range is from 0.0 to 1.0 where the
* number of decimal places will also determine the precision in error
* messages. A limit ratio may optionally be declared as a percentage
* where 0.80 and 80% represent the same value, the value must end with %.
-->
<rules>
<rule>
<element>BUNDLE</element>
<!-- <excludes>
<exclude>*Test</exclude>
</excludes>
<limits>
<limit>
<counter>INSTRUCTION</counter>
<value>COVEREDRATIO</value>
<minimum>.95</minimum>
</limit>
<limit>
<counter>BRANCH</counter>
<value>COVEREDRATIO</value>
<minimum>.95</minimum>
</limit>
</limits> -->
</rule>
<rule>
<element>PACKAGE</element>
</rule>
<rule>
<element>CLASS</element>
</rule>
<rule>
<element>SOURCEFILE</element>
</rule>
<rule>
<element>METHOD</element>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>

I have multiple projects and I wanted to give the different value for each module.
Please help on this .

Thanks,

Evgeny Mandrikov

unread,
Mar 14, 2019, 12:07:20 PM3/14/19
to JaCoCo and EclEmma Users


On Thursday, March 14, 2019 at 4:55:18 PM UTC+1, rre...@tibco.com wrote:
Hi Team ,

I'm doing the code coverage with jacoco plugin . I have multiple projects and I'm able to generate single jacoco.exe but issue is I'm unable to set the threshold value separately for each module . I wanted to set the threshold value for each module.

I have multiple projects and I wanted to give the different value for each module. 


The "check" goal considers classes only of a single module for which it is executed.

If maven plugin is not flexible enough for your use case, please consider usage of
JaCoCo Ant Tasks ( https://www.jacoco.org/jacoco/trunk/doc/ant.html ) , e.g. via maven-antrun-plugin
or JaCoCo Command Line Interface ( https://www.jacoco.org/jacoco/trunk/doc/cli.html ).

rre...@tibco.com

unread,
Mar 14, 2019, 12:40:14 PM3/14/19
to JaCoCo and EclEmma Users
Hi ,
Thanks for the reply . I'm able to generate the report and also able to do the jacoco "check" with single value of "COVERAGE RATIO" as .95 but my requirement is I wanted to have the different "COVERAGERATIO" for different module .
Please help

Thanks

Evgeny Mandrikov

unread,
Mar 14, 2019, 2:07:30 PM3/14/19
to JaCoCo and EclEmma Users
In attachment you'll find example, where configuration for "check" is specified in two separate pom.xml files corresponding to two separate modules.
example.zip

rre...@tibco.com

unread,
Mar 15, 2019, 12:55:42 AM3/15/19
to JaCoCo and EclEmma Users


Hi Mandrikov ,
Thanks for reply .
Let me give the more information regarding my issue .
I have a separate project called "Code-Coverage" maven project and I have added all project as dependencies and able to generate report and able to do jacoco "check" for single value as "COVEREDRATIO" as "0.95" . but I want to provide COVEREDRATIO value separately for each dependencies .
below are my some dependencies.


<dependency>
<groupId>api.common</groupId>
<artifactId>api-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>api.engine</groupId>
<artifactId>api-engine</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>api.externalAuth</groupId>
<artifactId>api-externalAuth</artifactId>
<version>${project.version}</version>
</dependency>

So I want to give the COVEREDRATIO value independently for each module/Dependency .
Ex : for api-engine --I want to give COVEREDRATIO - 0.95
for api-common -- I want to give COVEREDRATIO --0.8

Thanks

rre...@tibco.com

unread,
Mar 15, 2019, 4:16:22 AM3/15/19
to JaCoCo and EclEmma Users

Hi Team ,

Just to provide more information .
Let's take an example .
I have a project A , B ,C and all three having unit test cases and also I have a project called "Integration-tests" where it will perform integration tests for all three modules/projects (A,B,C) . now I have created a project called "Code-coverage " in tha I'm able to generate aggregate report by merging all jacococ.exec's generated in individual projects. Now I want to perform Jacoco "check" with threshold values per module (let's say for A : 0.9 , B:0.8 , C:0.7) in "Code-coverage" project but not in individual project .

Thanks,

Evgeny Mandrikov

unread,
Mar 15, 2019, 4:52:28 AM3/15/19
to JaCoCo and EclEmma Users
As was already said earlier ( https://groups.google.com/d/msg/jacoco/bgZUCIIsDP8/30N28YhwCwAJ ) as of today this is not possible with jacoco-maven-plugin , because
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages