我已在 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 中是否缺少某些内容?
这里是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>
maven:test
它将生成jacoco.exec文件jacoco:report
,它会在 target/site/jacoco 目录下的 html 文件中生成报告。您可以打开index.html查看报告运行
mvn jacoco:report
它将生成覆盖率报告。打开 target/site/jacoco/index.html 文件即可获取图片视图。