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.
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 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.
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.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With