无法运行jacoco代码覆盖工具

use*_*858 3 java code-coverage maven jacoco jacoco-maven-plugin

我有一个maven项目(链接),我想在其上运行代码覆盖.

mvn test -Pcoverage jacoco:prepare-agent jacoco:report在主项目pom文件上运行命令,但不生成报告.相反,我得到一个警告说

[INFO] --- jacoco-maven-plugin:0.7.7.201606060606:report (post-test) @ pulsar-discovery-service ---
[INFO] Skipping JaCoCo execution due to missing execution data file.
[INFO] 
[INFO] --- jacoco-maven-plugin:0.7.7.201606060606:prepare-agent (default-cli) @ pulsar-discovery-service ---
[INFO] argLine set to -javaagent:/home/jai1/.m2/repository/org/jacoco/org.jacoco.agent/0.7.7.201606060606/org.jacoco.agent-0.7.7.201606060606-runtime.jar=destfile=/home/jai1/pulsar/pulsar-discovery-service/target/jacoco.exec
[INFO] 
[INFO] --- jacoco-maven-plugin:0.7.7.201606060606:report (default-cli) @ pulsar-discovery-service ---
[INFO] Skipping JaCoCo execution due to missing execution data file.
Run Code Online (Sandbox Code Playgroud)

有人可以建议如何使用此pom文件生成代码覆盖率报告.我正在使用apache-maven-3.3.9和testNG.

God*_*din 5

你的pom.xml包含

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.19.1</version>
    <configuration>
      <argLine> -Xmx2G -XX:MaxDirectMemorySize=8G
        -Dio.netty.leakDetectionLevel=advanced</argLine>
    </configuration>
  </plugin>
Run Code Online (Sandbox Code Playgroud)

目标状态的JaCoCo文档prepare-agent

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

...将"argLine"定义为Maven属性,而不是作为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>
Run Code Online (Sandbox Code Playgroud)