I am having trouble getting the Cobertura plugin to run integration tests in Maven. The closest answer to this question I have found is http://jira.codehaus.org/browse/MCOBERTURA-86. However, the issue remains an open bug. I tried the configuration suggested by Stevo on 03/Apr/09, it didn't work.
My POM
<reporting> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> <version>2.3-SNAPSHOT</version> <reportSets> <reportSet> <reports> <report>cobertura-integration</report> </reports> </reportSet> </reportSets> </plugin> </plugins> </reporting>
which is by the way exactly the same as the configuration fragment provided by Stevo.
The simplest way to run integration tests is to use the Maven failsafe plugin. By default, the Maven surefire plugin executes unit tests during the test phase, while the failsafe plugin runs integration tests in the integration-test phase.
Simply put, Cobertura is a reporting tool that calculates test coverage for a codebase – the percentage of branches/lines accessed by unit tests in a Java project.
From my opinion, the cobertura maven plugin has two big disadvantages. It has no report only goal, all unit tests will run beside surefire again. It creates the code coverage for unit tests only .
I am using the JaCoCo maven plugin now. JaCoCo reuses the surefire and/or failsafe reports to create a code coverage from unit and/or integration test. Furthermore JaCoCo has a good Jenkins integration. Here is an example where JaCoCo uses surefire unit tests and failsafe integration tests.
<build> <plugins> <!-- Unit tests --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.16</version> </plugin> <!-- Integration tests --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-failsafe-plugin</artifactId> <version>2.16</version> <executions> <execution> <phase>integration-test</phase> <goals> <goal>integration-test</goal> <goal>verify</goal> </goals> </execution> </executions> </plugin> <!-- The JaCoCo plugin generates a report about the test coverage. In contrast to the cobertura plugin JaCoCo can be configured to generate code coverage for integration tests. Another advantage of JaCoCo is that it reports only, cobertura executes all unit tests again (beside the surefire plugin). --> <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.6.4.201312101107</version> <executions> <execution> <id>jacoco-prepare-agent</id> <goals> <goal>prepare-agent</goal> </goals> </execution> <execution> <id>jacoco-prepare-agent-integration</id> <goals> <goal>prepare-agent-integration</goal> </goals> </execution> <execution> <id>jacoco-report</id> <goals> <goal>report</goal> </goals> </execution> <execution> <id>jacoco-integration</id> <goals> <goal>report-integration</goal> </goals> </execution> <execution> <id>jacoco-check</id> <goals> <goal>check</goal> </goals> <configuration> <rules /> </configuration> </execution> </executions> </plugin> </plugins> </build>
Try to configure a execution phase for that plugin like
<build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> <version>2.5.1</version> <configuration> <formats> <format>xml</format> </formats> </configuration> <executions> <execution> <id>cobertura-check</id> <phase>verify</phase> <goals> <goal>cobertura</goal> </goals> </execution> </executions> </plugin>
That way it works like a charm for me.
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