Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Cobertura检查未使生成失败_Java_Maven_Code Coverage_Cobertura_Maven Cobertura Plugin - Fatal编程技术网

Java Cobertura检查未使生成失败

Java Cobertura检查未使生成失败,java,maven,code-coverage,cobertura,maven-cobertura-plugin,Java,Maven,Code Coverage,Cobertura,Maven Cobertura Plugin,我创建了一个基本的maven包。src/main/java目录包含: public class Blah { public int blah(){ return 1; } public int bluh(){ return 2; } } import static org.junit.Assert.assertEquals; import org.junit.Test; public class BlahTest {

我创建了一个基本的maven包。src/main/java目录包含:

public class Blah {
    public int blah(){
        return 1;
    }

    public int bluh(){
        return 2;
    }
}
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());
    }
}
src/test/java目录包含:

public class Blah {
    public int blah(){
        return 1;
    }

    public int bluh(){
        return 2;
    }
}
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>

4.0.0
cob_试验
cob_试验
1.0-快照
朱尼特
朱尼特
4.12
测试
org.codehaus.mojo
cobertura maven插件
2.7
真的
75
85
75
85
75
85
当我运行
mvn install
时,检查部分中的各种参数未被验证。由于有2个函数,我预计覆盖率为50%,预期覆盖率最低值高于此值。因此,构建应该失败。另外,是否有一种方法可以在命令行上的构建之后立即显示包级别的覆盖率数字,而不是将它们显示在html文件中

详细的拆分很有帮助,但我也希望在违反最小覆盖率限制时使构建失败。

您必须执行

mvn verify
运行cobertura,因为它是verfiy生命周期阶段的默认运行

如果您想更改,可以按如下方式修改插件配置(将阶段从验证更改为您喜欢的阶段):


org.codehaus.mojo
cobertura maven插件
2.7
真的
75
85
75
85
75
85
验证
检查

unrecogned标签:“executions”应该是合法的:等等,你在pom的错误位置添加了插件,我会更新代码片段。