﻿<?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-aldream-文章分类-测试</title><link>http://www.blogjava.net/aldreamlau/category/27258.html</link><description>me</description><language>zh-cn</language><lastBuildDate>Mon, 12 Nov 2007 17:37:00 GMT</lastBuildDate><pubDate>Mon, 12 Nov 2007 17:37:00 GMT</pubDate><ttl>60</ttl><item><title>在eclipse调试JSP和java程序</title><link>http://www.blogjava.net/aldreamlau/articles/159969.html</link><dc:creator>aldream</dc:creator><author>aldream</author><pubDate>Mon, 12 Nov 2007 06:53:00 GMT</pubDate><guid>http://www.blogjava.net/aldreamlau/articles/159969.html</guid><wfw:comment>http://www.blogjava.net/aldreamlau/comments/159969.html</wfw:comment><comments>http://www.blogjava.net/aldreamlau/articles/159969.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/aldreamlau/comments/commentRss/159969.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/aldreamlau/services/trackbacks/159969.html</trackback:ping><description><![CDATA[<span style="font-size: 10pt;">原文出处：<a href="http://www.laliluna.de/assets/tutorials/debugging-jsp-java-tutorial-en.pdf">http://www.laliluna.de/assets/tutorials/debugging-jsp-java-tutorial-en.pdf</a><br />
</span><br />
<p>This tutorial gives you an overview of how
to use the debugging feature of eclipse to debug  your web or Java
projects.</p>
<h1>General</h1>
<p><strong>Author</strong>:
</p>
<p>Sascha
Wolski</p>
<p>Sebastian
Hennebrueder</p>
<p><a href="http://www.laliluna.de/tutorial.html">http://www.laliluna.de/tutorial.html</a>
? Tutorials for  Struts, JSF, EJB, Hibernate, xdoclet, eclipse and
more.</p>
<p><strong>Datum</strong>:
</p>
<p>January, 25 2005<br />
<strong>Development
Tools</strong></p>
<p>Eclipse
3.x
</p>
<p>MyEclipse
plugin 3.8
</p>
<p>(A
cheap and quite powerful Extension to Eclipse to develop Web
Applications and EJB (J2EE) Applications. I think that there is a
test version availalable at MyEclipse.)</p>
<p><br />
</p>
<p><strong>PDF
Version des Tutorials</strong></p>
<p><a href="http://www.laliluna.de/assets/tutorials/debugging-jsp-java-tutorial-en.pdf">http://www.laliluna.de/assets/tutorials/debugging-jsp-java-tutorial-en.pdf</a></p>
<h1>Introduction</h1>
<p>The Eclipse Platform features a Java
debugger that provides all standard debugging functionality,
including the ability to perform step execution, setting of
breakpoints and values, inspecting variables and values, and to
suspend and resume threads. With the extension MyEclipse you are
able to debug JSP and included files too.
</p>
<p><br />
<br />
</p>
<h1>The debug perspective</h1>
<p>First we will explain the debug perspective.
You can activate the perspective under <strong>Windows &gt; Open
Perspective &gt; Other...</strong>
</p>
<p><img src="http://www.laliluna.de/assets/images/tutorials/debugging-jsp-java-tutorial/select-perspective.gif" name="Graphic1" alt="" align="left" border="0" height="249" width="244" /><br clear="left" />
<br />
<br />
</p>
<p>Alternatively, you can click on the debug
icon of the perspective tool bar.</p>
<p><img src="http://www.laliluna.de/assets/images/tutorials/debugging-jsp-java-tutorial/select-perspective-toolbar.gif" name="Graphic2" alt="" align="left" border="0" height="33" width="220" /><br clear="left" />
<br />
<br />
</p>
<h2>Debug view</h2>
<p>The Debug view displays the stack trace for
the suspended threads for each target you are debugging. Each entry
is the variable state of a method right when it called the next
method. The view allows you to manage the debugging of a program in
the workbench.</p>
<p><img src="http://www.laliluna.de/assets/images/tutorials/debugging-jsp-java-tutorial/window-debug.gif" name="Graphic3" alt="" align="left" border="0" height="303" width="474" /><br clear="left" />
<br />
<br />
</p>
<h2>Variables view</h2>
<p>The view displays information about the
variables in the selected class. You can get information about the
variable like value, size and more from this view.</p>
<p><img src="http://www.laliluna.de/assets/images/tutorials/debugging-jsp-java-tutorial/window-variable.gif" name="Graphic4" alt="" align="left" border="0" height="297" width="400" /><br clear="left" />
<br />
<br />
</p>
<h2 style="page-break-before: always;">Breakpoints
view</h2>
<p>The view lists all breakpoints you have set
in the workbench project. In this view, you can enable or disable
breakpoints, remove them, or add a new ones. You can also
double-click a breakpoint to display its location in the editor.</p>
<p>This view also lists Java exception breakpoints,
which suspend execution at the point where the exception is thrown.
You can add or remove exceptions.
</p>
<p><br />
<br />
</p>
<p><img src="http://www.laliluna.de/assets/images/tutorials/debugging-jsp-java-tutorial/window-breakpoints.gif" name="Graphic5" alt="" align="left" border="0" height="131" width="410" /><br clear="left" />
<br />
<br />
</p>
<h2>Expressions view</h2>
<p>You can inspect data from each class of a
suspended thread, and other places in this view. It opens
automatically when an item is added to the view.</p>
<p><img src="http://www.laliluna.de/assets/images/tutorials/debugging-jsp-java-tutorial/window-expressions.gif" name="Graphic6" alt="" align="left" border="0" height="247" width="404" /><br clear="left" />
<br />
<br />
</p>
<h1>Debug a web project</h1>
<p>In the next steps I will explain how you can
debug a project. I will refer to the project JSP + Servlet you can
download on our site.
<a href="http://www.laliluna.de/assets/tutorials/java-servlets-jsp-tutorial.zip">http://www.laliluna.de/assets/tutorials/java-servlets-jsp-tutorial.zip</a>
</p>
<p>Open the class <strong>BookEdit.java</strong> and set
a breakpoint in the method <strong>doGet(..)</strong> at line 72. You can set a
breakpoint by double-click on the info bar on the left edge of the
editor, or right click <strong>Toggle Breakpoint</strong>.</p>
<p><img src="http://www.laliluna.de/assets/images/tutorials/debugging-jsp-java-tutorial/set-breakpoint-java.gif" name="Graphic7" alt="" align="left" border="0" height="157" width="584" /><br clear="left" />
<br />
<br />
</p>
<p>Set the second breakpoint in the
<strong>bookEdit.jsp</strong> file on the HTML start tag at line 14.</p>
<p><strong>Note</strong>: If you don't have installed
MyEclipse, you can't set a breakpoint in jsp and included files.</p>
<p><img src="http://www.laliluna.de/assets/images/tutorials/debugging-jsp-java-tutorial/set-breakpoint-jsp.gif" name="Graphic8" alt="" align="left" border="0" height="203" width="488" /><br clear="left" />
<br />
<br />
</p>
<p>To see all breakpoints you can use the
Breakpoints view in the debug perspective.
</p>
<h2>Breakpoint Properties</h2>
<p>You can apply some properties to each
breakpoint, for example how many times a breakpoint can hit before it
suspends the thread or on which condition it suspends the thread.</p>
<p>Select the breakpoint right mouse button and
choose the option <strong>Breakpoint Properties</strong>.</p>
<p><img src="http://www.laliluna.de/assets/images/tutorials/debugging-jsp-java-tutorial/debug-breakpoint-properties-open.gif" name="Graphic21" alt="" align="left" border="0" height="100" width="216" /><br clear="left" />
<br />
<br />
</p>
<p><img src="http://www.laliluna.de/assets/images/tutorials/debugging-jsp-java-tutorial/debug-breakpoint-properties.gif" name="Graphic20" alt="" align="left" border="0" height="469" width="552" /><br clear="left" />
<br />
<br />
</p>
<h3><br />
<br />
</h3>
<h3>Hit Count</h3>
<p>The hit count sets a number of times the
breakpoint can be executed before the thread suspends. Very helpful
in a loop expression or if you want to know the value of a expression
after some hits.</p>
<h3>Enable Condition</h3>
<p>There are two options to suspend a thread by
using a condition.
</p>
<ul>
    <li>
    <p>if the enabled condition is true</p>
    </li>
    <li>
    <p>if the enabled condition changes</p>
    </li>
</ul>
<p>If you want that the condition suspends the
thread when it is true select the option <strong>condition is true</strong> on
<strong>Suspend when</strong>.</p>
<p>Example:</p>
<pre>action.equals("edit");</pre>
<p>
<br />
<br />
</p>
<p>If you want that the condition suspends the
thread when the value of the condition changes select the option
<strong>value of the condition </strong><span>changes
on </span><strong>Suspend when</strong><span style="font-style: normal;">.</span></p>
<p><br />
<br />
</p>
<h3><br />
<br />
</h3>
<h3 style="page-break-before: always;">Suspend Policy</h3>
<p>You can define if the breakpoint suspends
only the thread or the complete virtual machine.</p>
<h2>Deploy and Debug</h2>
<p>Now we want to debug the project, so deploy
it and call it in your web browser. <br />
Choose <strong>Edit</strong> on the
list of books.</p>
<p><img src="http://www.laliluna.de/assets/images/tutorials/debugging-jsp-java-tutorial/edit-book.gif" name="Graphic9" alt="" align="left" border="0" height="228" width="456" /><br clear="left" />
<br />
<br />
</p>
<p>After you clicked the <strong>Edit</strong> link,
eclipse shows you the following confirm window.  You can choose if
you want to switch to the debug perspective. Yes, you want it<strong> ;- )</strong></p>
<p><img src="http://www.laliluna.de/assets/images/tutorials/debugging-jsp-java-tutorial/switch-to-debug-perspective.gif" name="Graphic10" alt="" align="left" border="0" height="191" width="457" /><br clear="left" />
<br />
<br />
</p>
<p style="page-break-before: always;">The first
entry in the debug view represents the state of the method where the
breakpoint was set. You can preview the state of a entry simply by
clicking on it, also the file will be open where the method is
placed.</p>
<p><img src="http://www.laliluna.de/assets/images/tutorials/debugging-jsp-java-tutorial/debug-view-current-frame.gif" name="Graphic11" alt="" align="left" border="0" height="162" width="435" /><br clear="left" />
<br />
<br />
</p>
<p>You can see the values of all variables of
the selected entry in the Variables view.</p>
<p><img src="http://www.laliluna.de/assets/images/tutorials/debugging-jsp-java-tutorial/debug-variables-view.gif" name="Graphic17" alt="" align="left" border="0" height="256" width="391" /><br clear="left" />
<br />
<br />
</p>
<p>A marked line and an arrow at the breakpoint
shows that the debugger is suspended on this line.</p>
<p><img src="http://www.laliluna.de/assets/images/tutorials/debugging-jsp-java-tutorial/debug-editor.gif" name="Graphic12" alt="" align="left" border="0" height="183" width="355" /><br clear="left" />
<br />
<br />
</p>
<p>If you've decided that you missed an
important place in the execution process, perhaps the breakpoint was
in the wrong place, or maybe you accidentally stepped over some code
you wanted to inspect earlier in the process. Eclipse has a feature
called <strong>Drop to frame</strong><span>, that
essentially lets you 'rewind' the execution to the beginning of any
method in the stack. This is especially useful when you perform
variable modification or code hot swapping.<br />
Right click on the
frame and choose the option </span><strong>Drop to Frame</strong>.</p>
<p><br />
<br />
</p>
<h2><br />
<br />
</h2>
<h2 style="page-break-before: always;">Inspect
expressions</h2>
<p>To get informations about expression, you
can inspect a expression. Right click on the marked expression, you
want to inspect and choose <strong>Inspect</strong><span>
or press </span><strong>Ctrl + Shift + I</strong><span>.
A pop-up window appears that holds the informations about the
expression. </span>
</p>
<p><img src="http://www.laliluna.de/assets/images/tutorials/debugging-jsp-java-tutorial/debug-inspect.gif" name="Graphic13" alt="" align="left" border="0" height="207" width="389" /><br clear="left" />
<br />
<br />
</p>
<h2><br />
<br />
</h2>
<h2>Watch expressions</h2>
<p>Watch is similar to inspect an expression.
Watch means that the expression will be added to the Expressions
view, where you can watch the informations about the expression. Add
two expressions to the Expressions view.
</p>
<p>Mark the expressions, right click and choose
<strong>Watch</strong>.</p>
<p><img src="http://www.laliluna.de/assets/images/tutorials/debugging-jsp-java-tutorial/debug-watch.gif" name="Graphic14" alt="" align="left" border="0" height="179" width="537" /><br clear="left" />
<br />
<br />
</p>
<p>Now the two expression are in the
Expressions view.</p>
<p><img src="http://www.laliluna.de/assets/images/tutorials/debugging-jsp-java-tutorial/debug-expression-view.gif" name="Graphic15" alt="" align="left" border="0" height="158" width="428" /><br clear="left" />
<br />
<br />
</p>
<h2><br />
<br />
</h2>
<h2 style="page-break-before: always;">Display
expressions</h2>
<p>If you want to display the type and the
value of an expression, mark the expression and choose  the <strong>Display</strong>
option from the context menu (right mouse button) or press <strong>Ctrl +
Shift + D</strong>.
</p>
<h2><img src="http://www.laliluna.de/assets/images/tutorials/debugging-jsp-java-tutorial/debug-display.gif" name="Graphic16" alt="" align="left" border="0" height="127" width="275" /><br clear="left" />
Run
to Line</h2>
<p>If you set a breakpoint and somewhere under
the breakpoint is a line you want to go, you can use the option <strong>Run
to Line</strong>. The code between the breakpoint and the selected line
will be executed. Select the line you want to go, press the right
mouse button and choose  the option <strong>Run to Line</strong><span>
or use the key binding </span><strong>Ctrl + R</strong>.</p>
<h2><img src="http://www.laliluna.de/assets/images/tutorials/debugging-jsp-java-tutorial/debug-run-to-line.gif" name="Graphic18" alt="" align="left" border="0" height="302" width="636" /><br clear="left" />
Debugging
JSP files (supported by MyEclipse)</h2>
<p><img src="http://www.laliluna.de/assets/images/tutorials/debugging-jsp-java-tutorial/debug-jsp-variable-view.gif" name="Graphic19" alt="" align="left" border="0" height="208" width="384" /><br clear="left" />
Debugging
a JSP file is the same like debugging a Java class, but the most
features (Watch, Inspect, etc) are not implemented. The only way to
get the values of variables is the Variables view.</p>
<p><br />
<br />
</p>
<p>That's it. You will only need to debug, when
you make mistakes. Avoid them and forget the tutorial.</p>
<br />
<img src ="http://www.blogjava.net/aldreamlau/aggbug/159969.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/aldreamlau/" target="_blank">aldream</a> 2007-11-12 14:53 <a href="http://www.blogjava.net/aldreamlau/articles/159969.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>一个Junit例子(转自caterpillar.onlyfun.net)</title><link>http://www.blogjava.net/aldreamlau/articles/159653.html</link><dc:creator>aldream</dc:creator><author>aldream</author><pubDate>Sat, 10 Nov 2007 16:55:00 GMT</pubDate><guid>http://www.blogjava.net/aldreamlau/articles/159653.html</guid><wfw:comment>http://www.blogjava.net/aldreamlau/comments/159653.html</wfw:comment><comments>http://www.blogjava.net/aldreamlau/articles/159653.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/aldreamlau/comments/commentRss/159653.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/aldreamlau/services/trackbacks/159653.html</trackback:ping><description><![CDATA[使用JUnit時，您主要都是透過繼承TestCase類別來撰寫測試案例，預設上您可以使用testXXX() 名稱來撰寫單元測試。<br />
<br />
在測試一個單元方法時，有時您會需要給它一些物件作為運行時的資料，例如您撰寫下面這個測試案例：<br />
<br />
MaxMinTest.java<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 128, 128);">&nbsp;1</span>&nbsp;<span style="color: rgb(0, 0, 255);">package</span><span style="color: rgb(0, 0, 0);">&nbsp;onlyfun.caterpillar.test;<br />
</span><span style="color: rgb(0, 128, 128);">&nbsp;2</span>&nbsp;<span style="color: rgb(0, 0, 0);"><br />
</span><span style="color: rgb(0, 128, 128);">&nbsp;3</span>&nbsp;<span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);">&nbsp;onlyfun.caterpillar.MaxMinTool;<br />
</span><span style="color: rgb(0, 128, 128);">&nbsp;4</span>&nbsp;<span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);">&nbsp;junit.framework.TestCase;<br />
</span><span style="color: rgb(0, 128, 128);">&nbsp;5</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;<br />
</span><span style="color: rgb(0, 128, 128);">&nbsp;6</span>&nbsp;<span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">&nbsp;MaxMinTest&nbsp;</span><span style="color: rgb(0, 0, 255);">extends</span><span style="color: rgb(0, 0, 0);">&nbsp;TestCase&nbsp;{<br />
</span><span style="color: rgb(0, 128, 128);">&nbsp;7</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);">&nbsp;testMax()&nbsp;{<br />
</span><span style="color: rgb(0, 128, 128);">&nbsp;8</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">[]&nbsp;arr&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;{</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">5</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">4</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">3</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">2</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(0, 0, 0);">2</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(0, 0, 0);">3</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(0, 0, 0);">4</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(0, 0, 0);">5</span><span style="color: rgb(0, 0, 0);">};<br />
</span><span style="color: rgb(0, 128, 128);">&nbsp;9</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;assertEquals(</span><span style="color: rgb(0, 0, 0);">5</span><span style="color: rgb(0, 0, 0);">,&nbsp;MaxMinTool.getMax(arr));<br />
</span><span style="color: rgb(0, 128, 128);">10</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;}<br />
</span><span style="color: rgb(0, 128, 128);">11</span>&nbsp;<span style="color: rgb(0, 0, 0);"><br />
</span><span style="color: rgb(0, 128, 128);">12</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);">&nbsp;testMin()&nbsp;{<br />
</span><span style="color: rgb(0, 128, 128);">13</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">[]&nbsp;arr&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;{</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">5</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">4</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">3</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">2</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(0, 0, 0);">2</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(0, 0, 0);">3</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(0, 0, 0);">4</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(0, 0, 0);">5</span><span style="color: rgb(0, 0, 0);">};<br />
</span><span style="color: rgb(0, 128, 128);">14</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;assertEquals(</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">5</span><span style="color: rgb(0, 0, 0);">,&nbsp;MaxMinTool.getMin(arr));<br />
</span><span style="color: rgb(0, 128, 128);">15</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;}<br />
</span><span style="color: rgb(0, 128, 128);">16</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;<br />
</span><span style="color: rgb(0, 128, 128);">17</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);">&nbsp;main(String[]&nbsp;args)&nbsp;{<br />
</span><span style="color: rgb(0, 128, 128);">18</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;junit.swingui.TestRunner.run(MaxMinTest.</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">);<br />
</span><span style="color: rgb(0, 128, 128);">19</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;}<br />
</span><span style="color: rgb(0, 128, 128);">20</span>&nbsp;<span style="color: rgb(0, 0, 0);">}</span></div>
<br />
您將設計的MaxMinTool包括靜態方法getMax()與getMin()，當您給它一個整數陣列，它們將個別傳回陣列中的最大值與最小值，顯然
的，您所準備的陣列重複出現在兩個單元測試之中，重複的程式碼在設計中可以減少就儘量減少，在這兩個單元測試中，整數陣列的準備是單元方法所需要的資源，
我們稱之為fixture，也就是一個測試時所需要的資源集合。<br />
<br />
fixture必須與上下文（Context）無關，也就是與程式執行前後無關，這樣才符合單元測試的意涵，為此，通常將所需的fixture撰寫在單元方法之中，如此在單元測試開始時創建fixture，並於結束後銷毀fixture。<br />
<br />
然而對於重複出現在各個單元測試中的fixture，您可以集中加以管理，您可以在繼承TestCase之後，重新定義<span style="font-weight: bold;">setUp()</span>與<span style="font-weight: bold;">tearDown()</span>方法，將數個單元測試所需要的fixture在setUp()中創建，並在tearDown()中銷毀，例如：<br />
<br />
MaxMinTest.java<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 128, 128);">&nbsp;1</span>&nbsp;<span style="color: rgb(0, 0, 255);">package</span><span style="color: rgb(0, 0, 0);">&nbsp;onlyfun.caterpillar.test;<br />
</span><span style="color: rgb(0, 128, 128);">&nbsp;2</span>&nbsp;<span style="color: rgb(0, 0, 0);"><br />
</span><span style="color: rgb(0, 128, 128);">&nbsp;3</span>&nbsp;<span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);">&nbsp;onlyfun.caterpillar.MaxMinTool;<br />
</span><span style="color: rgb(0, 128, 128);">&nbsp;4</span>&nbsp;<span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);">&nbsp;junit.framework.TestCase;<br />
</span><span style="color: rgb(0, 128, 128);">&nbsp;5</span>&nbsp;<span style="color: rgb(0, 0, 0);"><br />
</span><span style="color: rgb(0, 128, 128);">&nbsp;6</span>&nbsp;<span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">&nbsp;MaxMinTest&nbsp;</span><span style="color: rgb(0, 0, 255);">extends</span><span style="color: rgb(0, 0, 0);">&nbsp;TestCase&nbsp;{<br />
</span><span style="color: rgb(0, 128, 128);">&nbsp;7</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">[]&nbsp;arr;<br />
</span><span style="color: rgb(0, 128, 128);">&nbsp;8</span>&nbsp;<span style="color: rgb(0, 0, 0);"><br />
</span><span style="color: rgb(0, 128, 128);">&nbsp;9</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">protected</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);">&nbsp;setUp()&nbsp;</span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);">&nbsp;Exception&nbsp;{<br />
</span><span style="color: rgb(0, 128, 128);">10</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">super</span><span style="color: rgb(0, 0, 0);">.setUp();<br />
</span><span style="color: rgb(0, 128, 128);">11</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;arr&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">[]{</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">5</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">4</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">3</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">2</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(0, 0, 0);">2</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(0, 0, 0);">3</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(0, 0, 0);">4</span><span style="color: rgb(0, 0, 0);">,&nbsp;</span><span style="color: rgb(0, 0, 0);">5</span><span style="color: rgb(0, 0, 0);">};<br />
</span><span style="color: rgb(0, 128, 128);">12</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;}<br />
</span><span style="color: rgb(0, 128, 128);">13</span>&nbsp;<span style="color: rgb(0, 0, 0);"><br />
</span><span style="color: rgb(0, 128, 128);">14</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">protected</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);">&nbsp;tearDown()&nbsp;</span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);">&nbsp;Exception&nbsp;{<br />
</span><span style="color: rgb(0, 128, 128);">15</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">super</span><span style="color: rgb(0, 0, 0);">.tearDown();<br />
</span><span style="color: rgb(0, 128, 128);">16</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;arr&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">;<br />
</span><span style="color: rgb(0, 128, 128);">17</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;}<br />
</span><span style="color: rgb(0, 128, 128);">18</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;<br />
</span><span style="color: rgb(0, 128, 128);">19</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);">&nbsp;testMax()&nbsp;{<br />
</span><span style="color: rgb(0, 128, 128);">20</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;assertEquals(</span><span style="color: rgb(0, 0, 0);">5</span><span style="color: rgb(0, 0, 0);">,&nbsp;MaxMinTool.getMax(arr));<br />
</span><span style="color: rgb(0, 128, 128);">21</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;}<br />
</span><span style="color: rgb(0, 128, 128);">22</span>&nbsp;<span style="color: rgb(0, 0, 0);"><br />
</span><span style="color: rgb(0, 128, 128);">23</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);">&nbsp;testMin()&nbsp;{<br />
</span><span style="color: rgb(0, 128, 128);">24</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;assertEquals(</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">5</span><span style="color: rgb(0, 0, 0);">,&nbsp;MaxMinTool.getMin(arr));<br />
</span><span style="color: rgb(0, 128, 128);">25</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;}<br />
</span><span style="color: rgb(0, 128, 128);">26</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;<br />
</span><span style="color: rgb(0, 128, 128);">27</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);">&nbsp;main(String[]&nbsp;args)&nbsp;{<br />
</span><span style="color: rgb(0, 128, 128);">28</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;junit.swingui.TestRunner.run(MaxMinTest.</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">);<br />
</span><span style="color: rgb(0, 128, 128);">29</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;}<br />
</span><span style="color: rgb(0, 128, 128);">30</span>&nbsp;<span style="color: rgb(0, 0, 0);">}</span></div>
<br />
setUp()方法會在每一個單元測試testXXX()方法開始前被呼叫，因而整數陣列會被建立，而tearDown()會在每一個單元測試
testXXX()方法結束後被呼叫，因而整數陣列參考名稱將會參考至null，如此一來，您可以將fixture的管理集中在
setUp()與tearDown()方法之後。<br />
<br />
最後按照測試案例的內容，您完成MaxMinTool類別：
<br />
<br />
MaxMinTool.java<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 128, 128);">&nbsp;1</span>&nbsp;<span style="color: rgb(0, 0, 255);">package</span><span style="color: rgb(0, 0, 0);">&nbsp;onlyfun.caterpillar;<br />
</span><span style="color: rgb(0, 128, 128);">&nbsp;2</span>&nbsp;<span style="color: rgb(0, 0, 0);"><br />
</span><span style="color: rgb(0, 128, 128);">&nbsp;3</span>&nbsp;<span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">&nbsp;MaxMinTool&nbsp;{<br />
</span><span style="color: rgb(0, 128, 128);">&nbsp;4</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">&nbsp;getMax(</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">[]&nbsp;arr)&nbsp;{<br />
</span><span style="color: rgb(0, 128, 128);">&nbsp;5</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">&nbsp;max&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;Integer.MIN_VALUE;<br />
</span><span style="color: rgb(0, 128, 128);">&nbsp;6</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
</span><span style="color: rgb(0, 128, 128);">&nbsp;7</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">&nbsp;i&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">;&nbsp;i&nbsp;</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">&nbsp;arr.length;&nbsp;i</span><span style="color: rgb(0, 0, 0);">++</span><span style="color: rgb(0, 0, 0);">)&nbsp;{<br />
</span><span style="color: rgb(0, 128, 128);">&nbsp;8</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(arr[i]&nbsp;</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">&nbsp;max)<br />
</span><span style="color: rgb(0, 128, 128);">&nbsp;9</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;max&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;arr[i];<br />
</span><span style="color: rgb(0, 128, 128);">10</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
</span><span style="color: rgb(0, 128, 128);">11</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
</span><span style="color: rgb(0, 128, 128);">12</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">&nbsp;max;<br />
</span><span style="color: rgb(0, 128, 128);">13</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;}<br />
</span><span style="color: rgb(0, 128, 128);">14</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;<br />
</span><span style="color: rgb(0, 128, 128);">15</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">&nbsp;getMin(</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">[]&nbsp;arr)&nbsp;{<br />
</span><span style="color: rgb(0, 128, 128);">16</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">&nbsp;min&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;Integer.MAX_VALUE;<br />
</span><span style="color: rgb(0, 128, 128);">17</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
</span><span style="color: rgb(0, 128, 128);">18</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">&nbsp;i&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">;&nbsp;i&nbsp;</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">&nbsp;arr.length;&nbsp;i</span><span style="color: rgb(0, 0, 0);">++</span><span style="color: rgb(0, 0, 0);">)&nbsp;{<br />
</span><span style="color: rgb(0, 128, 128);">19</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(arr[i]&nbsp;</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">&nbsp;min)<br />
</span><span style="color: rgb(0, 128, 128);">20</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;min&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;arr[i];<br />
</span><span style="color: rgb(0, 128, 128);">21</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
</span><span style="color: rgb(0, 128, 128);">22</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
</span><span style="color: rgb(0, 128, 128);">23</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">&nbsp;min;<br />
</span><span style="color: rgb(0, 128, 128);">24</span>&nbsp;<span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;}<br />
</span><span style="color: rgb(0, 128, 128);">25</span>&nbsp;<span style="color: rgb(0, 0, 0);">}</span></div>
<br />
Swing介面的TestRunner在測試失敗時會顯示紅色的棒子，而在測試成功後會顯示綠色的棒子，而 <span style="font-weight: bold;">"Keep the bar green to keep the code clean."</span> 正是JUnit的名言，也是測試的最終目的。<br />
<img src ="http://www.blogjava.net/aldreamlau/aggbug/159653.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/aldreamlau/" target="_blank">aldream</a> 2007-11-11 00:55 <a href="http://www.blogjava.net/aldreamlau/articles/159653.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>