目前,我正在执行模块级别的最低 JUnit 总覆盖率。因此,如果总线路覆盖率低于某个值(在我的情况下为 80%),则构建失败。为此,我将 maven-surefire-plugin 与 maven-enforcer-plugin、JUnit 和 JMockit 一起使用。pom 文件部分看起来像这样。
<build>
<plugins>
....
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit4</artifactId>
<version>2.18.1</version>
</dependency>
</dependencies>
<configuration>
<systemPropertyVariables>
<coverage-outputDir>${basedir}/target/coverageReport</coverage-outputDir>
<coverage-output>html,merge</coverage-output>
<coverage-check>80</coverage-check>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
<executions>
<execution>
<id>coverage.check</id>
<goals>
<goal>enforce</goal>
</goals>
<phase>test</phase>
<configuration>
<rules>
<requireFilesDontExist>
<files>
<file>coverage.check.failed</file>
</files>
</requireFilesDontExist>
</rules>
</configuration>
</execution>
</executions>
</plugin>
....
</build>
<dependencies>
....
<dependency>
<groupId>org.jmockit</groupId>
<artifactId>jmockit</artifactId>
<version>1.17</version>
</dependency>
<dependency>
<groupId>org.jmockit</groupId>
<artifactId>jmockit-coverage</artifactId>
<version>1.17</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
....
</dependencies>
我的问题是,有些类的覆盖率可能远低于 80%,只要总覆盖率不低于 80%,构建仍然可以通过。
那么,有什么方法可以在班级级别上强制执行我的覆盖范围吗?