Jacoco is a free code coverage library for Java. It provides coverage(Counters) for –
- Instructions
- Branches
- Cyclomatic Complexity
- Lines
- Methods
POM Configuration –
[sourcecode language=”xml”]
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.4.201502262128</version>
<configuration>
<excludes>
<exclude>**/Util*</exclude>
</excludes>
</configuration>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
[/sourcecode]
This can then be called by Jenkins using –
mvn clean test sonar:sonar
The above configuration excludes files ending in Util. Theres great debate over whether excluding fields is valid, but I think it is. Ideally I’d be able to exclude code that I consider ‘noise’, and there are plans to add support for this. I particularly like the idea of FilteringOptions, and like idea of excluding the following –
- Private, empty default constructors – assuming no calls to it
- Plain getters and setters
Like this:
Like Loading...