获取“由于缺少执行数据文件而跳过 JaCoCo 执行";在执行 JaCoCo 时 [英] Getting "Skipping JaCoCo execution due to missing execution data file" upon executing JaCoCo

查看:37
本文介绍了获取“由于缺少执行数据文件而跳过 JaCoCo 执行";在执行 JaCoCo 时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Maven 3.0.3、JUnit 4.8.1 和 Jacoco 0.6.3.201306030806,我正在尝试创建测试覆盖率报告.

I'm using Maven 3.0.3, JUnit 4.8.1, and Jacoco 0.6.3.201306030806, and I am trying to create test coverage reports.

我有一个只有单元测试的项目,但我无法运行报告,我反复收到错误:Skipping JaCoCo execution due to missing execution data file 当我运行时:

I have a project with unit tests only, but I can't get reports to run, I'm repeatedly getting the error: Skipping JaCoCo execution due to missing execution data file when I run:

mvn clean install -P test-coverage

这是我的 pom 的配置方式:

Here is how my pom is configured:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>2.14.1</version>
  <configuration>
    <reuseForks>true</reuseForks>
    <argLine>-Xmx2048m</argLine>
  </configuration>
</plugin>
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-failsafe-plugin</artifactId>
  <version>2.14.1</version>
  <configuration>
    <reuseForks>true</reuseForks>
    <argLine>-Xmx4096m -XX:MaxPermSize=512M ${itCoverageAgent}</argLine>
  </configuration>
  <executions>
    <execution>
      <goals>
        <goal>integration-test</goal>
        <goal>verify</goal>
      </goals>
    </execution>
  </executions>
</plugin>
...
<profile>
  <id>test-coverage</id>
  <build>
    <plugins>
      <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <version>0.6.3.201306030806</version>
        <configuration>
          <destfile>${basedir}/target/coverage-reports/jacoco-unit.exec</destfile>
          <datafile>${basedir}/target/coverage-reports/jacoco-unit.exec</datafile>
        </configuration>
        <executions>
          <execution>
            <id>prepare-unit-tests</id>
            <goals>
              <goal>prepare-agent</goal>
            </goals>
          </execution>
          <!-- prepare agent for measuring integration tests -->
          <execution>
            <id>prepare-integration-tests</id>
            <goals>
              <goal>prepare-agent</goal>
            </goals>
            <phase>pre-integration-test</phase>
            <configuration>
              <propertyName>itCoverageAgent</propertyName>
            </configuration>
          </execution>
          <execution>
            <id>jacoco-site</id>
            <phase>verify</phase>
            <goals>
              <goal>report</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</profile>

我所有的测试都成功运行.以下是 Maven 的一些输出:

All my tests run successfully. Here is some of the output from Maven:

[INFO] --- jacoco-maven-plugin:0.6.2.201302030002:prepare-agent (prepare-unit-tests) @ myproject ---
[INFO] argLine set to -javaagent:/Users/davea/.m2/repository/org/jacoco/org.jacoco.agent/0.6.2.201302030002/org.jacoco.agent-0.6.2.201302030002-runtime.jar=destfile=/Users/davea/Dropbox/workspace/myproject/target/jacoco.exec
[INFO] 
    ...
Tests run: 14, Failures: 0, Errors: 0, Skipped: 0

[INFO]
    ...
[INFO] 
[INFO] --- jacoco-maven-plugin:0.6.2.201302030002:prepare-agent (prepare-integration-tests) @ myproject ---
[INFO] itCoverageAgent set to -javaagent:/Users/davea/.m2/repository/org/jacoco/org.jacoco.agent/0.6.2.201302030002/org.jacoco.agent-0.6.2.201302030002-runtime.jar=destfile=/Users/davea/Dropbox/workspace/myproject/target/jacoco.exec 
[INFO] 
[INFO] --- maven-failsafe-plugin:2.14.1:integration-test (default) @ myproject ---
[WARNING] File encoding has not been set, using platform encoding MacRoman, i.e. build is platform dependent!
[INFO] 
[INFO] --- maven-failsafe-plugin:2.14.1:verify (default) @ myproject ---
[INFO] Failsafe report directory: /Users/davea/Dropbox/workspace/myproject/target/failsafe-reports
[WARNING] File encoding has not been set, using platform encoding MacRoman, i.e. build is platform dependent!
[INFO] 
[INFO] --- jacoco-maven-plugin:0.6.2.201302030002:report (jacoco-site) @ myproject ---
[INFO] Skipping JaCoCo execution due to missing execution data file
[INFO] 

知道我缺少什么配置吗?

Any ideas what configuration I'm missing?

推荐答案

jacoco-maven-plugin:0.7.10-SNAPSHOT

来自 jacoco:prepare-agent 说:

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

注意添加到 -your -extra -arguments 中的 @{argLine}.

Note the @{argLine} that's added to -your -extra -arguments.

感谢 Slava Semushin 注意到变化和 在评论中报告.

Thanks Slava Semushin for noticing the change and reporting in the comment.

按照 jacoco:prepare-agent 说:

[org.jacoco:jacoco-maven-plugin:0.7.2-SNAPSHOT:prepare-agent] 准备一个指向 JaCoCo 运行时代理的属性,它可以被作为 VM 参数传递给被测应用程序.根据项目打包类型默认具有以下属性名称已设置:

[org.jacoco:jacoco-maven-plugin:0.7.2-SNAPSHOT:prepare-agent] Prepares a property pointing to the JaCoCo runtime agent that can be passed as a VM argument to the application under test. Depending on the project packaging type by default a property with the following name is set:

  • tycho.testArgLine 用于打包类型 eclipse-test-plugin 和
  • argLine 否则.

注意这些属性不能被覆盖测试配置,否则无法附加JaCoCo代理.如果您需要自定义参数,请附加它们.例如:

Note that these properties must not be overwritten by the test configuration, otherwise the JaCoCo agent cannot be attached. If you need custom parameters please append them. For example:

<argLine>${argLine} -your -extra -arguments</argLine>

结果覆盖信息是在执行期间收集的,默认情况下进程终止时写入文件.

Resulting coverage information is collected during execution and by default written to a file when the process terminates.

您应该在 maven-surefire-plugin 插件配置中更改以下行(注意 中的 ${argLine}>):

you should change the following line in maven-surefire-plugin plugin configuration from (note the ${argLine} inside <argLine>):

<argLine>-Xmx2048m</argLine>

<argLine>${argLine} -Xmx2048m</argLine>

也对其他插件maven-failsafe-plugin 进行必要的更改并替换以下内容(再次注意${argLine}):

Make also the necessary changes to the other plugin maven-failsafe-plugin and replace the following (again, notice the ${argLine}):

<argLine>-Xmx4096m -XX:MaxPermSize=512M ${itCoverageAgent}</argLine>

<argLine>${argLine} -Xmx4096m -XX:MaxPermSize=512M ${itCoverageAgent}</argLine>

这篇关于获取“由于缺少执行数据文件而跳过 JaCoCo 执行";在执行 JaCoCo 时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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