Section 13.8. What You Still Don t Know


13.8. What You Still Don't Know

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 development, 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.



    Java Application Development with Linux
    Java Application Development on Linux
    ISBN: 013143697X
    EAN: 2147483647
    Year: 2004
    Pages: 292

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net