java junit 覆盖率,java单元测试篇:使用clover为junit单元测试做覆盖率分析(三)...

三、修改build.xml文件添加clover任务?7L;x9NYPJm_0

5X7rDp{X2H,J"V0现在我们开始修改build.xml文件,添加clover任务,以实现junit测试覆盖率的分析。首先,我们添加clover任务的配置任务;在build.xml文件里添加如下代码:51Testing软件测试网qSt:WE-a$_,^m

(LQ*S&udl4F051Testing软件测试网6vk-qd)l~RY

J)Aach"it0

0D-~rqa!h)ON0这两行定义了能够在ant文件里使用clover任务的配置工作。然后再添加一个clover任务,用来启动clover构建任务:*]y Q%Zm2T0

51Testing软件测试网5^4t.yi~Yr/\

-G$^[4Q,O:t,_r0

?(Elh qi051Testing软件测试网~4V.Wr Di v5b `_51Testing软件测试网2Mc%e I8|v a

这里的initString定义了clover覆盖数据库的信息,它会在执行clover任务时自动创建,里边保存了源路径执行测试任务时候的全部信息,clover通过这个demo_coverage.db来创建覆盖率分析报告。如果这个demo_coverage.db存在,clover在每次运行时自动覆盖,如果不存在,clover自动创建它。51Testing软件测试网([ r

yr;JW2V4iN

7CW"P(w,~cV0我们这里使用clover,是为了搜集junit测试时候的覆盖率信息,所以呢,junit测试过程中,我们需要使用clover.jar包,所以我们还需要把clover.jar文件作为junit运行的依赖库,因此修改build.classpath代码成如下所示:51Testing软件测试网&t1}I

P;j%N&W]`51Testing软件测试网&YdL?,[,pE?

H-x{ P6S3O/D"e9[t051Testing软件测试网&i3F+OX+A9T0FH&zH{

51Testing软件测试网9mHz#x ozRCGq5v

eaC.\t[051Testing软件测试网Pp;G7m6`\$A_51Testing软件测试网^jl,ZAH!NZ5z

vy:@P2k4d051Testing软件测试网q1dxCkP e1j

51Testing软件测试网 E9Y'eN V51Testing软件测试网+p0W8l dWWV

这里顺便我们也把path的值说明一下,省得有人不懂哦!这里的ant.home是在计算机里创建的环境变量ANT_HOME,它的值应该是你的ant的安装路径,例如c:ant,所以前两行代码的意思,就是把c:antlibclover.jar和c:antlibjunit.jar作为依赖库。当然,事先你一定要拷贝这两个jar文件到你的lib目录。51Testing软件测试网[WV4j kDn51Testing软件测试网}Me$|.{KgE

好了,我们现在开始重新使用clover任务来运行junit测试!51Testing软件测试网$EY,tP.lduc%[q

GY;t5\K z,Px?)|C:J0C:cloversincky>ant clean{f#G]}+\(}R#\$Y0

:o| k*a`0Buildfile: build.xml.OgN

WS&T0

taL e'_P0clean:7W+T:lgDe051Testing软件测试网B;g_&E0i}yE

[delete] Deleting directory C:cloversinckybuild51Testing软件测试网A

`"CE'm51Testing软件测试网5?YD{-N tZ

BUILD SUCCESSFUL51Testing软件测试网$p6mOO(p

/J)q[e^4b#iI0Total time: 0 seconds:m:M@Q]D~0

kb.Oq"kKx_-M0C:cloversincky>ant clover compile~T5A~:K2zu&]051Testing软件测试网c6q)x

Y'ZW-Q.T

v5H

Buildfile: build.xml51Testing软件测试网K^5Zn;|*y51Testing软件测试网w|2|_8fg]

clover:/Tfl9RU051Testing软件测试网

a;AWf/r1C1W

[clover-setup] Clover Version 1.3.8, built on May 18 2005$MVnpJz0

6I5d#]/M@)M0[clover-setup] loaded from: C:cloverlibclover.jar0`J7w${~%{Vg]jn4J0

s_'ZP2k"pnDcw-xeg0[clover-setup] 30 day Evaluation License registered to sinckyzhang@163.com51Testing软件测试网"c`;gg+z&k

lw3\@/L%ip*e-uL0[clover-setup] You have 10 day(s) before your Evaluation License expires.&mkS"Xbb8l M051Testing软件测试网:W'I%K d y3WSD

[clover-setup] Clover is enabled with initstring 'C:cloversinckydemo_coverage.db'F;t@-p,_#d051Testing软件测试网%S{S~-X1V:Z

compile:51Testing软件测试网Z#y&H\Z51Testing软件测试网8wz6Xpy+a

[mkdir] Created dir: C:cloversinckybuild#K`y0J3UV051Testing软件测试网rO:U:C+},Yd

[javac] Compiling 4 source files to C:cloversinckybuild7\F2D

N3}Q)IM0

ujm+aHY\1p0[clover] Clover Version 1.3.8, built on May 18 200551Testing软件测试网|W\c,O2j

1Ek7cSlh0[clover] loaded from: C:cloverlibclover.jart%~{v8c#jD1V051Testing软件测试网a T*?fH2t

[clover] 30 day Evaluation License registered to sinckyzhang@163.com

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值