Given the importance given to the Unit and Integration tests , it is important to evaluate the amount of code that our test cases
cover. The contenders for tool of choice were Emma, Cobertura and JACOCO (sure
has a strange name than others,it is actually JAva COde COverage). JACOCO won for the following reasons
Highlighted in GREEN is covered code.
This report should help us to really write quality tests and in turn deliver a quality product.Now lets see how to set this up.
JACOCO Setup.
You will be so surprised that it is so simple with maven. add the following to your pom and thats it, yes really thats it. Your unit and integration tests coverage reports are ready.
Add the following dependency
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.5.3.201107060350</version>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>install</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
Suggestions and user experience are welcome
- While Emma and Cobertura have been around for long time they are not much efficient in collecting run time coverage data from a test running inside the container. JACOCO is made for it.
- They also do cool stuffs like on the fly Instrumentation of classes
- They work hand in hand with Arquillian etc etc
- You can read further @ http://www.eclemma.org/jacoco/
Project Level |
Package level |
Class level |
Method Level |
This report should help us to really write quality tests and in turn deliver a quality product.Now lets see how to set this up.
JACOCO Setup.
You will be so surprised that it is so simple with maven. add the following to your pom and thats it, yes really thats it. Your unit and integration tests coverage reports are ready.
Add the following dependency
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.core</artifactId>
<version>0.5.3.201107060350</version>
<scope>test</scope>
</dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.core</artifactId>
<version>0.5.3.201107060350</version>
<scope>test</scope>
</dependency>
and this
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.5.3.201107060350</version>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>install</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
Suggestions and user experience are welcome
Yes I agree with your statement on Cobertura & Emma...faced lot of issues in our previous projects...Let me take a look on JaCoCO and see how it fits, especially for projects with multiple modules
ReplyDelete