Jacoco doesn't produce coverage reports

守給你的承諾、 提交于 2020-05-16 05:04:10

问题


I 'm using maven-sure fire plugin to execute tests and Jacoco plugin to generate the coverage reports. Jacoco does't provide coverage reports and instead fails with the debug log as shown here under.

[INFO] --- jacoco-maven-plugin:0.8.0:report (jacoco-site) @ util --- [INFO] Skipping JaCoCo execution due to missing execution data file.

Here is how the maven sure-fire plugin looks.

             <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <version>2.5.2</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.10</version>
                <configuration>
                    <parallel>classes</parallel>
                     <threadCount>8</threadCount>
                     <forkCount>4</forkCount>
                     <encoding>UTF-8</encoding>
                    <inputEncoding>UTF-8</inputEncoding>
                    <outputEncoding>UTF-8</outputEncoding>
                    <argLine>-Xms256m -Xmx512m -XX:MaxPermSize=128m -ea
                        -Dfile.encoding=UTF-8</argLine>
                     </configuration>
            </plugin>

Here is how the Jacoco plugin looks like.

<plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.0</version>
                <configuration>
                    <destFile>${basedir}/target/coverage-reports/jacoco-unit.exec</destFile>
                    <dataFile>${basedir}/target/coverage-reports/jacoco-unit.exec</dataFile>
                </configuration>
                <executions>
                    <execution>
                        <id>jacoco-initialize</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>jacoco-site</id>
                        <phase>package</phase>
                        <goals>
                        <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

回答1:


Quoting http://www.jacoco.org/jacoco/trunk/doc/prepare-agent-mojo.html :

If your project already defines VM arguments for test execution, be sure that they will include property defined by JaCoCo.

One of the ways to do this in case of maven-surefire-plugin - is to use syntax for late property evaluation:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <argLine>@{argLine} -your -extra -arguments</argLine>
  </configuration>
</plugin>

Another way is to define "argLine" as a Maven property rather than as part of the configuration of maven-surefire-plugin:

<properties>
  <argLine>-your -extra -arguments</argLine>
</properties>
...
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <!-- no argLine here -->
  </configuration>
</plugin>

so either define

<argLine>-Xms256m -Xmx512m -XX:MaxPermSize=128m -ea
                    -Dfile.encoding=UTF-8</argLine>

as property:

<build>
  <properties>
    <argLine>-Xms256m -Xmx512m -XX:MaxPermSize=128m -ea
                    -Dfile.encoding=UTF-8</argLine>
  </properties>
...
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.10</version>
    <configuration>
      <!-- no argLine here -->

or add @{argLine} to it:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>2.10</version>
  <configuration>
    <argLine>@{argLine} -Xms256m -Xmx512m -XX:MaxPermSize=128m -ea
                    -Dfile.encoding=UTF-8</argLine>


来源:https://stackoverflow.com/questions/49581414/jacoco-doesnt-produce-coverage-reports

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!