Jacoco不提供承保范围报告 [英] Jacoco doesn't produce coverage reports

查看:146
本文介绍了Jacoco不提供承保范围报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用maven-sure fire插件执行测试,并使用Jacoco插件生成覆盖率报告. Jacoco不提供覆盖率报告,而是显示如下所示的调试日志失败.

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:rep​​ort(jacoco-site)@ util --- [INFO]由于缺少执行数据文件,跳过了JaCoCo执行.

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

这是maven sure-fire插件的外观.

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>

这是Jacoco插件的外观.

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>

推荐答案

引用

如果您的项目已经定义了用于执行测试的VM参数,请确保它们将包含JaCoCo定义的属性.

在使用maven-surefire-plugin的情况下,执行此操作的方法之一是使用语法进行后期属性评估:

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>

另一种方法是将"argLine"定义为Maven属性,而不是将其定义为maven-surefire-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>

所以要么定义

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

作为属性:

<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 -->

或在其中添加@{argLine}

<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>

这篇关于Jacoco不提供承保范围报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆