maven集成cobertura生成junit code coverage报告

maven 同时被 2 个专栏收录
5 篇文章 0 订阅
3 篇文章 0 订阅

修改pom.xml 增加如下插件:

  1. <plugin>
  2. <groupId>org.codehaus.mojo</groupId>
  3. <artifactId>cobertura-maven-plugin</artifactId>
  4. <version>2.6</version>
  5. <configuration>
  6. <formats>
  7. <format>html</format>
  8. <format>xml</format>
  9. </formats>
  10. <instrumentation>
  11. <excludes>
  12. <exclude>com/**/*Test.class</exclude>
  13. </excludes>
  14. </instrumentation>
  15. </configuration>
  16. </plugin>


增加reporting配置:

  1. <reporting>
  2. <plugins>
  3. <plugin>
  4. <groupId>org.codehaus.mojo</groupId>
  5. <artifactId>cobertura-maven-plugin</artifactId>
  6. <configuration>
  7. <formats>
  8. <format>html</format>
  9. <format>xml</format>
  10. </formats>
  11. </configuration>
  12. </plugin>
  13. </plugins>
  14. </reporting>


利用 mvn cobertura:cobertura 就可以生成report了, 生成的report在你项目根目录的 target/site/cobertura/下面

这下面有两种格式的report, html的可以直接在你本地浏览浏览器打开。 xml结构可以提供给第三方程序调用显示result。
有关jenkins集成cobertura请参考如下文章: