UISpec4J: Java/Swing GUI testing made simple!

UISpec4J: Java/Swing GUI testing made simple!

UISpec4J is an Open Source functional and/or unit testing library for Swing-based Java applications, built on top of JUnit and TestNG.

If you are writing a Swing application, you will appreciate UISpec4J above all for its simplicity: UISpec4J’s APIs are designed to hide as much as possible the complexity of Swing, resulting in easy to write and easy to read test scripts. This is especially true when comparing UISpec4J tests with those produced using Swing or low-level, event-based testing libraries.

Here is for example how a JTable content is tested with UISpec4J:

  public void testContacts() { Table contacts = getMainWindow().getTable(); assertTrue(contacts.contentEquals(new Object[][]{ {“John”, “12”, Boolean.FALSE}, {“Sylvia”, “43”, Boolean.TRUE}, {“Bill”, “31”, Boolean.FALSE}})); }

This code is shorter than what would be needed using the Swing APIs, but there is more: it checks the values actually displayed by the underlying JTable component, not just its internal model values. Achieving this with Swing would require checking the values computed by the renderers, resulting in several times as many lines of code.

Exploring UISpec4J

If you are new to UISpec4J, the best thing you can do is have a look at our tutorial and a simple UISpec4J example. Then you can follow our getting started guide to start using it on you own.

The documentation overview page lists all the how-to guides that will help you come to speed with UISpecJ.

Current release

The current release is 2.4 for JDK 1.5+, and 1.5 for JDK 1.4 (see change log). You can retrieve it from our download page.



Thanks a lot to JetBrains for providing us with licences for their impressive IDE, IntelliJ/IDEA. We have been IntelliJ fans since 2002, and we still haven’t found anything that comes close to this piece of software.