﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-GHawk-随笔分类-软件测试</title><link>http://www.blogjava.net/ghawk/category/6026.html</link><description /><language>zh-cn</language><lastBuildDate>Tue, 27 Feb 2007 19:07:27 GMT</lastBuildDate><pubDate>Tue, 27 Feb 2007 19:07:27 GMT</pubDate><ttl>60</ttl><item><title>开源 Java 测试框架（转）</title><link>http://www.blogjava.net/ghawk/archive/2006/01/10/27346.html</link><dc:creator>GHawk</dc:creator><author>GHawk</author><pubDate>Tue, 10 Jan 2006 02:41:00 GMT</pubDate><guid>http://www.blogjava.net/ghawk/archive/2006/01/10/27346.html</guid><wfw:comment>http://www.blogjava.net/ghawk/comments/27346.html</wfw:comment><comments>http://www.blogjava.net/ghawk/archive/2006/01/10/27346.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/ghawk/comments/commentRss/27346.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/ghawk/services/trackbacks/27346.html</trackback:ping><description><![CDATA[<SPAN class=style7><SPAN class=style7>from &nbsp;<A href="http://blog.csdn.net/wangyihust/archive/2006/01/02/568616.aspx">http://blog.csdn.net/wangyihust/archive/2006/01/02/568616.aspx</A> 
<DIV class=story>
<H2><IMG onmousewheel="return bbimg(this)" title=点击新窗口查看大图 height=14 alt="" src="http://www.open-open.com/image/item.gif" width=13 onload="java_script_:if(this.width>600)this.width=600" border=0>&nbsp;<A href="http://www.open-open.com/open30443.htm"><FONT color=#003366>JUnit</FONT></A>&nbsp;&nbsp;<SPAN class=NavigationColor>&nbsp;</SPAN></H2>
<P>JUnit是由 Erich Gamma 和 Kent Beck 编写的一个回归测试框架（regression testing framework）。Junit测试是程序员测试，即所谓白盒测试，因为程序员知道被测试的软件如何（How）完成功能和完成什么样（What）的功能。Junit是一套框架，继承TestCase类，就可以用Junit进行自动测试了。 </P>
<P><A href="http://www.junit.org/"><FONT color=#003366>http://www.junit.org/</FONT></A></P></DIV>
<DIV class=story>
<H2><FONT color=#003366><IMG onmousewheel="return bbimg(this)" title=点击新窗口查看大图 height=14 alt="" src="http://www.open-open.com/image/item.gif" width=13 onload="java_script_:if(this.width>600)this.width=600" border=0></FONT>&nbsp;<A href="http://www.open-open.com/open30543.htm"><FONT color=#003366>Cactus&nbsp;</FONT></A>&nbsp;<SPAN class=NavigationColor>&nbsp;</SPAN></H2>
<P>Cactus是一个基于JUnit框架的简单测试框架，用来单元测试服务端Java代码。Cactus框架的主要目标是能够单元测试服务端的使用Servlet对象的Java方法如HttpServletRequest,HttpServletResponse,HttpSession等。</P>
<P><A href="http://jakarta.apache.org/cactus/"><FONT color=#003366>http://jakarta.apache.org/cactus/</FONT></A></P></DIV>
<DIV class=story>
<H2><FONT color=#003366><IMG onmousewheel="return bbimg(this)" title=点击新窗口查看大图 height=14 alt="" src="http://www.open-open.com/image/item.gif" width=13 onload="java_script_:if(this.width>600)this.width=600" border=0></FONT>&nbsp;<A href="http://www.open-open.com/open30643.htm"><FONT color=#003366>Abbot</FONT></A>&nbsp;&nbsp;<SPAN class=NavigationColor>&nbsp;</SPAN></H2>
<P>Abbot是一个用来测试Java GUIs的框架。用简单的基于XML的脚本或者Java代码，你就可以开始一个GUI。</P>
<P><A href="http://abbot.sourceforge.net/"><FONT color=#003366>http://abbot.sourceforge.net/</FONT></A></P></DIV>
<DIV class=story>
<H2><FONT color=#003366><IMG onmousewheel="return bbimg(this)" title=点击新窗口查看大图 height=14 alt="" src="http://www.open-open.com/image/item.gif" width=13 onload="java_script_:if(this.width>600)this.width=600" border=0></FONT>&nbsp;<A href="http://www.open-open.com/open30743.htm"><FONT color=#003366>JUnitPerf</FONT></A>&nbsp;&nbsp;<SPAN class=NavigationColor>&nbsp;</SPAN></H2>
<P>Junitperf实际是junit的一个decorator，通过编写用于junitperf的单元测试，我们也可使测试过程自动化。</P>
<P><A href="http://www.clarkware.com/software/JUnitPerf.html"><FONT color=#003366>http://www.clarkware.com/software/JUnitPerf.html</FONT></A></P></DIV>
<DIV class=story>
<H2><FONT color=#003366><IMG onmousewheel="return bbimg(this)" title=点击新窗口查看大图 height=14 alt="" src="http://www.open-open.com/image/item.gif" width=13 onload="java_script_:if(this.width>600)this.width=600" border=0></FONT>&nbsp;<A href="http://www.open-open.com/open30843.htm"><FONT color=#003366>DbUnit</FONT></A>&nbsp;&nbsp;<SPAN class=NavigationColor>&nbsp;</SPAN></H2>
<P>DbUnit是为数据库驱动的项目提供的一个对JUnit 的扩展，除了提供一些常用功能，它可以将你的数据库置于一个测试轮回之间的状态。 </P>
<P><A href="http://dbunit.sourceforge.net/"><FONT color=#003366>http://dbunit.sourceforge.net/</FONT></A></P></DIV>
<DIV class=story>
<H2><FONT color=#003366><IMG onmousewheel="return bbimg(this)" title=点击新窗口查看大图 height=14 alt="" src="http://www.open-open.com/image/item.gif" width=13 onload="java_script_:if(this.width>600)this.width=600" border=0></FONT>&nbsp;<A href="http://www.open-open.com/open30943.htm"><FONT color=#003366>Mockrunner</FONT></A>&nbsp;&nbsp;<SPAN class=NavigationColor>&nbsp;</SPAN></H2>
<P>Mockrunner用在J2EE环境中进行应用程序的单元测试。它不仅支持Struts actions, servlets，过滤器和标签类还包括一个JDBC和一个JMS测试框架，可以用于测试基于EJB的应用程序。</P>
<P><A href="http://mockrunner.sourceforge.net/index.html"><FONT color=#003366>http://mockrunner.sourceforge.net/index.html</FONT></A></P></DIV>
<DIV class=story>
<H2><FONT color=#003366><IMG onmousewheel="return bbimg(this)" title=点击新窗口查看大图 height=14 alt="" src="http://www.open-open.com/image/item.gif" width=13 onload="java_script_:if(this.width>600)this.width=600" border=0></FONT>&nbsp;<A href="http://www.open-open.com/open31043.htm"><FONT color=#003366>DBMonster</FONT></A>&nbsp;&nbsp;<SPAN class=NavigationColor>&nbsp;</SPAN></H2>
<P>DBMonster是一个用生成随机数据来测试SQL数据库的压力测试工具。</P>
<P><A href="http://dbmonster.kernelpanic.pl/"><FONT color=#003366>http://dbmonster.kernelpanic.pl/</FONT></A></P></DIV>
<DIV class=story>
<H2><FONT color=#003366><IMG onmousewheel="return bbimg(this)" title=点击新窗口查看大图 height=14 alt="" src="http://www.open-open.com/image/item.gif" width=13 onload="java_script_:if(this.width>600)this.width=600" border=0></FONT>&nbsp;<A href="http://www.open-open.com/open31143.htm"><FONT color=#003366>MockEJB</FONT></A>&nbsp;&nbsp;<SPAN class=NavigationColor>&nbsp;</SPAN></H2>
<P>MockEJB是一个不需要EJB容器就能运行EJB并进行测试的轻量级框架。</P>
<P><A href="http://mockejb.sourceforge.net/"><FONT color=#003366>http://mockejb.sourceforge.net/</FONT></A></P></DIV>
<DIV class=story>
<H2><FONT color=#003366><IMG onmousewheel="return bbimg(this)" title=点击新窗口查看大图 height=14 alt="" src="http://www.open-open.com/image/item.gif" width=13 onload="java_script_:if(this.width>600)this.width=600" border=0></FONT>&nbsp;<A href="http://www.open-open.com/open31243.htm"><FONT color=#003366>StrutsTestCase</FONT></A>&nbsp;&nbsp;<SPAN class=NavigationColor>&nbsp;</SPAN></H2>
<P>StrutsTestCase 是Junit TestCase类的扩展，提供基于Struts框架的代码测试。StrutsTestCase同时提供Mock 对象方法和Cactus方法用来实际运行Struts ActionServlet，你可以通过运行servlet引擎来测试。因为StrutsTestCase使用ActionServlet控制器来测试你的代码，因此你不仅可以测试Action对象的实现，而且可以测试mappings，from beans以及forwards声明。StrutsTestCase不启动servlet容器来测试struts应用程序（容器外测试）也属于Mock对象测试，但是与EasyMock不同的是，EasyMock是提供了创建Mock对象的API，而StrutsTest则是专门负责测试Struts应用程序的Mock对象测试框架。 </P>
<P><A href="http://strutstestcase.sourceforge.net/"><FONT color=#003366>http://strutstestcase.sourceforge.net/</FONT></A></P></DIV>
<DIV class=story>
<H2><FONT color=#003366><IMG onmousewheel="return bbimg(this)" title=点击新窗口查看大图 height=14 alt="" src="http://www.open-open.com/image/item.gif" width=13 onload="java_script_:if(this.width>600)this.width=600" border=0></FONT>&nbsp;<A href="http://www.open-open.com/open31343.htm"><FONT color=#003366>JFCUnit</FONT></A>&nbsp;&nbsp;<SPAN class=NavigationColor>&nbsp;</SPAN></H2>
<P>JFCUnit使得你能够为Java偏移应用程序编写测试例子。它为从用代码打开的窗口上获得句柄提供了支持；为在一个部件层次定位部件提供支持；为在部件中发起事件（例如按一个按钮）以及以线程安全方式处理部件测试提供支持。</P>
<P><A href="http://jfcunit.sourceforge.net/"><FONT color=#003366>http://jfcunit.sourceforge.net/</FONT></A></P></DIV>
<DIV class=story>
<H2><FONT color=#003366><IMG onmousewheel="return bbimg(this)" title=点击新窗口查看大图 height=14 alt="" src="http://www.open-open.com/image/item.gif" width=13 onload="java_script_:if(this.width>600)this.width=600" border=0></FONT>&nbsp;<A href="http://www.open-open.com/open31443.htm"><FONT color=#003366>JTestCase</FONT></A>&nbsp;&nbsp;<SPAN class=NavigationColor>&nbsp;</SPAN></H2>
<P>JTestCase 使用XML文件来组织多测试案例数据，声明条件（操作和期望的结果），提供了一套易于使用的方法来检索XML中的测试案例，按照数据文件的定义来声明结果。</P>
<P><A href="http://jtestcase.sourceforge.net/"><FONT color=#003366>http://jtestcase.sourceforge.net/</FONT></A></P></DIV>
<DIV class=story>
<H2><FONT color=#003366><IMG onmousewheel="return bbimg(this)" title=点击新窗口查看大图 height=14 alt="" src="http://www.open-open.com/image/item.gif" width=13 onload="java_script_:if(this.width>600)this.width=600" border=0></FONT>&nbsp;<A href="http://www.open-open.com/open31543.htm"><FONT color=#003366>SQLUnit</FONT></A>&nbsp;&nbsp;<SPAN class=NavigationColor>&nbsp;</SPAN></H2>
<P>SQLUnit是一个单元测试框架，用于对数据库存储过程进行回归测试。用 Java/JUnit/XML开发。 </P>
<P><A href="http://sqlunit.sourceforge.net/"><FONT color=#003366>http://sqlunit.sourceforge.net</FONT></A></P></DIV>
<DIV class=story>
<H2><FONT color=#003366><IMG onmousewheel="return bbimg(this)" title=点击新窗口查看大图 height=14 alt="" src="http://www.open-open.com/image/item.gif" width=13 onload="java_script_:if(this.width>600)this.width=600" border=0></FONT>&nbsp;<A href="http://www.open-open.com/open59643.htm"><FONT color=#003366>JTR</FONT></A>&nbsp;&nbsp;<SPAN class=NavigationColor>&nbsp;</SPAN></H2>
<P>JTR (Java Test Runner)是一个开源的基于反转控制(IOC)的J2EE测试框架。它允许你构建复杂的J2EE测试套件(Test Suites)并连到应用服务器执行测试,可以包括多个测试实例。JTR的licensed是GPL协议。</P>
<P><A href="http://jtrunner.sourceforge.net/"><FONT color=#003366>http://jtrunner.sourceforge.net/</FONT></A></P></DIV>
<DIV class=story>
<H2><FONT color=#003366><IMG onmousewheel="return bbimg(this)" title=点击新窗口查看大图 height=14 alt="" src="http://www.open-open.com/image/item.gif" width=13 onload="java_script_:if(this.width>600)this.width=600" border=0></FONT>&nbsp;<A href="http://www.open-open.com/open64143.htm"><FONT color=#003366>Marathon</FONT></A>&nbsp;&nbsp;<SPAN class=NavigationColor>&nbsp;</SPAN></H2>
<P>Marathon是一个针对使用Java/Swing开发GUI应用程序的测试框架，它由recorder, runner 和 editor组成，测试脚本是python代码。Marathon的焦点是放在最终用户的测试上。</P>
<P><A href="http://marathonman.sourceforge.net/"><FONT color=#003366>http://marathonman.sourceforge.net</FONT></A></P></DIV>
<DIV class=story>
<H2><FONT color=#003366><IMG onmousewheel="return bbimg(this)" title=点击新窗口查看大图 height=14 alt="" src="http://www.open-open.com/image/item.gif" width=13 onload="java_script_:if(this.width>600)this.width=600" border=0></FONT>&nbsp;<A href="http://www.open-open.com/open64243.htm"><FONT color=#003366>TestNG</FONT></A>&nbsp;&nbsp;<SPAN class=NavigationColor>&nbsp;</SPAN></H2>
<P>TestNG是根据JUnit 和 NUnit思想而构建的一个测试框架，但是TestNG增加了许多新的功能使得它变得更加强大与容易使用比如：<BR>*支持JSR 175注释（JDK 1.4利用JavaDoc注释同样也支持）<BR>*灵活的Test配置<BR>*支持默认的runtime和logging JDK功能<BR>*强大的执行模型（不再TestSuite）<BR>*支持独立的测试方法。</P>
<P><A href="http://testng.org/"><FONT color=#003366>http://testng.org/</FONT></A></P></DIV>
<DIV class=story>
<H2><FONT color=#003366><IMG onmousewheel="return bbimg(this)" title=点击新窗口查看大图 height=14 alt="" src="http://www.open-open.com/image/item.gif" width=13 onload="java_script_:if(this.width>600)this.width=600" border=0></FONT>&nbsp;<A href="http://www.open-open.com/open64343.htm"><FONT color=#003366>Surrogate Test framework</FONT></A>&nbsp;&nbsp;<SPAN class=NavigationColor>&nbsp;</SPAN></H2>
<P>Surrogate Test framework是一个值得称赞单元测试框架，特别适合于大型，复杂Java系统的单元测试。这个框架能与JUnit,MockEJB和各种支持模拟对象（mock object ）的测试工具无缝给合。这个框架基于AspectJ技术。 
<P><A href="http://surrogate.sourceforge.net/"><FONT color=#003366>http://surrogate.sourceforge.net</FONT></A></P></DIV>
<DIV class=story>
<H2><FONT color=#003366><IMG onmousewheel="return bbimg(this)" title=点击新窗口查看大图 height=14 alt="" src="http://www.open-open.com/image/item.gif" width=13 onload="java_script_:if(this.width>600)this.width=600" border=0></FONT>&nbsp;<A href="http://www.open-open.com/open64443.htm"><FONT color=#003366>MockCreator</FONT></A>&nbsp;&nbsp;<SPAN class=NavigationColor>&nbsp;</SPAN></H2>
<P>MockCreator可以为给定的interface或class生成模拟对象（Mock object）的源码。</P>
<P><A href="http://mockcreator.sourceforge.net/"><FONT color=#003366>http://mockcreator.sourceforge.net/</FONT></A></P></DIV>
<DIV class=story>
<H2><FONT color=#003366><IMG onmousewheel="return bbimg(this)" title=点击新窗口查看大图 height=14 alt="" src="http://www.open-open.com/image/item.gif" width=13 onload="java_script_:if(this.width>600)this.width=600" border=0></FONT>&nbsp;<A href="http://www.open-open.com/open64543.htm"><FONT color=#003366>jMock</FONT></A>&nbsp;&nbsp;<SPAN class=NavigationColor>&nbsp;</SPAN></H2>
<P>jMock利用mock objects思想来对Java code进行测试。jMock具有以下特点:容易扩展，让你快速简单地定义mock objects,因此不必打破程序间的关联，让你定义灵活的超越对象之间交互作用而带来测试局限，减少你测试地脆弱性。</P>
<P><A href="http://www.jmock.org/"><FONT color=#003366>http://www.jmock.org/</FONT></A></P></DIV>
<DIV class=story>
<H2><FONT color=#003366><IMG onmousewheel="return bbimg(this)" title=点击新窗口查看大图 height=14 alt="" src="http://www.open-open.com/image/item.gif" width=13 onload="java_script_:if(this.width>600)this.width=600" border=0></FONT>&nbsp;<A href="http://www.open-open.com/open64643.htm"><FONT color=#003366>EasyMock</FONT></A>&nbsp;&nbsp;<SPAN class=NavigationColor>&nbsp;</SPAN></H2>
<P>EasyMock为Mock Objects提供接口并在JUnit测试中利用Java的proxy设计模式生成它们的实例。EasyMock最适合于测试驱动开发。</P>
<P><A href="http://www.easymock.org/"><FONT color=#003366>http://www.easymock.org/</FONT></A></P></DIV>
<DIV class=story>
<H2><FONT color=#003366><IMG onmousewheel="return bbimg(this)" title=点击新窗口查看大图 height=14 alt="" src="http://www.open-open.com/image/item.gif" width=13 onload="java_script_:if(this.width>600)this.width=600" border=0></FONT>&nbsp;<A href="http://www.open-open.com/open64743.htm"><FONT color=#003366>The Grinder</FONT></A>&nbsp;&nbsp;<SPAN class=NavigationColor>&nbsp;</SPAN></H2>
<P>The Grinder是一个负载测试框架。在BSD开源协议下免费使用。</P>
<P><A href="http://grinder.sourceforge.net/"><FONT color=#003366>http://grinder.sourceforge.net/</FONT></A></P></DIV>
<DIV class=story>
<H2><FONT color=#003366><IMG onmousewheel="return bbimg(this)" title=点击新窗口查看大图 height=14 alt="" src="http://www.open-open.com/image/item.gif" width=13 onload="java_script_:if(this.width>600)this.width=600" border=0></FONT>&nbsp;<A href="http://www.open-open.com/open64843.htm"><FONT color=#003366>XMLUnit</FONT></A>&nbsp;&nbsp;<SPAN class=NavigationColor>&nbsp;</SPAN></H2>
<P>XMLUnit不仅有Java版本的还有.Net版本的。Java开发的XMLUnit提供了两个JUnit 扩展类XMLAssert和XMLTestCase,和一组支持的类。这些类可以用来比较两张XML之间的不同之处，展示XML利用XSLT来,校验XML,求得XPath表达式在XML中的值,遍历XML中的某一节点利DOM展开。</P>
<P><A href="http://xmlunit.sourceforge.net/"><FONT color=#003366>http://xmlunit.sourceforge.net/</FONT></A></P></DIV>
<DIV class=story>
<H2><FONT color=#003366><IMG onmousewheel="return bbimg(this)" title=点击新窗口查看大图 height=14 alt="" src="http://www.open-open.com/image/item.gif" width=13 onload="java_script_:if(this.width>600)this.width=600" border=0></FONT>&nbsp;<A href="http://www.open-open.com/open64943.htm"><FONT color=#003366>Jameleon</FONT></A>&nbsp;&nbsp;<SPAN class=NavigationColor>&nbsp;</SPAN></H2>
<P>Jameleon一个自动化测试工具。它被用来测试各种各样的应用程序，所以它被设计成插件模式。为了使整个测试过程变得简单Jameleon提供了一个GUI,因此Jameleon实现了一个Swing 插件。</P>
<P><A href="http://jameleon.sourceforge.net/index.html"><FONT color=#003366>http://jameleon.sourceforge.net/index.html</FONT></A></P></DIV>
<DIV class=story>
<H2><FONT color=#003366><IMG onmousewheel="return bbimg(this)" title=点击新窗口查看大图 height=14 alt="" src="http://www.open-open.com/image/item.gif" width=13 onload="java_script_:if(this.width>600)this.width=600" border=0></FONT>&nbsp;<A href="http://www.open-open.com/open79343.htm"><FONT color=#003366>J2MEUnit</FONT></A>&nbsp;&nbsp;<SPAN class=NavigationColor>&nbsp;</SPAN></H2>
<P>J2MEUnit是应用在J2ME应用程序的一个单元测试框架。它基于JUnit。</P>
<P><A href="http://j2meunit.sourceforge.net/"><FONT color=#003366>http://j2meunit.sourceforge.net/</FONT></A></P></DIV>
<H2 class=story><FONT color=#003366><IMG onmousewheel="return bbimg(this)" title=点击新窗口查看大图 height=14 alt="" src="http://www.open-open.com/image/item.gif" width=13 onload="java_script_:if(this.width>600)this.width=600" border=0></FONT>&nbsp;<A href="http://www.open-open.com/open83943.htm"><FONT color=#003366>Jetif</FONT></A>&nbsp;&nbsp;<SPAN class=NavigationColor>&nbsp;</SPAN></H2>
<P class=story><SPAN class=NavigationColor></SPAN><FONT size=3>Jetif是一个用纯Java实现的回归测试框架。它为Java程序单元测试以及功能测试提供了一个简单而且可 伸缩的架构，可以用于个人开发或企业级开发的测试。它容易使用，功能强大，而且拥有一些企业级测试的重要功能。Jetif来源于JUnit, JTestCase以及TestNG的启发，有几个基本的概念直接来自于JUnit， 比如说断言机制，Test Listener的概念，因此从JUnit转到Jetif是非常容易的。</FONT></P>
<P class=story><A href="http://jetif.sourceforge.net/"><FONT color=#003366>http://jetif.sourceforge.net/</FONT></A></P>
<H2 class=story><FONT size=2><FONT color=#003366><IMG onmousewheel="return bbimg(this)" title=点击新窗口查看大图 height=14 alt="" src="http://www.open-open.com/image/item.gif" width=13 onload="java_script_:if(this.width>600)this.width=600" border=0></FONT>&nbsp;</FONT><A href="http://www.open-open.com/open84043.htm"><FONT color=#003366>GroboUtils</FONT></A><FONT size=2>&nbsp;&nbsp;<SPAN class=NavigationColor>&nbsp;</SPAN></FONT></H2>
<P class=story><SPAN class=NavigationColor></SPAN><FONT size=3>GroboUtils使得扩展Java测试变得可能。它包括用在Java不同方面测试的多个子项目。在GroboUtils中最常被到的工具是:多线程测试(multi-threaded tests),整体单元测试(hierarchial unit tests),代码覆盖工具(code coverage tool)。</FONT></P>
<P class=story><A href="http://groboutils.sourceforge.net/"><FONT color=#003366>http://groboutils.sourceforge.net/</FONT></A></P>
<H2 class=story><FONT size=2><FONT color=#003366><IMG onmousewheel="return bbimg(this)" title=点击新窗口查看大图 height=14 alt="" src="http://www.open-open.com/image/item.gif" width=13 onload="java_script_:if(this.width>600)this.width=600" border=0></FONT>&nbsp;</FONT><A href="http://www.open-open.com/open85343.htm"><FONT color=#003366>Testare</FONT></A><FONT size=2>&nbsp;&nbsp;<SPAN class=NavigationColor>&nbsp;</SPAN></FONT></H2>
<P class=story><SPAN class=NavigationColor></SPAN><FONT size=3>TESTARE是用来简化分布式应用程序(比如:在SERVLETS,JMS listeners, CORBA ORBs或RMI环境下)测试开发过程的一个测试框架。</FONT></P>
<P class=story><A href="https://testare.dev.java.net/"><FONT color=#003366>https://testare.dev.java.net/</FONT></A></P></SPAN></SPAN><img src ="http://www.blogjava.net/ghawk/aggbug/27346.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/ghawk/" target="_blank">GHawk</a> 2006-01-10 10:41 <a href="http://www.blogjava.net/ghawk/archive/2006/01/10/27346.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>用 Cobertura 测量测试覆盖率</title><link>http://www.blogjava.net/ghawk/archive/2005/12/17/24331.html</link><dc:creator>GHawk</dc:creator><author>GHawk</author><pubDate>Sat, 17 Dec 2005 03:23:00 GMT</pubDate><guid>http://www.blogjava.net/ghawk/archive/2005/12/17/24331.html</guid><wfw:comment>http://www.blogjava.net/ghawk/comments/24331.html</wfw:comment><comments>http://www.blogjava.net/ghawk/archive/2005/12/17/24331.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/ghawk/comments/commentRss/24331.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/ghawk/services/trackbacks/24331.html</trackback:ping><description><![CDATA[<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR vAlign=top>
<TD width="100%">
<H1><A href="http://www-128.ibm.com/developerworks/cn/java/j-cobertura/"><FONT size=3>http://www-128.ibm.com/developerworks/cn/java/j-cobertura/</FONT></A></H1>
<H1>用 Cobertura 测量测试覆盖率</H1>
<P id=subtitle>找出隐藏 bug 的未测试到的代码</P><IMG class=display-img height=6 alt="" src="http://www.ibm.com/i/c.gif" width=1></TD>
<TD class=no-print width=192><IMG height=18 alt=developerWorks src="http://www-128.ibm.com/developerworks/i/dw.gif" width=192></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR vAlign=top>
<TD width=10><IMG height=1 alt="" src="http://www.ibm.com/i/c.gif" width=10></TD>
<TD width="100%">
<TABLE class=no-print cellSpacing=0 cellPadding=0 width=160 align=right border=0>
<TBODY>
<TR>
<TD width=10><IMG height=1 alt="" src="http://www.ibm.com/i/c.gif" width=10></TD>
<TD>
<TABLE cellSpacing=0 cellPadding=0 width=150 border=0>
<TBODY>
<TR>
<TD class=v14-header-1-small>文档选项</TD></TR></TBODY></TABLE>
<TABLE class=v14-gray-table-border cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD class=no-padding width=150>
<TABLE cellSpacing=0 cellPadding=0 width=143 border=0><IMG height=1 alt="" src="http://www.ibm.com/i/c.gif" width=8> 
<FORM name=email action=https://www-130.ibm.com/developerworks/secure/email-it.jsp><INPUT type=hidden value="Cobertura 是一种开源工具，它通过检测基本的代码，并观察在测试包运行时执行了哪些代码和没有执行哪些代码，来测量测试覆盖率。除了找出未测试到的代码并发现 bug 外，Cobertura 还可以通过标记无用的、执行不到的代码来优化代码，还可以提供 API 实际操作的内部信息。Elliotte Rusty Harold 将与您分享如何利用代码覆盖率的最佳实践来使用 Cobertura。" name=body><INPUT type=hidden value="用 Cobertura 测量测试覆盖率" name=subject><INPUT type=hidden value=cn name=lang>
<SCRIPT language=JavaScript type=text/javascript>
<!--
document.write('<tr valign="top"><td width="8"><img src="//www.ibm.com/i/c.gif" width="8" height="1" alt=""/></td><td width="16"><img src="//www.ibm.com/i/v14/icons/em.gif" height="16" width="16" vspace="3" alt="将此页作为电子邮件发送" /></td><td width="122"><p><a class="smallplainlink" href="javascript:document.email.submit();"><b>将此页作为电子邮件发送</b></a></p></td></tr>');
//-->
</SCRIPT>
 
<TBODY>
<TR vAlign=top>
<TD width=8><IMG height=1 alt="" src="http://www.ibm.com/i/c.gif" width=8></TD>
<TD width=16><IMG height=16 alt=将此页作为电子邮件发送 src="http://www.ibm.com/i/v14/icons/em.gif" width=16 vspace=3></TD>
<TD width=122>
<P><A class=smallplainlink href="javascript:document.email.submit();"><B><FONT color=#5c81a7 size=2>将此页作为电子邮件发送</FONT></B></A></P></TD></TR><NOSCRIPT><tr valign="top"><td width="8"><img alt="" height="1" width="8" src="//www.ibm.com/i/c.gif"/></td><td width="16"><img alt="" width="16" height="16" src="//www.ibm.com/i/c.gif"/></td><td class="small" width="122"><p><span class="ast">未显示需要 JavaScript 的文档选项</span></p></td></tr></NOSCRIPT></FORM></TBODY></TABLE></TD></TR></TBODY></TABLE><BR>
<TABLE cellSpacing=0 cellPadding=0 width=150 border=0>
<TBODY>
<TR>
<TD class=v14-header-1-small>对此页的评价</TD></TR></TBODY></TABLE>
<TABLE class=v14-gray-table-border cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD class=no-padding width=150>
<TABLE cellSpacing=0 cellPadding=0 width=143 border=0>
<TBODY>
<TR vAlign=top>
<TD width=8><IMG height=1 alt="" src="http://www.ibm.com/i/c.gif" width=8></TD>
<TD><IMG height=16 alt="" src="http://www.ibm.com/i/v14/icons/d_bold.gif" width=16 vspace=3 border=0></TD>
<TD width=125>
<P><A class=smallplainlink href="http://www-128.ibm.com/developerworks/cn/java/j-cobertura/#rate"><B><FONT color=#996699 size=2>帮助我们改进这些内容</FONT></B></A></P></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR></TD></TR></TBODY></TABLE>
<P>级别: 初级</P>
<P><A href="http://www-128.ibm.com/developerworks/cn/java/j-cobertura/#author"><FONT color=#996699>Elliotte Rusty Harold</FONT></A>, 副教授, Polytechnic University<BR></P>
<P>2005 年 5 月 26 日</P>
<BLOCKQUOTE>Cobertura 是一种开源工具，它通过检测基本的代码，并观察在测试包运行时执行了哪些代码和没有执行哪些代码，来测量测试覆盖率。除了找出未测试到的代码并发现 bug 外，Cobertura 还可以通过标记无用的、执行不到的代码来优化代码，还可以提供 API 实际操作的内部信息。Elliotte Rusty Harold 将与您分享如何利用代码覆盖率的最佳实践来使用 Cobertura。</BLOCKQUOTE>
<P>尽管测试先行编程（test-first programming）和单元测试已不能算是新概念，但测试驱动的开发仍然是过去 10 年中最重要的编程创新。最好的一些编程人员在过去半个世纪中一直在使用这些技术，不过，只是在最近几年，这些技术才被广泛地视为在时间及成本预算内开发健壮的无缺陷软件的关键所在。但是，测试驱动的开发不能超过测试所能达到的程度。测试改进了代码质量，但这也只是针对实际测试到的那部分代码而言的。您需要有一个工具告诉您程序的哪些部分没有测试到，这样就可以针对这些部分编写测试代码并找出更多 bug。 </P>
<P>Mark Doliner 的 Cobertura （<I>cobertura</I> 在西班牙语是覆盖的意思）是完成这项任务的一个免费 GPL 工具。Cobertura 通过用额外的语句记录在执行测试包时，哪些行被测试到、哪些行没有被测试到，通过这种方式来度量字节码，以便对测试进行监视。然后它生成一个 HTML 或者 XML 格式的报告，指出代码中的哪些包、哪些类、哪些方法和哪些行没有测试到。可以针对这些特定的区域编写更多的测试代码，以发现所有隐藏的 bug。 </P>
<P><A name=N10074><SPAN class=atitle><FONT face=Arial size=4>阅读 Cobertura 输出</FONT></SPAN></A></P>
<P>我们首先查看生成的 Cobertura 输出。图 1 显示了对 Jaxen 测试包运行 Cobertura 生成的报告（请参阅 <A href="http://www-128.ibm.com/developerworks/cn/java/j-cobertura/#resources"><FONT color=#996699>参考资料</FONT></A>）。从该报告中，可以看到从很好（在 <CODE>org.jaxen.expr.iter</CODE> 包中几乎是 100%）到极差（在 <CODE>org.jaxen.dom.html</CODE> 中完全没有覆盖）的覆盖率结果。</P><BR><A name=N1008B><B>图 1. Jaxen 的包级别覆盖率统计数据</B></A><BR><IMG height=490 alt="" hspace=5 src="http://www-128.ibm.com/developerworks/cn/java/j-cobertura/overview.jpg" width=676 vspace=5 border=0> <BR>
<P>Cobertura 通过被测试的行数和被测试的分支数来计算覆盖率。第一次测试时，两种测试方法之间的差别并不是很重要。Cobertura 还为类计算平均 McCabe 复杂度（请参阅 <A href="http://www-128.ibm.com/developerworks/cn/java/j-cobertura/#resources"><FONT color=#996699>参考资料</FONT></A>）。</P>
<P>可以深入挖掘 HTML 报告，了解特定包或者类的覆盖率。图 2 显示了 <CODE>org.jaxen.function</CODE> 包的覆盖率统计。在这个包中，覆盖率的范围从 <CODE>SumFunction</CODE> 类的 100% 到 <CODE>IdFunction</CODE> 类的仅为 5%。</P><BR><A name=N100B5><B>图 2. org.jaxen.function 包中的代码覆盖率</B></A><BR><IMG height=490 alt="" hspace=5 src="http://www-128.ibm.com/developerworks/cn/java/j-cobertura/package.jpg" width=676 vspace=5 border=0> <BR>
<P>进一步深入到单独的类中，具体查看哪一行代码没有测试到。图 3 显示了 <CODE>NameFunction</CODE> 类中的部分覆盖率。最左边一栏显示行号。后一栏显示了执行测试时这一行被执行的次数。可以看出，第 112 行被执行了 100 次，第 114 行被执行了 28 次。用红色突出显示的那些行则根本没有测试到。这个报告表明，虽然从总体上说该方法被测试到了，但实际上还有许多分支没有测试到。 </P><BR><A name=N100D0><B>图 3. NameFunction 类中的代码覆盖率</B></A><BR><IMG height=590 alt="" hspace=5 src="http://www-128.ibm.com/developerworks/cn/java/j-cobertura/class.jpg" width=676 vspace=5 border=0> <BR>
<TABLE cellSpacing=0 cellPadding=0 width="40%" align=right border=0>
<TBODY>
<TR>
<TD width=10><IMG height=1 alt="" src="http://www.ibm.com/i/c.gif" width=10></TD>
<TD>
<TABLE cellSpacing=0 cellPadding=5 width="100%" border=1>
<TBODY>
<TR>
<TD bgColor=#eeeeee>
<P>Cobertura 是 jcoverage 的分支（请参阅 <A href="http://www-128.ibm.com/developerworks/cn/java/j-cobertura/#resources"><FONT color=#996699>参考资料</FONT></A>）。GPL 版本的 jcoverage 已经有一年没有更新过了，并且有一些长期存在的 bug，Cobertura 修复了这些 bug。原来的那些 jcoverage 开发人员不再继续开发开放源码，他们转向开发 jcoverage 的商业版和 jcoverage+，jcoverage+ 是一个从同一代码基础中发展出来的封闭源代码产品。开放源码的奇妙之处在于：一个产品不会因为原开发人员决定让他们的工作获得相应的报酬而消亡。 </P></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
<P><A name=N100EC><SPAN class=smalltitle><STRONG><FONT face=Arial>确认遗漏的测试</FONT></STRONG></SPAN></A></P>
<P>利用 Cobertura 报告，可以找出代码中未测试的部分并针对它们编写测试。例如，图 3 显示 Jaxen 需要进行一些测试，运用 <CODE>name()</CODE> 函数对文字节点、注释节点、处理指令节点、属性节点和名称空间节点进行测试。 </P>
<P>如果有许多未覆盖的代码，像 Cobertura 在这里报告的那样，那么添加所有缺少的测试将会非常耗时，但也是值得的。不一定要一次完成它。您可以从被测试的最少的代码开始，比如那些所有没有覆盖的包。在测试所有的包之后，就可以对每一个显示为没有覆盖的类编写一些测试代码。对所有类进行专门测试后，还要为所有未覆盖的方法编写测试代码。在测试所有方法之后，就可以开始分析对未测试的语句进行测试的必要性。 </P>
<P><A name=N100FC><SPAN class=smalltitle><STRONG><FONT face=Arial>（几乎）不留下任何未测试的代码</FONT></STRONG></SPAN></A></P>
<P>是否有一些可以测试但不应测试的内容？这取决于您问的是谁。在 JUnit FAQ 中，J. B. Rainsberger 写到“一般的看法是：如果 <I>自身</I> 不会出问题，那么它会因为太简单而不会出问题。第一个例子是 <CODE>getX()</CODE> 方法。假定 <CODE>getX()</CODE> 方法只提供某一实例变量的值。在这种情况下，除非编译器或者解释器出了问题，否则 <CODE>getX()</CODE> 是不会出问题的。因此，不用测试 <CODE>getX()</CODE>，测试它不会带来任何好处。对于 <CODE>setX()</CODE> 方法来说也是如此，不过，如果 <CODE>setX()</CODE> 方法确实要进行任何参数验证，或者说确实有副作用，那么还是有必要对其进行测试。” </P>
<TABLE cellSpacing=0 cellPadding=0 width="40%" align=right border=0>
<TBODY>
<TR>
<TD width=10><IMG height=1 alt="" src="http://www.ibm.com/i/c.gif" width=10></TD>
<TD>
<TABLE cellSpacing=0 cellPadding=5 width="100%" border=1>
<TBODY>
<TR>
<TD bgColor=#eeeeee>
<P>理论上，对未覆盖的代码编写测试代码不一定就会发现 bug。但在实践中，我从来没有碰到没有发现 bug 的情况。未测试的代码充满了 bug。所做的测试越少，在代码中隐藏的、未发现的 bug 就会越多。</P></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
<P>我不同意。我已经记不清在“简单得不会出问题”的代码中发现的 bug 的数量了。确实，一些 getter 和 setter 很简单，不可能出问题。但是我从来就没有办法区分哪些方法是真的简单得不会出错，哪些方法只是看上去如此。编写覆盖像 setter 和 getter 这样简单方法的测试代码并不难。为此所花的少量时间会因为在这些方法中发现未曾预料到的 bug 而得到补偿。 </P>
<P>一般来说，开始测量后，达到 90% 的测试覆盖率是很容易的。将覆盖率提高到 95% 或者更高就需要动一下脑筋。例如，可能需要装载不同版本的支持库，以测试没有在所有版本的库中出现的 bug。或者需要重新构建代码，以便测试通常执行不到的部分代码。可以对类进行扩展，让它们的受保护方法变为公共方法，这样就可以对这些方法进行测试。这些技巧看起来像是多此一举，但是它们曾帮助我在一半的时间内发现更多的未发现的 bug。 </P>
<P>并不总是可以得到完美的、100% 的代码覆盖率。有时您会发现，不管对代码如何改造，仍然有一些行、方法、甚至是整个类是测试不到的。下面是您可能会遇到的挑战的一些例子： </P>
<UL>
<LI>只在特定平台上执行的代码。例如，在一个设计良好的 GUI 应用程序中，添加一个 Exit 菜单项的代码可以在 Windows PC 上运行，但它不能在 Mac 机上运行。<BR><BR>
<LI>捕获不会发生的异常的 <CODE>catch</CODE> 语句，比如在从 <CODE>ByteArrayInputStream</CODE> 进行读取操作时抛出的 <CODE>IOException</CODE>。<BR><BR>
<LI>非公共类中的一些方法，它们永远也不会被实际调用，只是为了满足某个接口契约而必须实现。<BR><BR>
<LI>处理虚拟机 bug 的代码块，比如说，不能识别 UTF-8 编码。 <BR><BR></LI></UL>
<P>考虑到上面这些以及类似的情况，我认为一些极限程序员自动删除所有未测试代码的做法是不切实际的，并且可能具有一定的讽刺性。不能总是获得绝对完美的测试覆盖率并不意味着就不会有更好的覆盖率。 </P>
<P>然而，比执行不到的语句和方法更常见的是残留代码，它不再有任何作用，并且从代码基中去掉这些代码也不会产生任何影响。有时可以通过使用反射来访问私有成员这样的怪招来测试未测试的代码。还可以为未测试的、包保护（package-protected）的代码来编写测试代码，将测试类放到将要测试的类所在那个包中。但最好不要这样做。所有不能通过发布的（公共的和受保护的）接口访问的代码都应删除。执行不到的代码不应当成为代码基的一部分。代码基越小，它就越容易被理解和维护。 </P>
<TABLE cellSpacing=0 cellPadding=0 width="40%" align=right border=0>
<TBODY>
<TR>
<TD width=10><IMG height=1 alt="" src="http://www.ibm.com/i/c.gif" width=10></TD>
<TD>
<TABLE cellSpacing=0 cellPadding=5 width="100%" border=1>
<TBODY>
<TR>
<TD bgColor=#eeeeee>
<P>不要漏掉测量单元测试包和类本身。我不止一次注意到，某些个测试方法或者类没有被测试包真正运行。通常这表明名称规范中存在问题（比如将一个方法命名为 <CODE><I>tes</I>SomeReallyComplexCondition</CODE>，而不是将其命名为 <CODE><I>test</I>SomeReallyComplexCondition</CODE>），或者忘记将一个类添加到主 <CODE>suite()</CODE> 方法中。在其他情况下，未预期的条件导致跳过了测试方法中的代码。不管是什么情况，都是虽然已经编写了测试代码，但没有真正运行它。JUnit 不会告诉您它没有像您所想的那样运行所有测试，但是 Cobertura 会告诉您。找出了未运行的测试后，改正它一般很容易。 </P></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD><IMG height=1 alt="" src="http://www.ibm.com/i/v14/rules/blue_rule.gif" width="100%"></TD></TR></TBODY></TABLE>
<TABLE class=no-print cellSpacing=0 cellPadding=0 align=right>
<TBODY>
<TR align=right>
<TD>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD vAlign=center><IMG height=16 alt="" src="http://www.ibm.com/i/v14/icons/u_bold.gif" width=16 border=0><BR></TD>
<TD vAlign=top align=right><A class=fbox href="http://www-128.ibm.com/developerworks/cn/java/j-cobertura/#main"><B><FONT color=#996699>回页首</FONT></B></A></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR><BR>
<P><A name=N10178><SPAN class=atitle><FONT face=Arial size=4>运行 Cobertura</FONT></SPAN></A></P>
<P>在了解了测量代码覆盖率的好处后，让我们再来讨论一下如何用 Cobertura 测量代码覆盖率的具体细节。Cobertura 被设计成为在 Ant 中运行。现在还没有这方面的 IDE 插件可用，不过一两年内也许就会有了。 </P>
<P>首先需要在 build.xml 文件中添加一个任务定义。以下这个顶级 <CODE>taskdef</CODE> 元素将 cobertura.jar 文件限定在当前工作目录中： </P>
<TABLE cellSpacing=0 cellPadding=5 width="65%" bgColor=#cccccc border=1>
<TBODY>
<TR>
<TD><PRE><CODE class=section><FONT face="Lucida Console">&lt;taskdef classpath="cobertura.jar" resource="tasks.properties" /&gt;</FONT></CODE></PRE></TD></TR></TBODY></TABLE><BR>
<P>然后，需要一个 <CODE>cobertura-instrument</CODE> 任务，该任务将在已经编译好的类文件中添加日志代码。<CODE>todir</CODE> 属性指定将测量类放到什么地方。<CODE>fileset</CODE> 子元素指定测量哪些 .class 文件： </P>
<TABLE cellSpacing=0 cellPadding=5 width="65%" bgColor=#cccccc border=1>
<TBODY>
<TR>
<TD><PRE><CODE class=section><FONT face="Lucida Console">&lt;target name="instrument"&gt;
  &lt;cobertura-instrument todir="target/instrumented-classes"&gt;
    &lt;fileset dir="target/classes"&gt;
      &lt;include name="**/*.class"/&gt;
    &lt;/fileset&gt;
  &lt;/cobertura-instrument&gt;
&lt;/target&gt;</FONT></CODE></PRE></TD></TR></TBODY></TABLE><BR>
<P>用通常运行测试包的同一种类型的 Ant 任务运行测试。惟一的区别在于：被测量的类必须在原始类出现在类路径中之前出现在类路径中，而且需要将 Cobertura JAR 文件添加到类路径中： </P>
<TABLE cellSpacing=0 cellPadding=5 width="100%" bgColor=#eeeeee border=1>
<TBODY>
<TR>
<TD><PRE><CODE class=section><FONT face="Lucida Console">&lt;target name="cover-test" depends="instrument"&gt;
  &lt;mkdir dir="${testreportdir}" /&gt;
  &lt;junit dir="./" failureproperty="test.failure" printSummary="yes" 
         fork="true" haltonerror="true"&gt;
    &lt;!-- Normally you can create this task by copying your existing JUnit
         target, changing its name, and adding these next two lines.
         You may need to change the locations to point to wherever 
         you've put the cobertura.jar file and the instrumented classes. --&gt;
    &lt;classpath location="cobertura.jar"/&gt;
    &lt;classpath location="target/instrumented-classes"/&gt;
    &lt;classpath&gt;
      &lt;fileset dir="${libdir}"&gt;
        &lt;include name="*.jar" /&gt;
      &lt;/fileset&gt;
      &lt;pathelement path="${testclassesdir}" /&gt;
      &lt;pathelement path="${classesdir}" /&gt;
    &lt;/classpath&gt;
    &lt;batchtest todir="${testreportdir}"&gt;
      &lt;fileset dir="src/java/test"&gt;
        &lt;include name="**/*Test.java" /&gt;
        &lt;include name="org/jaxen/javabean/*Test.java" /&gt;
      &lt;/fileset&gt;
    &lt;/batchtest&gt;
  &lt;/junit&gt;
&lt;/target&gt;&gt;</FONT></CODE></PRE></TD></TR></TBODY></TABLE><BR>
<P>Jaxen 项目使用 JUnit 作为其测试框架，但是 Cobertura 是不受框架影响的。它在 TestNG、Artima SuiteRunner、HTTPUni 或者在您自己在地下室开发的系统中一样工作得很好。</P>
<P>最后，<CODE>cobertura-report</CODE> 任务生成本文开始部分看到的那个 HTML 文件： </P>
<TABLE cellSpacing=0 cellPadding=5 width="100%" bgColor=#eeeeee border=1>
<TBODY>
<TR>
<TD><PRE><CODE class=section><FONT face="Lucida Console">&lt;target name="coverage-report" depends="cover-test"&gt;
 &lt;cobertura-report srcdir="src/java/main" destdir="cobertura"/&gt;
&lt;/target&gt;</FONT></CODE></PRE></TD></TR></TBODY></TABLE><BR>
<P><CODE>srcdir</CODE> 属性指定原始的 .java 源代码在什么地方。<CODE>destdir</CODE> 属性指定 Cobertura 放置输出 HTML 的那个目录的名称。</P>
<P>在自己的 Ant 编译文件中加入了类似的任务后，就可以通过键入以下命令来生成一个覆盖报告： </P>
<TABLE cellSpacing=0 cellPadding=5 width="100%" bgColor=#eeeeee border=1>
<TBODY>
<TR>
<TD><PRE><CODE class=section><FONT face="Lucida Console">% ant instrument
% ant cover-test
% ant coverage-report</FONT></CODE></PRE></TD></TR></TBODY></TABLE><BR>
<P>当然，如果您愿意的话，还可以改变目标任务的名称，或者将这三项任务合并为一个目标任务。 </P><BR>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD><IMG height=1 alt="" src="http://www.ibm.com/i/v14/rules/blue_rule.gif" width="100%"></TD></TR></TBODY></TABLE>
<TABLE class=no-print cellSpacing=0 cellPadding=0 align=right>
<TBODY>
<TR align=right>
<TD>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD vAlign=center><IMG height=16 alt="" src="http://www.ibm.com/i/v14/icons/u_bold.gif" width=16 border=0><BR></TD>
<TD vAlign=top align=right><A class=fbox href="http://www-128.ibm.com/developerworks/cn/java/j-cobertura/#main"><B><FONT color=#996699>回页首</FONT></B></A></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR><BR>
<P><A name=N101CE><SPAN class=atitle><FONT face=Arial size=4>结束语</FONT></SPAN></A></P>
<P>Cobertura 是敏捷程序员工具箱中新增的一个重要工具。通过生成代码覆盖率的具体数值，Cobertura 将单元测试从一种艺术转变为一门科学。它可以寻找测试覆盖中的空隙，直接找到 bug。测量代码覆盖率使您可以获得寻找并修复 bug 所需的信息，从而开发出对每个人来说都更健壮的软件。 </P><BR>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD><IMG height=1 alt="" src="http://www.ibm.com/i/v14/rules/blue_rule.gif" width="100%"></TD></TR></TBODY></TABLE>
<TABLE class=no-print cellSpacing=0 cellPadding=0 align=right>
<TBODY>
<TR align=right>
<TD>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD vAlign=center><IMG height=16 alt="" src="http://www.ibm.com/i/v14/icons/u_bold.gif" width=16 border=0><BR></TD>
<TD vAlign=top align=right><A class=fbox href="http://www-128.ibm.com/developerworks/cn/java/j-cobertura/#main"><B><FONT color=#996699>回页首</FONT></B></A></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR><BR>
<P><A name=resources><SPAN class=atitle><FONT face=Arial size=4>参考资料 </FONT></SPAN></A></P>
<UL>
<LI>您可以参阅本文在 developerWorks 全球站点上的 <A href="http://www-128.ibm.com/developerworks/java/library/j-cobertura/" target=_blank><FONT color=#5c81a7>英文原文</FONT></A>。<BR><BR>
<LI>从 SourceForge 下载 <A href="http://cobertura.sourceforge.net/"><FONT color=#5c81a7>Cobertura</FONT></A>。<BR><BR>
<LI>获得 <A href="http://www.junit.org/"><FONT color=#5c81a7>JUnit</FONT></A> <A href="http://junit.sourceforge.net/doc/testinfected/testing.htm"><FONT color=#5c81a7>受影响的测试</FONT></A>，它是用于 Java 平台的实际标准单元测试框架。<BR><BR>
<LI>阅读 Dave Thomas 和 Andy Hunt 合著的 <A href="http://devworks.krcinfo.com/WebForms/ProductDetails.aspx?ProductID=0974514012"><FONT color=#5c81a7><I>Pragmatic Unit Testing in Java With JUnit</I> </FONT></A>（Pragmatic Bookshelf，2003）。<BR><BR>
<LI>Cenqua 的 <A href="http://www.cenqua.com/clover/"><FONT color=#5c81a7>Clover</FONT></A> 是一个更精致的、收费的测试覆盖率工具，它所做的工作实质上与 Cobertura 相同，只是它做得更细致一些。<BR><BR>
<LI>IBM Rational 提供了全面的测试工具包来帮助您检测代码。“<A href="http://www-128.ibm.com/developerworks/rational/library/274.html"><FONT color=#5c81a7>Get started with automated testing: Road map to success</FONT></A>”为您提供了即刻开始测试自己的代码所需的基础知识。 <BR><BR>
<LI>Mike Kelly 提供了“<A href="http://www.ibm.com/developerworks/rational/library/568.html"><FONT color=#5c81a7>using TestManager to report test coverage</FONT></A>”的细节（developerWorks，2003 年 12 月）。<BR><BR>
<LI><A href="http://www.ibm.com/developerworks/rational/products/purifyplus"><FONT color=#5c81a7>PureCoverage</FONT></A> 是 IBM Rational PurifyPlus 测试工具包的一部分，它是一个出色的代码覆盖率工具。Rational Application Developor 包括 PureCoverage 功能，从“<A href="http://www-128.ibm.com/developerworks/cn/rational/kelly-stoker/"><FONT color=#5c81a7>使用 IBM Rational Application Developer for WebSphere Software 进行组件测试</FONT></A>”中可以了解关于它的更多知识（developerWorks，2005 年 3 月）。<BR><BR>
<LI>Cobertura 是 <A href="http://www.jcoverage.com/"><FONT color=#5c81a7>jcoverage</FONT></A> 的分支。 <BR><BR>
<LI>Carnegie Mellon 的 Software Engineering Institute 发表了对 <A href="http://www.sei.cmu.edu/str/descriptions/cyclomatic_body.html"><FONT color=#5c81a7>McCabe's Cyclomatic Complexity</FONT></A> 的详细说明。<BR><BR>
<LI>David Carew 和 Sandeep Desai 合著的 “<A href="http://www.ibm.com/developerworks/edu/i-dw-wes-junit-i.html?S_TACT=105AGX02"><FONT color=#5c81a7>Keeping critters out of your code: How to use WebSphere and JUnit to prevent programming bugs</FONT></A>”（developerWorks，2003 年 6 月） 分析了如何用 XP 方法进行测试。<BR><BR>
<LI>Dennis M. Sosnoski <A href="http://www-128.ibm.com/developerworks/cn/java/j-cwt02095/"><FONT color=#5c81a7>推出</FONT></A> 了 <A href="http://www-128.ibm.com/developerworks/cn/views/java/articles.jsp?view_by=search&amp;search_by=Classworking+%E5%B7%A5%E5%85%B7%E7%AE%B1%3A"><FONT color=#5c81a7>Classworking 工具箱</FONT></A> 系列，探讨开源的 <A href="http://hansel.sourceforge.net/"><FONT color=#5c81a7>Hansel</FONT></A> 和 <A href="http://www.cs.uoregon.edu/research/perpetual/dasada/Software/Gretel/"><FONT color=#5c81a7>Gretel</FONT></A> 代码覆盖率工具。<BR><BR>
<LI>参阅“<A href="http://www-106.ibm.com/developerworks/java/library/j-jester/"><FONT color=#5c81a7>Test your tests with Jester</FONT></A>”，了解关于开放源代码 JUnit 测试测试器的知识。<BR><BR>
<LI>Malcolm Davis 撰写的“<A href="http://www-128.ibm.com/developerworks/cn/java/j-ant/"><FONT color=#5c81a7>利用 Ant 和 JUnit 进行增量开发</FONT></A>”（developerWorks，2000 年 11 月）介绍了如何将 JUnit 集成到自己的项目中。<BR><BR>
<LI>Eric Allen 和 Roy Miller 在他们各自的专栏 <A href="http://www-128.ibm.com/developerworks/cn/views/java/articles.jsp?view_by=search&amp;search_by=%E8%AF%8A%E6%96%AD+Java+%E4%BB%A3%E7%A0%81%EF%BC%9A"><FONT color=#5c81a7>诊断 Java 代码</FONT></A> 和 <A href="http://www-106.ibm.com/developerworks/java/library/j-xpcol.html"><FONT color=#5c81a7>Demystifying Extreme Programming</FONT></A> 中经常讨论到单元测试。<BR><BR>
<LI>Erik Hatcher 的 <A href="http://www-128.ibm.com/developerworks/cn/java/j-junitmail/"><FONT color=#5c81a7>让编译和测试过程自动化</FONT></A> （developerWorks，2001 年 8 月）展示了如何将增量测试和连续编译结合到一个自动过程中。<BR><BR>
<LI>探索 <A href="http://alphaworks.ibm.com/tech/focus"><FONT color=#5c81a7>FoCuS</FONT></A>，这是 IBM alphaWorks 的一个工具，它实现了功能覆盖方法，并通过提供未测试区域的详细覆盖率信息来改进应用程序测试。<BR><BR>
<LI>作为本文分析对象的 <A href="http://jaxen.codehaus.org/"><FONT color=#5c81a7>Jaxen 项目</FONT></A> 是一个用于 Java 编程的开源 XPath 引擎，适合多种不同对象模型。 <BR><BR>
<LI>在 developerWorks 的 <A href="http://www.ibm.com/developerworks/cn/java/"><FONT color=#5c81a7>Java 技术专区</FONT></A> 中可以找到关于 Java 编程的各个方面的文章。<BR><BR>
<LI>请参阅 <A href="http://devworks.krcinfo.com/"><FONT color=#5c81a7>Developer Bookstore</FONT></A>，以获得一些技术书籍的完整清单，其中包括数百本 <A href="http://devworks.krcinfo.com/WebForms/ProductList.aspx?Search=Category&amp;id=1200"><FONT color=#5c81a7>Java 相关主题</FONT></A> 的书籍。<BR></LI></UL><BR>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD><IMG height=1 alt="" src="http://www.ibm.com/i/v14/rules/blue_rule.gif" width="100%"></TD></TR></TBODY></TABLE>
<TABLE class=no-print cellSpacing=0 cellPadding=0 align=right>
<TBODY>
<TR align=right>
<TD>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD vAlign=center><IMG height=16 alt="" src="http://www.ibm.com/i/v14/icons/u_bold.gif" width=16 border=0><BR></TD>
<TD vAlign=top align=right><A class=fbox href="http://www-128.ibm.com/developerworks/cn/java/j-cobertura/#main"><B><FONT color=#996699>回页首</FONT></B></A></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR><BR>
<P><A name=author><SPAN class=atitle><FONT face=Arial size=4>关于作者</FONT></SPAN></A></P>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD colSpan=2><FONT face=Arial size=4><IMG height=5 alt="" src="http://www.ibm.com/i/c.gif" width="100%"></FONT></TD></TR>
<TR vAlign=top align=left>
<TD>
<P><FONT face=Arial size=4></FONT></P></TD>
<TD>
<P>Elliotte Rusty Harold 出生在新奥尔良，现在他还定期回老家喝一碗美味的秋葵汤。不过目前，他和妻子 Beth 定居在纽约临近布鲁克林的 Prospect Heights，同住的还有他的猫咪 Charm（取自夸克）和 Marjorie（取自他岳母的名字）。他是 Polytechnic 大学计算机科学的副教授，讲授 Java 技术和面向对象编程。他的 <A href="http://www.cafeaulait.org/"><FONT color=#5c81a7>Cafe au Lait</FONT></A> 网站是 Internet 上最受欢迎的独立 Java 站点之一，姊妹站点 <A href="http://www.cafeconleche.org/"><FONT color=#5c81a7>Cafe con Leche</FONT></A> 已经成为最受欢迎的 XML 站点之一。他的著作包括 <A href="http://devworks.krcinfo.com/WebForms/ProductDetails.aspx?ProductID=0321150406"><FONT color=#5c81a7><I>Effective XML</I> </FONT></A>、<A href="http://devworks.krcinfo.com/WebForms/ProductDetails.aspx?ProductID=0201771861"><FONT color=#5c81a7> <I>Processing XML with Java</I> </FONT></A>、<A href="http://devworks.krcinfo.com/WebForms/ProductDetails.aspx?ProductID=1565928709"><FONT color=#5c81a7> <I>Java Network Programming</I> </FONT></A>和 <A href="http://www.cafeconleche.org/books/bible3/"><FONT color=#5c81a7><I>The XML 1.1 Bible</I> </FONT></A>。目前他正在从事 XML 的 <A href="http://www.xom.nu/"><FONT color=#5c81a7>XOM</FONT></A> API、<A href="http://jaxen.codehaus.org/"><FONT color=#5c81a7>Jaxen</FONT></A> XPath 引擎和 <A href="http://jester.sourceforge.net/"><FONT color=#5c81a7>Jester</FONT></A> 测试覆盖率工具的开发工作。 </P></TD></TR></TBODY></TABLE><BR></TD></TR></TBODY></TABLE><img src ="http://www.blogjava.net/ghawk/aggbug/24331.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/ghawk/" target="_blank">GHawk</a> 2005-12-17 11:23 <a href="http://www.blogjava.net/ghawk/archive/2005/12/17/24331.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>EasyMock 2.0_ReleaseCandidate 文档翻译</title><link>http://www.blogjava.net/ghawk/archive/2005/12/15/24060.html</link><dc:creator>GHawk</dc:creator><author>GHawk</author><pubDate>Thu, 15 Dec 2005 08:06:00 GMT</pubDate><guid>http://www.blogjava.net/ghawk/archive/2005/12/15/24060.html</guid><wfw:comment>http://www.blogjava.net/ghawk/comments/24060.html</wfw:comment><comments>http://www.blogjava.net/ghawk/archive/2005/12/15/24060.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/ghawk/comments/commentRss/24060.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/ghawk/services/trackbacks/24060.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: EasyMock 2.0_ReleaseCandidate ReadmeDocumentation for release 2.0_ReleaseCandidate (October 15 2005)© 2001-2005 OFFIS, Tammo Freese. 翻译：GHawk, 2005-12-15EasyMock 2 is a library that provides an ...&nbsp;&nbsp;<a href='http://www.blogjava.net/ghawk/archive/2005/12/15/24060.html'>阅读全文</a><img src ="http://www.blogjava.net/ghawk/aggbug/24060.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/ghawk/" target="_blank">GHawk</a> 2005-12-15 16:06 <a href="http://www.blogjava.net/ghawk/archive/2005/12/15/24060.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>