Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running integration tests with Cobertura Maven plugin

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.

like image 856
Candy Chiu Avatar asked Feb 02 '10 22:02

Candy Chiu


People also ask

How do I get my Maven integration tests to run?

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.

What does cobertura Maven plugin do?

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.


2 Answers

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> 
like image 163
user3119291 Avatar answered Sep 19 '22 11:09

user3119291


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.

like image 37
flob Avatar answered Sep 22 '22 11:09

flob