【问题标题】:JaCoCo report generation using maven使用 maven 生成 JaCoCo 报告
【发布时间】:2014-05-15 05:05:28
【问题描述】:

我在一个 jacoco.exec 文件中捕获了覆盖范围的详细信息。它的大小为 6Mb。 我需要使用 maven 生成覆盖率报告。 我尝试了以下

  <dependencies>
    <dependency>
      <groupId>org.jacoco</groupId>
      <artifactId>org.jacoco.ant</artifactId>
      <version>0.7.0.201403182114</version>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <version>0.6.3.201306030806</version>
        <executions>
          <!--
            Ensures that the code coverage report for integration tests after
            integration tests have been run.
          -->
          <execution>
            <id>post-integration-test</id>
            <phase>post-integration-test</phase>
            <goals>
              <goal>report</goal>
            </goals>
            <configuration>
              <!-- Sets the path to the file which contains the execution data. -->
              <dataFile>D:/JaCoCo/jacoco.exec</dataFile>
              <!-- Sets the output directory for the code coverage report. -->
              <outputDirectory>${project.reporting.outputDirectory}/jacoco-it</outputDirectory>
            </configuration>
          </execution>
        </executions>
      </plugin>      
    </plugins>
  </build>

它正在生成一个零百分比的覆盖率报告。

在测试之前,jacoco.exec 文件大小为零字节,现在大小为 6MB。 我在 pom.xml 中缺少什么吗?

【问题讨论】:

  • 嗨 user1226320 你知道为什么你的报告是空的吗?
  • 你的 classDumpDir 在哪里? Jacoco 需要 classDumpDir 和 dataFile 来生成我相信的报告

标签: maven jacoco


【解决方案1】:

这里是jacoco插件配置。

          <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.5.10.201208310627</version>
                <configuration>
                    <skip>${maven.test.skip}</skip>
                    <output>file</output>
                    <append>true</append>
                </configuration>
                <executions>
                    <execution>
                        <id>jacoco-initialize</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>jacoco-site</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
  1. 在运行maven:test 时会生成 jacoco.exec 文件
  2. 在运行jacoco:report 时,它会在target/site/jacoco 目录下的html 文件中生成报告。您可以通过打开 index.html 来查看报告

【讨论】:

  • 我已经生成了 jacoco.exec 文件。我只需要生成报告。
  • 运行 jacoco:report 时遇到的错误是什么
【解决方案2】:

运行mvn jacoco:report 它将生成覆盖率报告。打开 target/site/jacoco/index.html 文件以获取图片视图。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-06-13
    • 2021-12-28
    • 2018-12-18
    • 2015-07-19
    • 2018-09-09
    • 2019-06-08
    • 1970-01-01
    相关资源
    最近更新 更多