jacoco的maven插件使用

来源:互联网 发布:妈妈讲故事软件 编辑:程序博客网 时间:2024/06/05 04:13

最近要把java中的代码覆盖率搞起来,开始使用的是emma,百度了好久没有搞定,然后换成jacoco。其中收集了一些资料:

eclipse的eclemma插件,使用的jacoco, 搞起来最轻松

http://www.eclemma.org/ 


emma的maven插件:

http://www.cnblogs.com/morebetter/archive/2013/06/26/3156756.html


jacoco的maven插件:

http://blog.csdn.net/wangmuming/article/details/28868833

http://www.cnblogs.com/D-Key/p/4530876.html  ----想迅速用起来,这篇blog足够


emma好久不更新了,在配置的过程中,总是遇到:   Illegal local variable table start_pc 6 in method , 貌似是jdk版本高了。。。 然后放弃了。

改用jacoco,配置如下

pom.xml中添加:摘自http://www.cnblogs.com/D-Key/p/4530876.html

[html] view plain copy
  1. <span style="font-size:18px;"><build>  
  2.         <plugins>  
  3.             <!-- jacoco plugin -->  
  4.             <plugin>  
  5.                 <groupId>org.jacoco</groupId>  
  6.                 <artifactId>jacoco-maven-plugin</artifactId>  
  7.                 <version>0.7.9</version>  
  8.                 <executions>  
  9.                     <execution>  
  10.                         <!-- 在maven的initialize阶段,将Jacoco的runtime agent作为VM的一个参数 传给被测程序,用于监控JVM中的调用。 -->  
  11.                         <id>default-prepare-agent</id>  
  12.                         <goals>  
  13.                             <goal>prepare-agent</goal>  
  14.                         </goals>  
  15.   
  16.   
  17.                         <configuration>  
  18.                             <destFile>  
  19.                                 ${project.build.directory}/coverage-reports/jacoco.exec  
  20.                             </destFile>  
  21.                             <propertyName>surefireArgLine</propertyName>  
  22.                         </configuration>  
  23.   
  24.   
  25.                     </execution>  
  26.   
  27.   
  28.                     <!-- 在程序的verify阶段,执行report测试的程序。 文件的输入为perpare-agent阶段中设置或者默认的jacoco.exec.   
  29.                         参数 includes和excludes可用来选定report中过滤的类。 -->  
  30.                     <execution>  
  31.                         <id>default-report</id>  
  32.                         <phase>test</phase>  
  33.                         <goals>  
  34.                             <goal>report</goal>  
  35.                         </goals>  
  36.   
  37.   
  38.                         <configuration>  
  39.                             <dataFile>${project.build.directory}/coverage-reports/jacoco.exec</dataFile>  
  40.                             <outputDirectory>${project.reporting.outputDirectory}/jacoco</outputDirectory>  
  41.                         </configuration>  
  42.   
  43.   
  44.                     </execution>  
  45.   
  46.   
  47.                 </executions>  
  48.             </plugin>  
  49.   
  50.   
  51.             <!-- 使用 maven-surefire-plugin来执行单元测试。 将surefireArgLine赋值给argLine参数,以保证在测试执行时Jacoco   
  52.                 agent处于运行状态。 -->  
  53.             <plugin>  
  54.                 <groupId>org.apache.maven.plugins</groupId>  
  55.                 <artifactId>maven-surefire-plugin</artifactId>  
  56.                 <version>2.19.1</version>  
  57.                 <configuration>  
  58.                     <argLine>${surefireArgLine}</argLine>  
  59.                 </configuration>  
  60.             </plugin>  
  61.         </plugins>  
  62.     </build></span>  

mvn test,然后在target/site/.........找到统计结果
原创粉丝点击