Published

Automated UI testing with Swing & FEST

Testing an application is hard, but testing an user interface (UI) is even harder. FEST addresses this issue for Java Swing applications. It enables you to write easy and readable functional tests for your UI. Working together with JUnit, it lets your functional UI tests feel like common unit tests within your test suite.

FEST is a context-sensitive testing-framework, which means that the position of your UI components, their size or color isn’t important for the test (of course you can tests this criteria if you want). FEST identifies all UI components by an unique ID – their name. Therefore, your UI layout can change, but the tests will still work.

1

2

3

Component component=newJButton();

component.setName("aName");

Stringname=component.getName();

By the way: Because all components in your UI must have a unique name, it’s a good idea to use a Factory to create your components and to make sure that they all have an unique name.

FEST uses the java.awt.Robot class to interact with your UI. Robot is part of the JDK since version 1.3 and provides a low-level API to simulate user interaction for AWT or Swing application. FEST encapsulate this class into an abstract and easy to use API.

The difference between common JUnit tests and functional tests using FEST is the level of test-execution. JUnit tests are working on isolated classes and methods whereas functional tests (with FEST) are working on the real UI shown to the user. This real UI can be composed of many single objects that should be tested altogether. Also, functional test doesn’t work on a method-level – they are working on the same level as the human user simulating “clicks”, “selects” and “keys”.