头分配了一个任务,调查 JCoverage的使用,以下是我的调查情况:
-》主要是调查代码覆盖率测试的。(20090507追加)
一. JCoverage
JCoverage 的官网是: http://jcoverage.com/
不过,现在已经不再免费,变成商业软件了(收费 19.95 英镑):
http://cms.jcoverage.com/products/eclipse-plugin/pricing.html
主要信息在这个链接中 http://cms.jcoverage.com/products/eclipse-plugin/
二. Cobertura
Cobertura 是基于 jcoverage而发展起来的,也是用于代码覆盖率测试的,官网是 http://cobertura.sourceforge.net/index.html
官网上的介绍是: Cobertura is a free Java tool that calculates the percentage of code accessed by tests. It can be used to identify which parts of your Java program are lacking test coverage. It is based on jcoverage.
以下是网上摘录过来的一段介绍:
Cobertura 是 jcoverage 的分支。 GPL 版本的 jcoverage 已 经 有一年没有更新 过 了,并且有一些 长 期存在的 bug, Cobertura 修 复 了 这 些 bug。原来的那些 jcoverage 开发 人 员 不再 继续开发开 放源 码 ,他 们转 向 开发 jcoverage 的商 业 版和 jcoverage+, jcoverage+ 是一个从同一代 码 基 础 中 发 展出来的封 闭 源代 码产 品。
使用指南:
修改 build.xml中的 <include name="lib/**/*.jar" />为 <include name="lib/*.jar" />,
并可以先将其中为“ clean ”的任务注释掉
Buildfile: C:\kkkkk\workspace\basic\build.xml
init :
compile :
instrument :
[ delete ] Deleting: C:\kkkkk\workspace\basic\cobertura.ser
[ delete ] Deleting directory C:\kkkkk\workspace\basic\instrumented
[cobertura-instrument] Cobertura 1.9 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file
[cobertura-instrument] Instrumenting 1 file to C:\kkkkk\workspace\basic\instrumented
[cobertura-instrument] Cobertura: Saved information on 1 classes.
[cobertura-instrument] Instrument time: 78ms
test :
[ junit ] Cobertura: Loaded information on 1 classes.
[ junit ] Cobertura: Saved information on 1 classes.
[ junitreport ] Transform time: 407ms
coverage-report :
[cobertura-report] Cobertura 1.9 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file
[cobertura-report] Cobertura: Loaded information on 1 classes.
[cobertura-report] Report time: 109ms
alternate-coverage-report :
[cobertura-report] Cobertura 1.9 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file
[cobertura-report] Cobertura: Loaded information on 1 classes.
[cobertura-report] Report time: 188ms
coverage :
BUILD SUCCESSFUL
Total time: 3 seconds
先看单体测试结果:
再看覆盖率测试结果:
注意: 运行 build.xml时很可能会遇到 Could not create task or type of type junit 这个问题,请参考下面的解决办法:
摘自http://www.blogjava.net/andy199999/articles/77398.html
To fix this problem, you need to copy a JUnit.jar file to your eclipse/plugins/org.apache.ant/lib directory
Next you need to go into Eclipse then click on Window->Preferences->ant->Runtime, then select 'Ant Home Entries (Default). Click on the button 'Add External JARs'. Locate the junit.jar file you copied, select it and hit 'OK'. Hit 'Apply', then 'OK' and try your ant task again. That should fix it.
-》要解决这一问题,您需要复制JUnit.jar文件到你的eclipse/plugins/org.apache.ant/lib 目录下。
接下来,您需要进入Eclipse ,点击窗口> “预置> ”ant“> 运行,然后选择'ant主页条目(默认) 。按一下按钮,添加外部jar文件。找到junit.jar文件复制,请选择它并点击'确定' 。打击'应用' ,然后'确定' ,然后再试一次你的Ant任务。这应该能修复它。(20090507追加)
摘自:http://savegod.bokee.com/5402057.html
在eclipse中使用ant脚本、调用junit的task时会出现上述错误,解决方法:
1。将junit.jar 拷贝到eclipse的ant插件的目录下的lib中
2。在eclipse->windows->ant->runtime中设置ant加载的jar,增加一个外部的jar,将
添加的junit.jar加入到ant的classpath中。