Abbot GUI Tester framework for testing Java GUI
components and programs
All materials Copyright (C) 2002 Timothy Wall
Getting Started
JUnit is used as the controlling harness
for running tests, but the tests can easily be adapted to other environments.
If you haven't done so yet, download the abbot
package. All the supporting
jars you need (including junit) are included.
The overview of
the Abbot system will give you an idea of the different system components.
There is also some background
concerning the issues involved with Java GUI testing.
Quick Start
- Launch the script editor.
CLASSPATH=.:abbot.jar:lib/xerces-130.jar:lib/regexp-110.jar:lib/junit.jar
java -classpath $CLASSPATH junit.extensions.awt.editor.ScriptEditor
- Create a new script.
Select Script->New from the menu bar to get a new script with default
launch and terminate steps.
Launch defines a class and method to invoke to launch your GUI.
Terminate disposes of all GUI components
generated by the launch step.
- Launch your GUI.
Edit the launch line to launch your GUI component or application.
The placeholder in the script just created defaults to invoking the script
editor's main method with an empty String array; see the
Launch step for
usage details. Use Script->Launch to display your GUI under test.
- Record some user actions.
Select Record->All Actions, and perform some user actions in your GUI.
Press the ESC key when you have finished. The editor will detect as many
high-level semantic events as it can and insert raw mouse motion and button
events for what it doesn't recognize.
- Add some assertions.
Once you've made some changes to your GUI, you should add some assertions to
verify different bits of the GUI state. Below the script steps is a tabbed
pane which provides two views of the components in your GUI. The hierarchy
view presents the full hierarchy of components that have been created.
You can explore your GUI's hierarchy by walking the hierarchy tree or by
clicking mouse button 3 (2 on linux) on a component in your launched GUI,
which will automatically select that component in the component browser.
Once you've selected a component in the browser, its associated properties
will appear in the pane to the right. Select a property ("Text" on a JButton,
for instance), the click the Add Property Check button to insert an
assertion into the test. Repeat as necessary for other components.
- Run the script.
The script editor also allows you to run the script, recording any test
failures or errors. Each step will be highlighted as it is played back, with
failures highlighed in yellow and errors in red.
When you've generated several tests and want to incorporate them into a
JUnit suite, you will want to derive from
AWTTestCase to provide a
custom AWTTestSuite
which will identify which scripts belong in the suite. AWTTestCase
is a simple JUnit test case wrapper around an Abbot test script. The only
thing you really need to do is return an inner AWTTestSuite instance in the
static "suite" method. The default implementation collects all scripts in
the directory "./scripts".
Examples
Look at a sample GUI component test
(which extends AWTTestCase) to see what it takes to write a test suite. The
FontChooserTest exercises this component.
The scripts comprising this suite are
here.
Abbot can also test a full application with a test case like this, which exercises this Java application (and scripts here and here).
You can watch Abbot do its thing by running one of the prepared example test
suites:
java -classpath $CLASSPATH example.FontChooserTest
java -classpath $CLASSPATH example.MyCodeTest
For a more complete description of the framework, see the
overview document.