Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maven Jacoco: how to increase code coverage thresholds automatically

I am using Jacoco with Maven builder for my project's code coverage. I have configured rules around maximum missed classes / methods and minimum line coverage failing which maven build fails (sample below).

<rules>
    <rule>
        <element>BUNDLE</element>
        <limits>
            <limit>
                <counter>CLASS</counter>
                <value>MISSEDCOUNT</value>
                <maximum>90</maximum>
            </limit>
        </limits>
    </rule>
</rules>

I am trying to figure out if there is a mechanism using which these rules get automatically updated if more test cases are added (or more methods are covered using same tests).

Let's say I added test cases for 5 more classes, the maximum value is above rule should be changed to 85.

like image 894
face Avatar asked Nov 29 '18 20:11

face


People also ask

How does JaCoCo increase code coverage?

Under projects/build/plugins , add the following XML: And under projects , add this XML: Now all you need to do is run the command mvn test jacoco:report . This runs all of the unit tests in your project and creates an HTML report of the code coverage information.

How do you fail a maven build if JUnit coverage falls below certain threshold?

How can I fail the build if it falls below a defined value? Maven fails by default if JUnit provider detects a test error. It is to fail the build based on JUnit coverage percentage for a project.It is not for the JUnit test it self.

What is difference between JaCoCo and SonarQube?

SonarQube has a broader approval, being mentioned in 163 company stacks & 271 developers stacks; compared to JaCoCo, which is listed in 5 company stacks and 11 developer stacks.


1 Answers

I think what you ask for is actually ratcheting support. This is usually achieved through Continuous Integration systems like Jenkins.

There is currently an open ticket (from 2014) to support ratcheting for Jacoco at Jenkins: https://issues.jenkins-ci.org/browse/JENKINS-22018

It seems that cobertura Jenkins plugin already supports ratcheting. So maybe you could use that if you want.

I do not know about other CI solutions and their Jacoco plugins but I hope that this may help you (hopefully you use a CI system).

like image 192
ngiallelis Avatar answered Oct 03 '22 21:10

ngiallelis