理解JaCoCo执行数据文件 | AI生成和翻译

Home 2025.09

以下是一份实用且全面的指南。

什么是 jacoco-it.exec

典型的 Maven 配置:

<plugin>
  <groupId>org.jacoco</groupId>
  <artifactId>jacoco-maven-plugin</artifactId>
  <version>0.8.12</version>
  <executions>
    <!-- 单元测试配置 -->
    <execution>
      <id>prepare-agent</id>
      <goals><goal>prepare-agent</goal></goals>
    </execution>
    <!-- 集成测试配置 -->
    <execution>
      <id>prepare-agent-integration</id>
      <goals><goal>prepare-agent-integration</goal></goals>
    </execution>
    <execution>
      <id>report</id>
      <phase>verify</phase>
      <goals><goal>report</goal></goals>
    </execution>
    <execution>
      <id>report-it</id>
      <phase>verify</phase>
      <goals><goal>report-integration</goal></goals>
    </execution>
  </executions>
</plugin>

该配置通常会生成 target/jacoco.exec(单元测试)和 target/jacoco-it.exec(集成测试)。

.exec 文件包含什么内容?

重要提示:

是否包含类结构信息?

通过 -javaagent 附加时会被更新吗?

简短回答:,具体细节如下:

常用代理选项:

-javaagent:/path/to/org.jacoco.agent.jar=\
destfile=/path/to/jacoco-it.exec,\
append=true,\
output=file

其他有用模式:

关于“更新”的说明:

典型工作流

集成测试阶段(Failsafe):

合并多次运行结果:

# 通过 Maven
mvn jacoco:merge -Djacoco.destFile=target/merged.exec \
  -Djacoco.dataFileList="target/jacoco.exec,target/jacoco-it.exec,other.exec"
# 然后
mvn jacoco:report -Djacoco.dataFile=target/merged.exec

常见问题与技巧


直接回答您的问题


Back Donate