jacoco的maven插件使用

最近要把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/.........找到统计结果

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值