JCoverage VS Cobertura

头分配了一个任务,调查 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+ 是一个从同一代 展出来的封 源代 码产 品。

 

使用指南:

  1. 下载最新的 Cobertura版本( cobertura-1.9-bin.zip (binary)): http://cobertura.sourceforge.net/download.html
  2. eclipse中建立一个新的 java项目 basic
  3. 将下载的 cobertura-1.9-bin\cobertura-1.9\examples\basic中的内容拷贝到 basic项目中
  4. basic项目中建立 lib目录,将 cobertura-1.9-bin\cobertura-1.9\lib中的 jar文件拷贝过来,导入该项目(同时, cobertura-1.9-bin\cobertura-1.9\cobertura.jar也导入 basic
  5. 修改 build.properties中的“ cobertura.dir=../.. ”为“ cobertura.dir=./ ”;

修改 build.xml中的 <include name="lib/**/*.jar" /> <include name="lib/*.jar" />

并可以先将其中为“ clean ”的任务注释掉

  1. 运行 build.xml,若没有问题,控制台应该得到如下提示信息:

 

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

 

 

  1. reports目录中查看测试结果:

先看单体测试结果:

 

再看覆盖率测试结果:

 

 

 

 

注意: 运行 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中。

 

 

你可能感兴趣的:(eclipse,cms,ant,软件测试,JUnit)