jacoco的maven插件使用

来源:互联网 发布:马丁全单吉他知乎 编辑:程序博客网 时间:2024/06/05 09:56

最近要把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

<build><plugins><!-- jacoco plugin --><plugin><groupId>org.jacoco</groupId><artifactId>jacoco-maven-plugin</artifactId><version>0.7.9</version><executions><execution><!-- 在maven的initialize阶段,将Jacoco的runtime agent作为VM的一个参数 传给被测程序,用于监控JVM中的调用。 --><id>default-prepare-agent</id><goals><goal>prepare-agent</goal></goals><configuration><destFile>${project.build.directory}/coverage-reports/jacoco.exec</destFile><propertyName>surefireArgLine</propertyName></configuration></execution><!-- 在程序的verify阶段,执行report测试的程序。 文件的输入为perpare-agent阶段中设置或者默认的jacoco.exec. 参数 includes和excludes可用来选定report中过滤的类。 --><execution><id>default-report</id><phase>test</phase><goals><goal>report</goal></goals><configuration><dataFile>${project.build.directory}/coverage-reports/jacoco.exec</dataFile><outputDirectory>${project.reporting.outputDirectory}/jacoco</outputDirectory></configuration></execution></executions></plugin><!-- 使用 maven-surefire-plugin来执行单元测试。 将surefireArgLine赋值给argLine参数,以保证在测试执行时Jacoco agent处于运行状态。 --><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-surefire-plugin</artifactId><version>2.19.1</version><configuration><argLine>${surefireArgLine}</argLine></configuration></plugin></plugins></build>

mvn test,然后在target/site/.........找到统计结果

0 0
原创粉丝点击