Java Reference
In-Depth Information
13.7
R EVIEW
We have shown you how to download JUnit and get it running. We have dis-
cussed creating a test case and creating a suite of tests. We've looked at the
Swing GUI for JUnit but also at the command-line interface. We have shown
how our design translates to a minimal code implementation from which we
can begin testing. We've discussed the “design, test, then code” approach, and
how you can use it to track the progress of your implementation.
13.8
W HAT Y OU S TILL D ON ' T K NOW
JUnit can be invoked from ant . It is an optional task (not part of the standard
ant release), but easy to install and get running. Both the junit.jar and ant 's
optional tasks JAR file need to be in your classpath. That's all it takes. See
http://ant.apache.org/manual/OptionalTasks/junit.html for more
details.
JUnit integrates well with Eclipse and other IDEs. It is easy to install and
very easy to use when it's part of your IDE. For whichever IDE you choose,
get the JUnit plug-in for it and use it.
One area we haven't yet discussed is how to do unit testing for the GUI
portion of your application. The basic idea is the same. In order to manipulate
your GUI from the test, you may want to investigate the java.awt.Robot
class. It can be used to generate system input events such as mouse and
keyboard actions.
In fact, we've only begun to describe the various ways that JUnit can be
used for all kinds of testing. Our focus has been on unit tests during code devel-
opment, but JUnit can also be applied to integration and release testing. With
any large Java application, it is crucial to have a good set of regression tests that
can be rerun after features or fixes are added, or after classes have been
refactored. JUnit has proven to be very valuable in these situations.
Finally, remember that JUnit is only a tool. The GIGO law 2 tells us not
to expect great tests just because we know how to run a tool. Test design, like
any good design skill, is art as well as science. Learning the art of testing will
pay dividends in better code built faster.
2. Garbage In, Garbage Out.
Search WWH ::




Custom Search