Testing Swing GUIs
Problem
You want to use a specialized toolkit for testing Swing GUI code.
Solution
Try out Abbot, Pounder, Jemmy, or JFCUnit.
Discussion
Testing GUI code is challenging. You locate GUI components, simulate user input, and capture the actual output to test against your expected output. You must also deal with threading issues, because many Swing events are delivered asynchronously on the event queue.
Minimizing dependency on GUI tests is always your first line of defense. You should make every effort to modularize your GUI code so that data models can be tested independently from the GUI. You can also write many tests against individual panels and components. But at some point, you may find that you have to run tests against the entire user interface in order to fully simulate how the user works with your application. This is where specialized GUI testing tool enter the picture.
Abbot
Abbot is a testing framework that builds
on functionality offered by the java.awt.Robot
class. In Abbot, you create testing scripts that locate components,
perform actions, and then assert that the GUI is in the correct
state. These scripts are your automated GUI tests. Although you can
use the Abbot API to write tests programmatically, Abbot scripts are
normally used for testing.
You generally create a script by running your application while Abbot
Recorders capture all events and generate the script for you. Then use the Costello script editor to change and customize your scripts. Next, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access