我创建了一个基本的 Maven 包。src/main/java 目录包含:
public class Blah {
public int blah(){
return 1;
}
public int bluh(){
return 2;
}
}
src/test/java 目录包含:
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class BlahTest {
@Test
public void blahTest() {
Blah b = new Blah();
assertEquals(1, b.blah());
}
}
pom如下:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cob_test</groupId>
<artifactId>cob_test</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.7</version>
<configuration>
<check>
<haltOnFailure>true</haltOnFailure>
<branchRate>75</branchRate>
<lineRate>85</lineRate>
<totalBranchRate>75</totalBranchRate>
<totalLineRate>85</totalLineRate>
<packageLineRate>75</packageLineRate>
<packageBranchRate>85</packageBranchRate>
</check>
</configuration>
</plugin>
</plugins>
</reporting>
</project>
在我运行时,检查部分中的各种参数都没有得到验证mvn install
。由于有 2 个功能,我预计覆盖率为 50%,并且预期的最低覆盖率高于此值。因此,构建应该失败。此外,有没有一种方法可以在构建后立即在命令行上显示包级别覆盖数字,而不是将它们放在 html 文件中。
详细的拆分很有帮助,但我也想在违反最小覆盖限制时使构建失败。