【发布时间】:2018-04-14 06:46:41
【问题描述】:
是否有任何 Java 测试框架(最好是 Jacoco 和/或 Sonar)允许代码覆盖率较差的团队原谅现有的代码库,但要求新代码高于阈值,(直到他们能够获得所有旧代码覆盖!)
【问题讨论】:
-
您可能还想在softwarerecs.stackexchange.com上提问
标签: java sonarqube automated-tests code-coverage jacoco
是否有任何 Java 测试框架(最好是 Jacoco 和/或 Sonar)允许代码覆盖率较差的团队原谅现有的代码库,但要求新代码高于阈值,(直到他们能够获得所有旧代码覆盖!)
【问题讨论】:
标签: java sonarqube automated-tests code-coverage jacoco
您可以在 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>
【讨论】:
我希望您可以使用 Sonar Quality Gates 执行此操作,并将其与您的 CI 服务器集成。在 Jenkins 中,您可能想尝试 Quality Gates Plugin。
【讨论】: