构建工具: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没有出现?
答案 0 :(得分:4)
我认为使用故障安全插件进行集成测试的工具尚未完成。恢复检测类目标默认为在集成测试阶段之前运行的prepare-package阶段: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插件的包含模式以包括集成测试(如果这似乎适合您的情况)。
答案 1 :(得分:0)
设置短语后,jacoco-it.exec未显示。 命令行是: mvn clean install -Djacoco.version = 0.7.8 -DfailOnError = false -Dmaven.test.failure.ignore = true
我终于发现问题是我没有在maven-failsafe-plugin中添加配置jacoco-agent.destfile。
<plugins>
<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>
<configuration>
<systemPropertyVariables>
<jacoco-agent.destfile>target/jacoco-it.exec</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<id>integration-tests</id>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>default-instrument</id>
<goals>
<goal>instrument</goal>
</goals>
</execution>
<execution>
<id>default-restore-instrumented-classes</id>
<phase>post-integration-test</phase>
<goals>
<goal>restore-instrumented-classes</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
答案 2 :(得分:0)
@ rhinoceros.xn这是插件配置,为我做了诀窍。但我使用mvn clean install
来运行此
<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>
<phase>post-integration-test</phase>
<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>