命令行方式使用cobertura

比较喜欢用command line方式,因为这样省去了用ant task方式写xml的麻烦。前几次在执行了cobertura-instrument.bat之后,根据网上说的把cobertura.jar和cobertura.ser拷到tomcat的bin目录下,启动tomcat就会报错,见下图:

命令行方式使用cobertura

    后来在同事的帮助下,网上也查了一下,说要把jar包放在lib目录下,于是把cobertura.jar拷到tomcat/common/lib目录下,见下图:

命令行方式使用cobertura

再次启动tomcat,成功~

命令行方式使用cobertura

    对于用command line方式来使用cobertura,现总结如下:

1.拷贝cobertura.jar到tomcat/common/lib目录下;

2.对于需要统计覆盖率的class文件进行instrument,命令行格式如下:

cobertura-instrument.bat [--basedir dir] [--datafile file] [--destination dir] [--ignore regex] classes [...]

 []内的参数可省略,我destination等参数都没用,直接对要进行instrument的class操作,我的命令行如下:

命令行方式使用cobertura

3.instrument成功后会在cobertura的目录下生成cobertura.ser文件,将此文件拷到tomcat/bin目录下,见下图:

命令行方式使用cobertura

4.启动tomcat。在命令提示符窗口,转到tomcat/bin目录,键入startup.bat并回车;

5.启动成功后,tomcat/bin目录下的cobertura.ser的文件时间会更新;

6.和平常一样测试,测试结束后,关闭tomcat。在命令提示符窗口键入shutdown.bat并回车,然后Ctrl+C来关闭tomcat窗口,这样cobertura.ser才会更新,见下图:

命令行方式使用cobertura
一般每次测试并关闭tomcat后,cobertura.ser都是在原来的基础上更新,所以一般不用merge命令:)
7.生成report,命令行格式如下:

cobertura-report.bat [--datafile file] [--destination dir] [--format (html|xml)] [--encoding encoding] source code directory [...] [--basedir dir file underneath basedir ...]

默认是html格式,会生成好多html文件,见下图:

命令行方式使用cobertura
    上图中没有指明source code directory,在查看report时,会显示没有和源代码关联,因此需指定源代码所在的目录,如下图:

命令行方式使用cobertura
8.打开index.html文件,查看覆盖率,如下图:

命令行方式使用cobertura

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值