gpt4 book ai didi

maven - 如何使用离线仪器生成Jacoco集成测试报告?

转载 作者:行者123 更新时间:2023-12-03 09:12:15 25 4
gpt4 key购买 nike

构建工具:Maven

使用离线检测的原因:删除 Powermock 不是一个选项

问题:运行failsafe 和surefire 并生成报告。但是,jacoco.exec 是生成的,但 jacoco-it.exec 不是。除了 IT 之外,离线检测、覆盖范围和报告也能正常工作。

这是我使用的maven插件配置:

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>default-instrument</id>
<goals>
<goal>instrument</goal>
</goals>
</execution>
<execution>
<id>default-restore-instrumented-classes</id>
<goals>
<goal>restore-instrumented-classes</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>default-report-integration</id>
<goals>
<goal>report-integration</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<systemPropertyVariables>
<jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.15</version>
<executions>
<execution>
<id>integration-tests</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<skipTests>${skip.integration.tests}</skipTests>
</configuration>
</execution>
</executions>
</plugin>

为了运行测试,我使用 maven clean install。

在测试执行结束时,我得到以下输出:

[INFO] 
[INFO] --- maven-failsafe-plugin:2.15:integration-test (integration-tests) @ elune ---
[INFO] Skipping execution of surefire because it has already been run for this configuration
[INFO]
[INFO] --- jacoco-maven-plugin:0.7.8:report (default-report) @ elune ---
[INFO] Loading execution data file C:\Projects\elune\target\jacoco.exec
[INFO] Analyzed bundle 'elune' with 4 classes
[INFO]
[INFO] --- jacoco-maven-plugin:0.7.8:report-integration (default-report-integration) @ elune ---
[INFO] Skipping JaCoCo execution due to missing execution data file.

另一个可能的提示可能是类的去仪器化发生在单元测试运行之后但集成测试之前。但我不知道这是对还是错:

[INFO] 
[INFO] --- jacoco-maven-plugin:0.7.8:restore-instrumented-classes (default-restore-instrumented-classes) @ elune ---
[INFO]
[INFO] --- maven-jar-plugin:2.6:jar (default-jar) @ elune ---
[INFO] Building jar: C:\Projects\elune\target\elune-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- spring-boot-maven-plugin:1.4.2.RELEASE:repackage (default) @ elune ---
[INFO]
[INFO] --- maven-failsafe-plugin:2.15:integration-test (default) @ elune ---
[INFO] Failsafe report directory: C:\Projects\elune\target\failsafe-reports

知道为什么 jacoco-it.exec 没有出现吗?

最佳答案

我认为使用故障安全插件进行集成测试的检测尚未融入。恢复检测类目标默认为在集成测试阶段之前运行的准备包阶段:http://maven.apache.org/ref/3.3.9/maven-core/lifecycles.html - 所以将这个目标转移到集成后测试阶段可能就足够了:

<execution>
<id>default-restore-instrumented-classes</id>
<phase>post-integration-test</phase>
<goals>
<goal>restore-instrumented-classes</goal>
</goals>
</execution>

这可能就足够了。否则,您也许可以更改 Surefire 插件的包含模式,以包含集成测试(如果这看起来适合您的情况)。

关于maven - 如何使用离线仪器生成Jacoco集成测试报告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41232650/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com