We all know how important it is to control the test coverage for the project. However, the only way to ensure objective results is through the use of automated test coverage reports like Clover or Cobertura. While Clover is a commercial product that will cost you money Cobertura is open-source solution that is absolutely free.
Unfortunately, being an open-source project Cobertura seriously lacks documentation, especially regarding how to configure Maven 2 plug-in. One of the most common problems with Cobertura is when generated report shows 100% test coverage while in reality many of the classes do not have tests.
The reason for this is that Cobertura did not perform code instrumentation during the site generation phase. As the result the coverage information is incorrect.
This is the example of how you can configure this report so that it would reflect real test coverage.
<build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> <executions> <execution> <id>site</id> <phase>pre-site</phase> <goals> <goal>clean</goal> </goals> </execution> <execution> <id>instrument</id> <phase>site</phase> <goals> <goal>instrument</goal> <goal>cobertura</goal> </goals> </execution> </executions> <configuration> <instrumentation> <excludes> <exclude>com/test/ClassToIgnore.class</exclude> <exclude>com/test/**/*Test.class</exclude> <exclude>com/test2/**/*.class</exclude> </excludes> </instrumentation> </configuration> </plugin> </plugins> </build>
And then we need to add this code to reporting section of our POM file
<reporting> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> </plugin> </plugins> </reporting>
- I am an IT professional with more than 12 years of experience in various software development areas, including system analysis, design and testing. I help my clients to convert business ideas into real-life solutions that make their businesses more profitable.






