Search code examples
javacode-coveragecoberturamaven-cobertura-plugin

Cobertura-report generation with maven plugin


I did instrumentation of code and war file successfully deployed into the tomcat container.

I am running my client tests on it.After successful run of the tests on it when I am shutting down my tomcat instance there is Cobertura.ser file in the bin directory of tomcat.

Cobertura.ser file contains all the details of code-coverage file.

Now,I wants to configure a maven task to generate Cobertura html report from .ser file.

I read the help guide of Cobertura-maven-plugin but I couldn't get properly.

(I am not running junit tests but I am performing selenium tests).

<plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>cobertura-maven-plugin</artifactId>
                        <version>2.5.2</version>
                        <executions>
                            <execution>
                                <id>instrument-code</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>instrument</goal>
                                </goals>
                                <configuration>
                                    <attach>true</attach>
                                </configuration>
                            </execution>
                            <execution>
                                <id>generate-report</id>
                                <phase>prepare-package</phase>                                
                                <goals>
                                    <goal>cobertura</goal>
                                </goals>
                                <configuration>
                                    <dataFile>C:\Servers\apache-tomcat-8.0.11\bin\cobertura.ser</dataFile>
                                    <formats>
                                        <format>html</format>
                                        <format>xml</format>
                                    </formats>
                                    <outputDirectory>C:\Users\satyam\report</outputDirectory> 
                                </configuration>
                            </execution>
                        </executions>                        
                    </plugin>

This is my maven configuration of Cobertura-plugin but this way maven is not generating report from Cobertura.ser file located in tomcat bin directory.


Solution

  • <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>cobertura-maven-plugin</artifactId>
    <configuration>
     <formats>
       <format>html</format>
       <!-- format>xml</format -->
     </formats>
     </configuration>
     </plugin>