如果行或分支覆盖率低于给定阈值,我正在尝试将WAR项目构建配置为失败.我一直在使用优秀的Java Power Tools书籍第455页提供的配置,但没有成功.这是我的项目Maven 2 POM的相关片段:
... ... ... org.codehaus.mojo cobertura-maven-plugin 2.2 80 80 90 90 clean check coverage-tests verify clean check au/**/*Constants.* au/**/*Constants.*
正如我所说,覆盖率报告工作正常,问题是如果线或分支覆盖率低于我指定的阈值,"安装"目标不会失败.有没有人有这个工作,如果是这样,你的POM是什么样的,你使用的是哪个版本的Cobertura和Maven?我正在使用Maven 2.0.9和Cobertura 2.2.
我已经尝试过谷歌搜索和阅读Cobertura文档,但没有运气(后者至少可以说是稀疏的).
据我所知,如果
元素设置为true并且任何指定的检查失败,那么Cobertura将导致构建失败,这正是您所要求的.但实际上,这个元素默认为true
如果不指定,所以你不必把它添加到您的配置检查.使构建低于任何覆盖阈值是(或至少应该是)默认行为.
编辑:我做了一些进一步的测试,haltOnFailure
似乎在我的环境中正常工作(Maven 2.2.1.和插件版本2.3,2.2,2.1,即Linux上的cobertura版本1.9.2,1.9,1.8).我正在使用下面的结果更新此答案.
实际上,我已经
在我的pom中添加了一个元素.我可能会误解的部分的Cobertura:检查,指出它'的文档默认绑定的生命周期阶段:verify
’但是,如果没有
元素的Cobertura:检查过程中未触发验证我的构建阶段.在我用于cobertura-maven-plugin的设置下面:
... ... ... org.codehaus.mojo cobertura-maven-plugin 2.3 80 80 90 90 verify check
在使用上面提到的插件配置修补mvn clean install
的新生成的maven项目上运行时,我得到以下结果mvn archetype:create
:
$ mvn archetype:create -DgroupId=com.mycompany.samples -DartifactId=cobertura-haltonfailure-testcase ... $ mvn clean install [INFO] Scanning for projects... [INFO] ------------------------------------------------------------------------ [INFO] Building cobertura-haltonfailure-testcase [INFO] task-segment: [clean, install] [INFO] ------------------------------------------------------------------------ [INFO] [clean:clean {execution: default-clean}] [INFO] Deleting directory /home/pascal/Projects/cobertura-haltonfailure-testcase/target [INFO] [resources:resources {execution: default-resources}] [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! [INFO] skip non existing resourceDirectory /home/pascal/Projects/cobertura-haltonfailure-testcase/src/main/resources [INFO] [compiler:compile {execution: default-compile}] [INFO] Compiling 1 source file to /home/pascal/Projects/cobertura-haltonfailure-testcase/target/classes [INFO] [resources:testResources {execution: default-testResources}] [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! [INFO] skip non existing resourceDirectory /home/pascal/Projects/cobertura-haltonfailure-testcase/src/test/resources [INFO] [compiler:testCompile {execution: default-testCompile}] [INFO] Compiling 1 source file to /home/pascal/Projects/cobertura-haltonfailure-testcase/target/test-classes [INFO] [surefire:test {execution: default-test}] [INFO] Surefire report directory: /home/pascal/Projects/cobertura-haltonfailure-testcase/target/surefire-reports ------------------------------------------------------- T E S T S ------------------------------------------------------- Running com.mycompany.samples.AppTest Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.09 sec Results : Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 [INFO] [jar:jar {execution: default-jar}] [INFO] Building jar: /home/pascal/Projects/cobertura-haltonfailure-testcase/target/cobertura-haltonfailure-testcase-1.0-SNAPSHOT.jar [INFO] Preparing cobertura:check [WARNING] Removing: check from forked lifecycle, to prevent recursive invocation. [INFO] [resources:resources {execution: default-resources}] [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! [INFO] skip non existing resourceDirectory /home/pascal/Projects/cobertura-haltonfailure-testcase/src/main/resources [INFO] [compiler:compile {execution: default-compile}] [INFO] Nothing to compile - all classes are up to date [INFO] [cobertura:instrument {execution: default}] [INFO] Cobertura 1.9.2 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file Instrumenting 1 file to /home/pascal/Projects/cobertura-haltonfailure-testcase/target/generated-classes/cobertura Cobertura: Saved information on 1 classes. Instrument time: 337ms [INFO] Instrumentation was successful. [INFO] [resources:testResources {execution: default-testResources}] [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! [INFO] skip non existing resourceDirectory /home/pascal/Projects/cobertura-haltonfailure-testcase/src/test/resources [INFO] [compiler:testCompile {execution: default-testCompile}] [INFO] Nothing to compile - all classes are up to date [INFO] [surefire:test {execution: default-test}] [INFO] Surefire report directory: /home/pascal/Projects/cobertura-haltonfailure-testcase/target/surefire-reports ------------------------------------------------------- T E S T S ------------------------------------------------------- Running com.mycompany.samples.AppTest Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.098 sec Results : Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 [INFO] [cobertura:check {execution: default}] [INFO] Cobertura 1.9.2 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file Cobertura: Loaded information on 1 classes. [ERROR] com.mycompany.samples.App failed check. Line coverage rate of 0.0% is below 80.0% Project failed check. Total line coverage rate of 0.0% is below 90.0% [INFO] ------------------------------------------------------------------------ [ERROR] BUILD ERROR [INFO] ------------------------------------------------------------------------ [INFO] Coverage check failed. See messages above. [INFO] ------------------------------------------------------------------------ [INFO] For more information, run Maven with the -e switch [INFO] ------------------------------------------------------------------------ [INFO] Total time: 18 seconds [INFO] Finished at: Sat Oct 24 21:00:39 CEST 2009 [INFO] Final Memory: 17M/70M [INFO] ------------------------------------------------------------------------ $
我没有使用maven 2.0.9进行测试,但是在我的机器上,haltOnFailure
生成了BUILD ERROR并停止了构建.我没有看到您的插件配置有任何差异,我无法重现您描述的行为.