Swing Testing Toolkit user guide

Getting Started with Swing Testing Toolkit

This document provides more in-depth descriptions of how to use the Swing Testing Toolkit  editor.

Creating a Test Specification

Tests specifications  are a convenient way to organize a suite of actions and assertions that make up a test case. They are saved to disk as XML as a convenient and standardized storage format.

Tests specifications are primarily composed of actions and assertions.

Actions are things that a user usually does to operate a GUI component, like pushing a button, selecting a menu item, or entering text. Most actions require one or more arguments.

Assertions (Check …) allow you to verify the state of your GUI. You can check the value of GUI component visible strings or properties.

Normally the test will stop running and report an error if actions or assertions fail.

Component finders represent actual GUI component instances within your code under test. They are used by most actions and assertions to locate the target GUI component.

Create New Test Specification

Run the class “xy.ui.testing.editor.TestEditor”.

Open an Existing Test Specification

Select Open Specification from the File menu, and you can browse for an existing test specification to open. The filename extension is “stt“.

Launching an Application

Launch Information

The Call Main Method Step allows you to indicate the main class name of your code under test. Its “main” method must be a public static method. This main class must be in the classpath.

Note that the Launch step is threaded. You can setup this launch step to fail if an exception is thrown. See the option: “Check exceptions after (seconds)”.

What goes into a Test Specification ?

The Add/Insert menu allows you to manually insert any test step type.


The easiest way to see the types of things that go into a test specification is to start recording. Once you’ve set up and execute your launch step properly, you can start recording by clicking on “Record…“. Recording settings will then appear.  If your application has not been launched yet, you can click on the checkbox “Start By Calling Main Method” and provide the main class name there. You can then click on Record and the editor will begin recording your actions.

Note that the recording does not cause the capture of all events. You must explicitly choose the component with which you want to interact by left-clicking on it and then select the type of interaction (action or assertion) in the dialog box that will open. This greatly reduces the complexity of the test cases.

When recording, the selection of suggested actions/assertions may change based on the currently selected component. The dialog box of the suggested actions/assertions is dynamically filled by the used Tester class.  These actions/assertions are automatically configured as much as possible according to the selected component. Once the step is inserted, you can further edit its attributes in the test editor.

When you are finished recording, you must click on the red  stop button to stop recording. Then you can click the Replay All button to play back the recording.

Advanced Topics

Integrate with JUnit

The test specifications can be executed using the following method:

TestingUtils.assertSuccessfulReplay(new File(“path/to/test-specification.stt”));

Note that this method ends by closing all windows to prepare the environment for a next run.

System.exit() call interception

The tested application and the test code share the same JVM. This is why it is possible to prevent the tested application from shutting down the JVM. For this purpose you can use the “System exit call interception” action.