Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I configure when cobertura tests run in maven-cobertura-plugin?

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?

like image 511
CPhelps Avatar asked Dec 09 '11 17:12

CPhelps


People also ask

How do I use cobertura maven plugin?

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.

How does cobertura check code coverage?

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.

How does cobertura integrate with Eclipse?

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.


1 Answers

You will note from the docs that cobertura:cobertura

  • Must be wired as a report
  • Instruments, tests and generates a report
  • Runs in its own lifecycle cobertura (not the default lifecycle)
  • Invokes lifecycle phase test before running itself

So, wiring it accordingly should automatically result in instrumentation and testing.

like image 86
Sri Sankaran Avatar answered Nov 07 '22 05:11

Sri Sankaran