I was looking for a nice solution to measure the code coverage in my Spring Boot biking project.
It should support Java 8, Maven and for added bonus, my IDE.
I ended up using JaCoCo respectively the Maven plugin.
If you expect a lengthier post, i must disappoint you. All that was need to turn this:
into this
and also having a nice report like this (right click in NetBeans 8 on the project and choose “Code Coverage > Show Report…”)
was the following plugin declaration in maven:
<plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.7.1.201405082137</version> <configuration> <excludes> <!-- Application starter --> <exclude>ac/simons/biking2/Application.class</exclude> <!-- Configuration --> <exclude>ac/simons/biking2/config/*</exclude> </excludes> </configuration> <executions> <execution> <id>pre-unit-test</id> <goals> <goal>prepare-agent</goal> </goals> </execution> <execution> <id>post-unit-test</id> <phase>test</phase> <goals> <goal>report</goal> <goal>check</goal> </goals> <configuration> <rules> <!-- implmentation is needed only for Maven 2 --> <rule implementation="org.jacoco.maven.RuleConfiguration"> <element>BUNDLE</element> <limits> <limit implementation="org.jacoco.report.check.Limit"> <counter>INSTRUCTION</counter> <value>COVEREDRATIO</value> <minimum>0.95</minimum> </limit> <!-- implmentation is needed only for Maven 2 --> <limit implementation="org.jacoco.report.check.Limit"> <counter>COMPLEXITY</counter> <value>COVEREDRATIO</value> <minimum>0.75</minimum> </limit> </limits> </rule> </rules> </configuration> </execution> </executions> </plugin> |
That’s it. NetBeans 8 recognizes JaCoCo immediately and everything works (except for my project not reaching my self set limits). No additional installs, no weird maven problems. Awesome.
Also i had no problems with JaCoCo and Java 8 features of any kind.
3 comments
Thanks for the post. Did exactly what I needed real quick.
Brilliant. Got it working in 2 minutes. Thank you!
You’re welcome!
Post a Comment