是否有任何 Java 测试框架(最好是 Jacoco 和/或 Sonar)可以让代码覆盖率较差的团队原谅现有的代码库,但要求新代码高于阈值(直到他们能够获得所有覆盖了旧代码!)
最佳答案
您可以将构建插件添加到您的 pom.xml 中。此操作正在进行至少 80% 的线路覆盖率检查。请参阅Jacoco doc了解更多信息。
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.0</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>jacoco-check</id>
<phase>test</phase>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule>
<element>BUNDLE</element>
<limits>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0.80</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
关于java - 如果新代码低于覆盖阈值,如何让构建失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47063528/