有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java jacoco maven插件未报告测试覆盖率

我试着用jacoco和maven。当我运行mvn clean测试时,我希望覆盖率输出会写入目标/覆盖率报告,但是当我打开索引时。html在构建之后,它是空的

我检查了以下内容, -杰科科。exec文件存在,其中包含一组类名 -在coverage html中有一个链接“Sessions”,当我点击它时,我会看到一堆似乎已经执行的类 -我在运行maven命令时没有看到错误或警告

我不明白为什么报告是空的。从我看到的所有例子来看,这似乎应该是可行的。我错过了什么

我正在为maven插件使用以下jacoco配置

  <plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <configuration>
      <append>true</append>
      <skip>false</skip>
      <excludes/>
      <outputDirectory>${project.build.directory}/coverage-reports/</outputDirectory>
      <dataFile>${project.build.directory}/jacoco.exec</dataFile>
      <includes>
        <include>mypackage.*</include>
      </includes>
      <check>false</check>
    </configuration>
    <executions>
      <execution>
        <id>pre-test</id>
        <goals>
          <goal>prepare-agent</goal>
        </goals>
      </execution>
      <execution>
        <id>post-test</id>
        <goals>
          <goal>report</goal>
        </goals>
        <phase>test</phase>
      </execution>
    </executions>
  </plugin>

更新

显然,这与我提供的includes模式有关。当我删除“包含”时,它确实显示了覆盖范围,但超出了我的需要。我仍在努力找出合适的包含模式


共 (1) 个答案

  1. # 1 楼答案

    你也需要把它挂到surefire上,换成

     <build>
            <plugins>
              <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.6.3.201306030806</version>
                <executions>
                  <!  pre-unit-test execution helps setting up some maven property,
                    which will be used later by JaCoCo  >
                  <execution>
                    <id>pre-unit-test</id>
                    <goals>
                      <goal>prepare-agent</goal>
                    </goals>
                    <configuration>
                      <destFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</destFile>
                      <!  passing property which will contains settings for JaCoCo agent.
                        If not specified, then "argLine" would be used for "jar" packaging  >
                      <propertyName>surefireArgLine</propertyName>
                    </configuration>
                  </execution>
                  <!  report phase setup  >
                  <execution>
                    <id>post-unit-test</id>
                    <phase>test</phase>
                    <goals>
                      <goal>report</goal>
                    </goals>
                    <configuration>
                      <!  output file with report data.  >
                      <dataFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</dataFile>
                      <!  output directory for the reports.  >
                      <outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
                    </configuration>
                  </execution>
                </executions>
              </plugin>
    
              <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.14</version>
                <executions>
                  <execution>
                    <id>default-test</id>
                    <phase>test</phase>
                    <goals>
                      <goal>test</goal>
                    </goals>
                    <configuration>
                      <argLine>${surefireArgLine}</argLine>
                    </configuration>
                  </execution>
                </executions>
                <configuration>
                  <argLine>-XX:MaxPermSize=512m</argLine>
                </configuration>
              </plugin>
            </plugins>
      </build>