Relations between cobertura and surefire

Problem in 1 sentence: "Cobertura does not provide correct code coverage"

Below is my pom.xml file

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
         xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <groupId>a.b.c</groupId>
    <artifactId>MyProject</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>war</packaging>
    <repositories>
        <repository>
            <id>google-api-services</id>
            <url>http://google-api-client-libraries.appspot.com/mavenrepo</url>
        </repository>
    </repositories>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java-version>1.6</java-version>
        <maven.test.skip.exec>false</maven.test.skip.exec>
        <cobertura-maven-plugin.version>2.5.2</cobertura-maven-plugin.version>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>com.google.appengine</groupId>
                <artifactId>appengine-maven-plugin</artifactId>
                <version>1.7.4</version>
            </plugin>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.1.1</version>
                <extensions>false</extensions>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.0</version>
                <configuration>
                    <source>${java-version}</source>
                    <target>${java-version}</target>
                    <encoding>${project.build.sourceEncoding}</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.1.3</version>
                <configuration>
                    <testFailureIgnore>false</testFailureIgnore>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
                <version>${cobertura-maven-plugin.version}</version>
                <configuration>
                    <formats>
                        <format>xml</format>
                        <format>html</format>
                    </formats>
                    <check/>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>cobertura</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <reporting>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
                <version>${cobertura-maven-plugin.version}</version>
            </plugin>
        </plugins>
    </reporting>
    <dependencies>
       ...
    </dependencies>
</project>

When I try to build with this pump, 2 things happen

  • All tests run 2 times
  • war started
  • Cobertura report shows 0% coverage

Please help me debug this problem.

+5
source share
2 answers

The first things I notice is that you are using the extremely old version of maven-surefire-plugin (2.1.3, which refers to 2006)!), But the current version is 2.13.

In addition, you linked the cobertura-maven-plugin to the package phase with a message to the cobertura target, which is simply incorrect.

, cobertura-maven-plugin :

  <properties>
    <cobertura-maven-plugin.version>2.5.2</cobertura-maven-plugin.version>
  </properties>

:

<project>
  ..
  <reporting>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>cobertura-maven-plugin</artifactId>
        <version>${cobertura-maven-plugin.version}</version>
      </plugin>
      ...
    </plugins>
  </reporting>
</project>

, . , (pom, tests ..).

+2

-, mvn clean install cobertura: cobertura, , . -, ( Cobertura Jenkins).

-, , , , . , cobertura -. ( ) , .

, , , , cobertura: cobertura

+1

All Articles