[英]Jacoco coverage percentage maven
运行 mvn 测试时,我的 spring 引导应用程序构建成功。 当我执行 mvn clean install 或 mvn clean verify 时,构建失败。 这是因为我将最小代码覆盖率配置为 80%。 当我运行 mvn clean install/verify 时,结果显示指令覆盖率为 0.00,但预期最小值为 0.50。
在设置最小阈值之前,运行 mvn clean install 会给出以下结果,即覆盖率为 65%。 我的配置中缺少什么? 我错过了什么吗? 我怎样才能让 jacoco 选择正确的代码?
这是我的pom
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.agent</artifactId>
<version>0.8.5</version>
<classifier>runtime</classifier>
<scope>test</scope>
</dependency>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.5</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.1</version>
<dependencies>
<dependency>
<groupId>com.github.bitmc</groupId>
<artifactId>checkstyle</artifactId>
<version>8.35.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>*</exclude>
</excludes>
</configuration>
<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-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>jacoco-check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule>
<element>PACKAGE</element>
<excludes>
<exclude>com.pip</exclude>
</excludes>
<limits>
<limit>
<counter>INSTRUCTION</counter>
<value>COVEREDRATIO</value>
<minimum>0.50</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
我正在使用 java 版本“1.8.0_202”
在你的插件配置中需要这样设置;
`
...
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.2</version>
<configuration>
<excludes>
<exclude>**/PACKEGE YOU WANT EXCLUDE.*</exclude>
</excludes>
</configuration>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule>
<element>BUNDLE</element>
<limits>
<limit>
<counter>INSTRUCTION</counter>
<value>COVEREDRATIO</value>
<minimum>65%</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
`
在您的示例中,标签插件来自插件标签。
如果您将 Jacoco 与 PowerMockito 一起使用,并且您想要覆盖的 class 被记录在 PrepareForTest 中,那么在这种情况下,它将显示 0% 的覆盖率。 尝试从 PrepareForTest 中删除目标 class
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.