In order to fine-tune which tests are run at which times and in which environments, we have several executions set up for the maven-surefire-plugin. We set the default configuration to skip all tests, then enable them for the executions we want. This by itself works well for us.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
<executions>
<execution>
<id>unit-tests</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
<includes>
<include>**/*Tests.java</include>
</includes>
<excludes>
<exclude>**/*IntegrationTests.java</exclude>
</excludes>
</configuration>
<execution>
<execution>
<id>integration-tests</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
<includes>
<include>**/*IntegrationTests.java</include>
</includes>
</configuration>
<execution>
</executions>
</plugin>
When I add the maven-cobertura-plugin to the mix, I run into problems. The cobertura goal runs, and successfully instruments my classes. However, no tests get run. I assume this is because the test execution that cobertura is running in is one that is skipped. However, I cannot find how to specify which phase and goal to set up for this execution. When I turn on all tests, the output seems to indicate that these are still running in these unit-tests and integration-tests phases/goals.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.4</version>
<configuration>
<formats>
<format>xml</format>
<format>html</format>
</formats>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>cobertura</goal>
</goals>
</execution>
</executions>
</plugin>
How do I need to specify a surefire execution so that the cobertura will run it against the instrumented classes?
Cobertura Code Coverage Report Do nothing, just type the following Maven command to download and run the maven-cobertura-plugin automatically. Maven will generate the Cobertura code coverage report at ${project}/target/site/cobertura/index. html . Please refer to this Cobertura Maven Plugin for more examples.
Cobertura is a free Java tool that calculates the percentage of code accessed by tests. It can be used to identify which parts of your Java program are lacking test coverage. It is based on jcoverage.
After installing the plugin, restart the eclipse IDE. The Coverage View automatically appears. Or you can open the coverage view from Window > Show View > Other > Java > Coverage. Or you can just type "Coverage" in the Quick Access search box in the eclipse.
You will note from the docs that cobertura:cobertura
cobertura
(not the default
lifecycle)test
before running itselfSo, wiring it accordingly should automatically result in instrumentation and testing.
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