Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法运行jacoco代码覆盖率工具_Java_Maven_Code Coverage_Jacoco_Jacoco Maven Plugin - Fatal编程技术网

Java 无法运行jacoco代码覆盖率工具

Java 无法运行jacoco代码覆盖率工具,java,maven,code-coverage,jacoco,jacoco-maven-plugin,Java,Maven,Code Coverage,Jacoco,Jacoco Maven Plugin,我有一个maven项目(),我想对其运行代码覆盖率 我在主项目pom文件上运行了命令mvn test-Pcoverage jacoco:prepare agent jacoco:report,但没有生成报告。相反,我得到的警告是 [INFO] --- jacoco-maven-plugin:0.7.7.201606060606:report (post-test) @ pulsar-discovery-service --- [INFO] Skipping JaCoCo execution du

我有一个maven项目(),我想对其运行代码覆盖率

我在主项目pom文件上运行了命令
mvn test-Pcoverage jacoco:prepare agent jacoco:report
,但没有生成报告。相反,我得到的警告是

[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.
有人能建议我如何用这个生成代码覆盖率报告吗。我正在使用apache-maven-3.3.9和testNG。

您似乎缺少pom.xml中的下一行
It seems like you are missing below line in pom.xml 
<destFile>
   ${project.build.directory}/coverage-reports/jacoco-unit.exec
</destFile>
${project.build.directory}/coverage reports/jacoco-unit.exec
请查看以下pom:

org.jacoco
jacocomaven插件
0.7.1.201405082137
准备-jacoco-4-单元测试
配制剂
${project.build.directory}/coverage reports/jacoco-unit.exec
贾可考林
创建-jacoco-reports-4-unit-tests
准备包装
报告
${project.build.directory}/coverage reports/jacoco-unit.exec
然后在maven surefire插件中,应定义以下内容:

<plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-surefire-plugin</artifactId>
     <version>2.17</version>
     <configuration>
         <skipTests>${skipUnitTests}</skipTests>
         <argLine>${jacocoArgLine}</argLine>
     </configuration>
</plugin>

org.apache.maven.plugins
maven surefire插件
2.17
${skipUnitTests}
${JacoCargline}

以下内容对我们有效:

设置一些属性:

<properties>
    ...
    <!-- versions below are last ones that are Java 6 compatible -->
    <version.jacoco-agent>0.7.4.201502262128</version.jacoco-agent>
    <jacocoArgLine />
    <surefire.base.argLine>-XX:-UseSplitVerifier -XX:MaxPermSize=384m -Xmx1024m -Djava.awt.headless=true</surefire.base.argLine>
    ...
</properties>
包含

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

下面是一个完整的简单演示项目,展示了单元、集成和测试。测试覆盖率通过Jacoco显示

  • 多模块项目
  • 单元测试(通过mvn清洁安装)
  • 集成测试(通过mvn清洁安装-P集成测试)
  • Cumber测试(通过mvn清洁安装)-到演示单元/it测试
  • Jacoco-测试覆盖率(聚合数据文件和聚合报告)
  • FindBugs-代码质量

享受这一天

这可能会有帮助@Ravi-Nope没有帮助请显示您的
maven surefire插件
jacoco maven插件
配置。另外,您的
覆盖范围
配置文件是否包含对
sonar jacoco侦听器的依赖关系
?整个配置已按您在“”中所述进行了尝试,但仍然没有luckok,让我尝试克隆您的项目并在本地进行尝试。谢谢。谢谢你花时间提醒一下-测试套件非常庞大,所以在运行mvn作业之前删除测试(或者只保留一个),否则需要两个小时才能完成。找到-名称“*Test.java”| xargs rm-fNice Try-但未能在项目模块3上执行目标:无法解析项目nl的依赖项。deholtmans:module3:jar:1.0-SNAPSHOT:找不到工件nl。deholtmans:module1:jar:1.0-SNAPSHOT我没有投票
    <profile>
        <id>coverage</id>
        <build>
            <pluginManagement>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>${surefire.plugin.version}</version>
                        <configuration>
                            <argLine>${surefire.base.argLine} @{jacocoArgLine}</argLine>
                            <systemPropertyVariables>
                                <java.awt.headless>true</java.awt.headless>
                            </systemPropertyVariables>
                        </configuration>
                    </plugin>
                </plugins>
            </pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <executions>
                        <execution>
                            <goals>
                                <goal>prepare-agent</goal>
                                <goal>report</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
  <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>
  <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>