13.07.2015 Views

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

312Chapter 13JUnit: Automating Unit Testing13.7REVIEWWe have shown you how to download JUnit and get it running. We have discussedcreating a test case and creating a suite of tests. We’ve looked at theSwing GUI for JUnit but also at the command-line interface. We have shownhow our design translates to a minimal code implementati<strong>on</strong> from which wecan begin testing. We’ve discussed the “design, test, then code” approach, andhow you can use it to track the progress of your implementati<strong>on</strong>.13.8WHAT YOU STILL DON’T KNOWJUnit can be invoked from ant. It is an opti<strong>on</strong>al task (not part of the standardant release), but easy to install and get running. Both the junit.jar and ant’sopti<strong>on</strong>al tasks JAR file need to be in your classpath. That’s all it takes. Seehttp://ant.apache.org/manual/Opti<strong>on</strong>alTasks/junit.html for moredetails.JUnit integrates well with Eclipse and other IDEs. It is easy to install andvery 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 GUIporti<strong>on</strong> of your applicati<strong>on</strong>. The basic idea is the same. In order to manipulateyour GUI from the test, you may want to investigate the java.awt.Robotclass. It can be used to generate system input events such as mouse andkeyboard acti<strong>on</strong>s.In fact, we’ve <strong>on</strong>ly begun to describe the various ways that JUnit can beused for all kinds of testing. Our focus has been <strong>on</strong> unit tests during code development,but JUnit can also be applied to integrati<strong>on</strong> and release testing. Withany large Java applicati<strong>on</strong>, it is crucial to have a good set of regressi<strong>on</strong> tests thatcan be rerun after features or fixes are added, or after classes have beenrefactored. JUnit has proven to be very valuable in these situati<strong>on</strong>s.Finally, remember that JUnit is <strong>on</strong>ly a tool. The GIGO law 2 tells us notto expect great tests just because we know how to run a tool. Test design, likeany good design skill, is art as well as science. Learning the art of testing willpay dividends in better code built faster.2. Garbage In, Garbage Out.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!