在执行JaCoCo时获取"由于缺少执行数据文件而跳过JaCoCo执行"

Dav*_*ave 92 junit maven jacoco

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

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

mvn clean install -P test-coverage
Run Code Online (Sandbox Code Playgroud)

这是我的pom配置方式:

<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>
Run Code Online (Sandbox Code Playgroud)

我的所有测试都成功运行.以下是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] 
Run Code Online (Sandbox Code Playgroud)

任何想法我缺少什么配置?

Jac*_*ski 112

jacoco - Maven的插件:0.7.10-快照

来自jacoco:准备代理人说:

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

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <argLine>@{argLine} -your -extra -arguments</argLine>
  </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

请注意@{argLine}添加的内容-your -extra -arguments.

感谢Slava Semushin注意到评论中的更改和报告.

jacoco - Maven的插件:0.7.2-SNAPSHOT

jacoco:准备代理,上面写着:

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

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

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

<argLine>${argLine} -your -extra -arguments</argLine>
Run Code Online (Sandbox Code Playgroud)

生成的覆盖信息在执行期间收集,并且在进程终止时默认写入文件.

你应该改变maven-surefire-plugin插件配置中的以下行(注意${argLine}里面<argLine>):

<argLine>-Xmx2048m</argLine>
Run Code Online (Sandbox Code Playgroud)

<argLine>${argLine} -Xmx2048m</argLine>
Run Code Online (Sandbox Code Playgroud)

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

<argLine>-Xmx4096m -XX:MaxPermSize=512M ${itCoverageAgent}</argLine>
Run Code Online (Sandbox Code Playgroud)

<argLine>${argLine} -Xmx4096m -XX:MaxPermSize=512M ${itCoverageAgent}</argLine>
Run Code Online (Sandbox Code Playgroud)

  • 这正是我的问题。我在 mvn 命令 `mvn clean package sonar:sonar -U -DargLine="-Dxxx=yyy"` 中有自定义参数。我没有明确声明 maven-surefire-plugin 并设置配置。我只是在 maven 命令行中添加 argLine 占位符,如 `mvn clean package sonar:sonar -U -DargLine="@{argLine} -Dxxx=yyy"`。现在生成 jacoco.exec 文件并在声纳中生成覆盖率报告。 (2认同)

Cha*_*Hey 17

我遇到了一个不同的问题,它返回了同样的错误.

Skipping JaCoCo execution due to missing execution data /target/jacoco.exec
Run Code Online (Sandbox Code Playgroud)

事实是,出于许多原因,这个错误被返回了.我们在Stack Overflow上尝试了不同的解决方案,但发现这个资源是最好的.它揭示了Jacoco可能返回相同错误的许多不同潜在原因.

对我们来说,解决方案是在配置中添加准备代理.

<execution>
   <id>default-prepare-agent</id>
   <goals>
       <goal>prepare-agent</goal>
   </goals>
</execution>
Run Code Online (Sandbox Code Playgroud)

我想大多数用户会因为不同的原因而遇到它,所以看看上面提到的资源吧!

  • 我想你把它钉了。人们可能会在Google上搜索“快速修复”,但最正确的答案是“事实是,由于许多很多原因而返回此错误”。只需找出那是什么。对我而言,这是父pom覆盖了maven-surefire-plugin中的&lt;argLine&gt;。 (2认同)

小智 13

可能有一种情况,pom中的其他argline设置或插件可能会覆盖jacoco执行顺序设置.

argLine设置为 - 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

其中一个例子

           <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.16</version>
                <configuration>
                    <forkCount>5</forkCount>
                    <reuseForks>true</reuseForks>
                    <argLine>-Dnet.sf.ehcache.disabled=true</argLine>
                </configuration>
            </plugin>
Run Code Online (Sandbox Code Playgroud)

从这些插件中删除argLine后,jacoco开始正常工作.


kya*_*kya 11

使用 maven-surefire-plugin 或 maven-failsafe-plugin 时,不得使用 forkCount 0 或将 forkMode 设置为 never,因为这会阻止使用 javaagent 设置执行测试,并且不会记录覆盖范围。

参考:https: //www.eclemma.org/jacoco/trunk/doc/maven.html

这是我的要点


小智 10

由于项目中缺少测试,人们还可以获得"由于缺少执行数据文件而跳过JaCoCo执行"错误.例如,当您启动新项目并且根本没有*Test.java文件时.

  • 这是金子!帮助过我 (2认同)

Alw*_*mer 8

我知道这个问题已经很老了,但是如果像我这样的人来这里寻找答案,那么这可能会有所帮助。我已经能够克服上述错误。

1) 从插件 maven-surefire-plugin 中删除以下代码

 <reuseForks>true</reuseForks>
 <argLine>-Xmx2048m</argLine>
Run Code Online (Sandbox Code Playgroud)

2)添加以下目标:

<execution>
<id>default-prepare-agent</id>
<goals>
   <goal>prepare-agent</goal>
</goals>
</execution>
Run Code Online (Sandbox Code Playgroud)


Waq*_*tho 6

我也有同样的问题。我将 Jacoco 版本从 0.6 更新到 0.8,并更新了 Surefire 插件。以下命令在 site/jacoco/ 文件夹中生成 Jacoco 报告:

mvn clean jacoco:prepare-agent install jacoco:report
Run Code Online (Sandbox Code Playgroud)

我的maven配置如下:

<plugins>
    <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <version>0.8.6</version>
        <executions>
            <execution>
                <goals>
                    <goal>prepare-agent</goal>
                </goals>
            </execution>
            <execution>
                <id>jacoco-report</id>
                <phase>test</phase>
                <goals>
                    <goal>report</goal>
                </goals>
                    </execution>
            <execution>
                <id>jacoco-check</id>
                <goals>
                    <goal>check</goal>
                </goals>
                <configuration>
                    <rules>
                        <rule>
                            <element>PACKAGE</element>
                            <limits>
                                <limit>
                                    <counter>LINE</counter>
                                    <value>COVEREDRATIO</value>
                                    <minimum>0.0</minimum>
                                </limit>
                            </limits>
                        </rule>
                    </rules>
                </configuration>
            </execution>
        </executions>
    </plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>3.0.0-M5</version>
        <configuration>
            <forkedProcessExitTimeoutInSeconds>60</forkedProcessExitTimeoutInSeconds>
            <forkCount>1</forkCount>
        </configuration>
    </plugin>
</plugins>
Run Code Online (Sandbox Code Playgroud)


Bon*_*oat 5

FWhat tdrury 说:

将您的插件配置更改为:

<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>0.6.3.201306030806</version>
    <executions>
      <!-- prepare agent for measuring integration tests -->
      <execution>
        <id>prepare-integration-tests</id>
        <phase>pre-integration-test</phase>
        <goals>
          <goal>prepare-agent</goal>
        </goals>
        <configuration>
          <destFile>${basedir}/target/coverage-reports/jacoco-unit.exec</destFile>
        </configuration>
      </execution>
      <execution>
        <id>jacoco-site</id>
        <phase>post-integration-test</phase>
        <goals>
          <goal>report</goal>
        </goals>
        <configuration>
          <dataFile>${basedir}/target/coverage-reports/jacoco-unit.exec</dataFile>
        </configuration>
      </execution>
    </executions>
  </plugin>
Run Code Online (Sandbox Code Playgroud)

编辑:刚刚注意到一件重要的事情,destFile 和 dataFile 似乎区分大小写,所以它应该是 destFile,而不是 destfile。


Paw*_*ski 5

我已经尝试了所有答案,但只有以下建议组合对我有用。为什么?我有非常具体的要求:

  1. 从命令行运行构建时,JaCoCo 生成报告:mvn clean verify(Maven 3.6.0)
  2. Intellij IDEA (2019.01) 也运行我的测试
  3. 这一切都javaagentsurefire插件中定义的另一个存在的情况下工作

解决方案-如常见问题解答我的固定配置)中所述,使用“后期替换”maven 属性argLinesurefire配置中添加值@{...}surefire

如何在 argLine 中使用其他插件设置的属性?Maven 为

${...} 在运行任何插件之前 pom.xml 中的值。所以 Surefire 永远不会在其 argLine 属性中看到占位符。由于版本 2.17 对这些属性使用了替代语法,

@{...} 允许在执行插件时延迟替换属性,因此被其他插件修改的属性将被正确拾取。

第一次尝试失败 -在目标配置中定义 jaCoCoArgLine属性- 该场景未能满足我的第二个要求,IntelliJ IDEA 无法找出我在项目中用于静态方法模拟的 jmockit 代理prepare-agentjacoco

  • 使用 JMockit 时遇到同样的问题,并能够使用此解决方案解决该问题。即在 Surefire 插件中添加 argLine (2认同)

小智 5

刚刚遇到同样的问题。

我有一个名为 的类HelloWorld,我为它创建了一个名为的测试类HelloWorldTests,然后我得到了输出Skipping JaCoCo execution due to missing execution data file.

然后我试图改变我的pom.xml让它工作,但尝试失败了。

最后,我只是将其重命名HelloWorldTestsHelloWorldTest,并且成功了!

所以我猜,默认情况下,jacoco 只识别名为 like 的测试类XxxTest,这表明它是Xxx. 所以只需将您的测试类重命名为这种格式就可以了!


tdr*_*ury 1

执行表示它将 jacoco 数据放入 /Users/davea/Dropbox/workspace/myproject/target/jacoco.exec 但您的 Maven 配置正在 ${basedir}/target/coverage-reports/jacoco-unit 中查找数据。执行。


归档时间:

查看次数:

92013 次

最近记录:

6 年 前