- 浏览: 683495 次
- 性别:
- 来自: 沈阳
文章分类
- 全部博客 (270)
- Ant Tool Script (12)
- XMLDigest (5)
- MyEclipse8.6 (1)
- RedHat (5)
- SVNVersionController (4)
- BatOperation (6)
- JspAndFaceWeb (66)
- javaSwing (18)
- PHP (12)
- J2SE (6)
- TestToolAndTestManual (12)
- C# (34)
- Java PatternDesign (20)
- Axis2AndWebService (5)
- ITLive (2)
- DBAndControl (10)
- C/C++ (8)
- Andriod (7)
- Python (7)
- JavaWork (16)
- Android-QA (1)
- Apache-Wicket (1)
- POI (1)
- JQuery (2)
- Struts2 (1)
- Flex&Flash (6)
- sdsdsd (0)
- 1212 (0)
最新评论
-
anayomin:
对九楼继续改进
public static <T> ...
Java List 分页 -
H4X0R:
来学习学习,赞一个
Aqua Data Studio 导出SQL -
yankai0219:
现在出现这个错误 Fatal error: Class 'PH ...
纯PHP搭建Apache+Eclipse+xDebug+PHPUnit+MakeGood -
yankai0219:
您好,我在搭建环境中提示PHPUnit_Framework_T ...
纯PHP搭建Apache+Eclipse+xDebug+PHPUnit+MakeGood -
wilsonchen:
chenhailong 写道wilsonchen 写道chen ...
C# RSA和Java RSA互通
Java Coverage(Cobertura)工具
最近有点清闲了,我的前辈让我研究Java Coverage的工具,发现这个Cobertura很名就给大家介绍一下吧
首先当然是下载Cobertura的jar包了,这个工具底层是JCoverage,熟悉Jcoverage的对这个也不会陌生的
Cobertura官网 http://cobertura.sourceforge.net/
大家可以了解很多东西,比如现在的作者啊什么,这里就不介绍了
然后点Download,下载二进制版本,比如名字叫cobertura-1.9.4.1(我用的是最新的version)
最后就是实践了。。下面就给大家讲解一下这个到底是什么玩意
Cobertura是一个开源的java工具,它主要用在java test中 内部封装了JCoverage
它是一个用ant全自动的测试工具,很强大。
如果你想测试覆盖率的话,用这个软件是相当不错的
那么下面就举一个简单的例子来说明它的强大
以下为要测试的Java类
package com.example.simple; /** * @author cnchenhl 2011/02/25 */ public class PrintStringOfYourName { private String name = null; private int id = 0; private String sex = null; private int age = 0; private String address; public String getName() { return name; } public int getId() { return id; } public String getSex() { return sex; } public int getAge() { return age; } public String getAddress() { return address; } public void setName(String name) { this.name = name; } public void setId(int id) { this.id = id; } public void setSex(String sex) { this.sex = sex; } public void setAge(int age) { this.age = age; } public void setAddress(String address) { this.address = address; } public String toString() { return "Name :" + name + "ID :" + id + "Age :" + age + "Sex :" + sex + "Address :" + address; } }
下面是测试的类test
package com.example.simple; import junit.framework.TestCase; import org.junit.Before; import org.junit.Test; /** * * @author cnchenhl 2011/02/25 */ public class PrintStringOfYourNameTest extends TestCase { @Before public void setUp() throws Exception { System.setProperty("Dnet.sourceforge.cobertura.datafile", "D:/TestCorbertura/cobertura.ser"); } @Test public void testtoString() { PrintStringOfYourName printStringOfYourName = new PrintStringOfYourName(); printStringOfYourName.setAddress("shanghai"); printStringOfYourName.setAge(24); printStringOfYourName.setId(0); printStringOfYourName.setName("chenhailong"); printStringOfYourName.setSex("male"); String str = printStringOfYourName.toString(); assertEquals(str, "Name :chenhailongID :0Age :24Sex :maleAddress :shanghai"); } }
好了准备工作完成了
那就准备自己的ant构建文件了。路径大家要仔细看,可能会有问题的,基本都是你们的路径有问题。
还要说明的一点是
System.setProperty("Dnet.sourceforge.cobertura.datafile", ""D:/TestCorbertura/cobertura.ser"");
是必须加的,官网指定的,大家要注意。因为instruments容易找不到cobertura.ser 文件,在ant中也要设定
具体的请看构建文件build.xml
<?xml version="1.0" encoding="UTF-8"?> <project name="cobertura.examples.basic" default="coverage" basedir="."> <property file="build.properties" /> <property name="bin.dir" value="${basedir}/bin" /> <property name="target" value="target" /> <path id="cobertura.classpath"> <fileset dir="${cobertura.dir}"> <include name="cobertura.jar" /> <include name="lib/**/*.jar" /> </fileset> </path> <taskdef classpathref="cobertura.classpath" resource="tasks.properties"/> <target name="init"> <mkdir dir="${classes.dir}" /> <mkdir dir="${instrumented.dir}" /> <mkdir dir="${reports.xml.dir}" /> <mkdir dir="${reports.html.dir}" /> <mkdir dir="${coverage.xml.dir}" /> <mkdir dir="${coverage.summaryxml.dir}" /> <mkdir dir="${coverage.html.dir}" /> <mkdir dir="${target}" /> </target> <target name="compile" depends="init"> <javac srcdir="${src.dir}" destdir="${classes.dir}" debug="yes"> <classpath refid="cobertura.classpath" /> </javac> </target> <target name="instrument" depends="init,compile"> <echo message="copy the file to the classes" /> <copy todir="${classes.dir}"> <fileset dir="${bin.dir}"> <include name="**/*.class" /> </fileset> </copy> <delete file="cobertura.ser" /> <delete dir="${instrumented.dir}" /> <cobertura-instrument todir="${instrumented.dir}"> <ignore regex="org.apache.log4j.*" /> <fileset dir="${classes.dir}"> <include name="**/*.class" /> <exclude name="**/*Test.class" /> </fileset> </cobertura-instrument> </target> <target name="test" depends="init,compile"> <junit fork="yes" dir="${basedir}" failureProperty="test.failed"> <classpath location="${instrumented.dir}" /> <classpath location="${classes.dir}" /> <classpath > </classpath> <classpath refid="cobertura.classpath" /> <formatter type="xml" /> <test name="${testcase}" todir="${reports.xml.dir}" if="testcase" /> <batchtest todir="${reports.xml.dir}" unless="testcase"> <fileset dir="${src.dir}"> <include name="**/*Test.java" /> </fileset> </batchtest> </junit> <junitreport todir="${reports.xml.dir}"> <fileset dir="${reports.xml.dir}"> <include name="TEST-*.xml" /> </fileset> <report format="frames" todir="${reports.html.dir}" /> </junitreport> </target> <target name="coverage-check"> <cobertura-check branchrate="34" totallinerate="100" /> </target> <target name="coverage-report"> <cobertura-report srcdir="${src.dir}" destdir="${coverage.xml.dir}" format="xml" /> </target> <target name="summary-coverage-report"> <cobertura-report srcdir="${src.dir}" destdir="${coverage.summaryxml.dir}" format="summaryXml" /> </target> <target name="alternate-coverage-report"> <cobertura-report destdir="${coverage.html.dir}"> <fileset dir="${src.dir}"> <include name="**/*.java"/> </fileset> </cobertura-report> </target> <target name="clean" description="Remove all files created by the build/test process."> <delete dir="${classes.dir}" /> <delete dir="${instrumented.dir}" /> <delete dir="${reports.dir}" /> <delete file="cobertura.log" /> <delete file="cobertura.ser" /> <delete dir="${target}" /> </target> <target name="coverage" depends="compile,instrument,test,coverage-report,summary-coverage-report,alternate-coverage-report,band" description="Compile, instrument ourself, run the tests and generate JUnit and coverage reports." /> <target name="band"> <delete file="${target}/report.zip" /> <jar destfile="${target}/report.zip" basedir="${reports.dir}"> <manifest> <attribute name="Build-Time" value="${timeStamp.day}" /> </manifest> </jar> </target> </project>
下面是构建文件需要的环境变量
# The source code for the examples can be found in this directory src.dir=src # The path to cobertura.jar cobertura.dir=D:/cobertura-1.9.4.1 # Classes generated by the javac compiler are deposited in this directory classes.dir=classes # Instrumented classes are deposited into this directory instrumented.dir=instrumented # All reports go into this directory reports.dir=reports # Unit test reports from JUnit are deposited into this directory reports.xml.dir=${reports.dir}/junit-xml reports.html.dir=${reports.dir}/junit-html # Coverage reports are deposited into these directories coverage.xml.dir=${reports.dir}/cobertura-xml coverage.summaryxml.dir=${reports.dir}/cobertura-summary-xml coverage.html.dir=${reports.dir}/cobertura-html
好了以上就大功告成了
哈哈
大家也尝试一下
如果有什么问题的话请给我留言!
谢谢大家的支持
发表评论
-
注册表修改IE—Proxy
2013-06-18 13:07 0[HKEY_CURRENT_USER\Softwar ... -
TestNG 测试工具介绍
2012-11-20 10:42 1461可以说TestNG的功能已经 ... -
YUIDoc Javascript Documentation Tool
2012-11-13 16:32 1296有的时候,生活就像和你作对,你越想干的事情,越干不来,但不想干 ... -
Spring mock 的三种形式
2012-10-16 07:17 2226今天看到一个文章: Spring mock的三种形式: ... -
Mockito怎么样Mock返回值为空的方法
2012-10-15 15:57 21734Mockito怎么样Mock返回值为空的方法? Moc ... -
JUnit Exception: No tests found in *******
2012-10-15 15:50 3152今天遇到以一个问题: JUnit找不到Test的类。 ... -
Closure Compiler实践
2012-07-22 11:15 0Clousure Compiler 是Google的JS 压 ... -
"A script on this page is causing Internet Explorer to run slowly“解决方案
2012-02-16 17:09 3040今天遇到了IE6等版本的s ... -
Eclipse Plugin EasyExplore
2011-12-22 10:49 1150好不容易在官网找到,希望对大家有用 官网现在下不 ... -
Selenium IDE1.1.0 详解(非安装教程)
2011-08-23 21:53 3577今天被一个项目的无厘头工具搞的要死,索性用了selenium强 ... -
Cygwin 统计代码量---工具最有用的一句话
2011-05-30 14:15 1436perl CountDiff.pl -woc -a -i se ... -
Djunit---------Ant 执行指南
2011-03-24 06:58 3858我想大家一定会遇到这个问题的 Djunit 是很强大的软件, ... -
JUnit jumpStart (Junit 起步)
2011-01-29 11:47 1533JUnit jumpStart Never in the ...
相关推荐
Java Coverage(Cobertura)工具
cobertura代码覆盖率工具,有工具包,并且付上一份自己给项目组写的手册一份。
代码测试覆盖率工具包cobertura.jar
代码测试覆盖率工具,该工具与ant执行集成,快速简单有效的测试代码的覆盖率,内附测试用例
Cobertura 是一种代码覆盖测试工具,它通过检测基本的代码,并观察在测试包运行时执行了哪些代码和没有执行哪些代码,来测量测试覆盖率。
Cobertura代码覆盖率测试工具介绍文档,Cobertura代码覆盖率测试工具介绍
Cobertura是一个测试案例覆盖率统计工具,此资源下载后,解压,配置上环境变量即可使用
cobertura测试代码
Cobertura is a free Java code coverage reporting tool. It is based on jcoverage 1.0.5. See the Cobertura web page and wiki for more details. Since 2.0.0, Cobertura versions follow the Semantic ...
cobertura junit java 单元测试 测试驱动
Junit+ant+cobertura示例源码程序。
Cobertura可用于分析Java代码的测试覆盖率。Cobertura根据没有被测试覆盖的代码生成基于HTML的报告。 Cobertura提供可用于插装、检查和测试代码的工具。通过监控可测试的代码,Cobertura允许你使用你选择的测试框架...
NULL 博文链接:https://fnzi.iteye.com/blog/1584621
cobertura1.9.1,里面有一个现成的ant+junit+cobertura的build.xml文件。
在测试驱动开发中,单元测试非常重要,而测试代码的分支覆盖率和行覆盖率同样重要,目前比较流行的单元测试工具为junit,而覆盖率测试工具cobertura非常好用,现在将2者集成到一块,个人感觉在现实的开发中还是比较...
cobertura-2.1.1.jar下载
Cobertura Jenkins 插件
Cobertura插件 该插件使您可以捕获代码覆盖率报告。 詹金斯(Jenkins)将生成覆盖率趋势报告。Cobertura插件可以在。 版本记录 可以在下面找到版本历史记录: 标记的发行版可以在以下页面上找到: :warning: 此...
cobertura-1.9.4.1-src.zip