我在我的pom中设置了Cobertura:
...
<build>
...
<plugins>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>${cobertura-maven-plugin.version}</version>
<configuration>
<formats>
<format>html</format>
</formats>
<outputDirectory>${project.build.directory}</outputDirectory>
<check>
<haltOnFailure>${testsAreRun}</haltOnFailure>
<totalBranchRate>27</totalBranchRate>
<totalLineRate>88</totalLineRate>
</check>
<instrumentation>
<ignoreTrivial>true</ignoreTrivial>
<excludes>
<exclude>something/app/**/*.class</exclude>
<exclude>something/config/**/*.class</exclude>
</excludes>
</instrumentation>
</configuration>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>clean</goal>
<!--<goal>cobertura</goal>-->
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
...
<plugins>
...
<build>
...
如果我跑:
mvn clean cobertura:cobertura
一切顺利。如果我跑:
mvn clean install
一切顺利。但是,如果我跑:
mvn clean cobertura:cobertura install
安装过程中构建失败,说我的代码覆盖率为0%,即:
[ERROR] Oct 22, 2014 3:03:59 PM net.sourceforge.cobertura.coveragedata.CoverageDataFileHandler loadCoverageData
INFO: Cobertura: Loaded information on 8 classes.
Project failed check. Total branch coverage rate of 0.0% is below 27.0%
Project failed check. Total line coverage rate of 0.0% is below 88.0%
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 15.839 s
[INFO] Finished at: 2014-10-22T15:03:59+01:00
[INFO] Final Memory: 38M/469M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:cobertura-maven-plugin:2.6:check (default) on project something: Coverage check failed. See messages above. -> [Help 1]
任何想法为什么?
答案 0 :(得分:0)
当你跑步时:
mvn cobertura:cobertura
它刚刚生成了报告。
当你跑
时mvn install
它会运行您在那里设置的所有插件,包括您已设置的具有线路和分支检查的配置