Testing Swing Application

2 years ago by in Concurrency, Design, Maven, Object Oriented Programming, Swing, Testing, Tutorial Tagged: , , , , , , ,

This tutorial demonstrates how to develop a simple Java Swing (or user interface) application and test the UI related logic using automated tests, such as JUnit (Homepage), using a series of videos compiled as a playlist (Youtube). The application is kept very simple while making use of various technologies, such as EasyMock (Homepage). This tutorial is targeted to college or university students who studied Java but lack experience and would like to do something productive. The main idea of this tutorial is not to learn Java, but to help the viewers to build testable Swing applications. The playlist presented by this tutorial shows how to build a Java Swing application that can be easily tested using automated tests in a step-by-step fashion.

All code for this tutorial is available at: http://java-creed-examples.googlecode.com/svn/testing/Testing Swing Application/. Each video has its own project and the viewers can download or view all code from the above link. With the exception of the first video, all other videos start from where the previous one left and thus the viewer can use the previous videos’ code as a starting point to the next video. The first video starts by creating a project from scratch.


The tutorial comprises the following

  1. Part 1 – Introduction: Introduce the problem and shows the limitations found when we tightly integrate the UI logic within the UI itself.
  2. Part 2 – Refactor UI Logic: Refactor the project and splits the UI logic away from the UI code. This is the first step in creating testable Swing/UI applications. This part introduces the concept of View and Presenter and provides a clear definition of their boundaries.
  3. Part 3 – Mocking: Describes how to test the UI logic and mocking the UI (referred to as the view).
  4. Part 4 – Multithreading: Shows how the introduction of multiple threads can tamper our tests and provides a simple solution to handle this issue.

The application shown in this tutorial is developed with Spring Tool Suite, also referred to as STS, (Download). The viewers are free to use any integrated development environment, also referred to as IDE, (Wiki), they prefer. In such event, please note that some of the commands or shortcuts may not work on a different IDE and some things may be organised differently. If you are new to Java, it is highly recommended to use the same IDE as the one used in the videos as this will simplify your learning experience. Please note that by no means we are saying that the other IDE are not good or that STS is better than all others. For more information about how to setup your environment please follow the Setting up the Environment tutorial.

Resources and Technologies

Following is a list of resources technologies used in this tutorial. These are shown in the order they appear.

  1. Spring Source Tool Suite: http://spring.io/tools/sts/all
  2. Maven: http://maven.apache.org/
  3. EasyMock: http://easymock.org/
  4. JUnit: http://junit.org/
  5. Jenkins (Continuous Integration): http://jenkins-ci.org/
  6. Hudson (Continuous Integration): http://hudson-ci.org/


Please note that the videos are recorded in HD (1080p). Make sure to use the correct resolution to make the best out of these videos as shown below.

Videos Resolution

Videos Resolution


Should you have any queries, please do not hesitate to contact me at: [email protected] or through Google+.

Recommended Books

  1. Test Driven Development (also referred to as TDD): By Example: Quite simply, test-driven development is meant to eliminate fear in application development. While some fear is healthy (often viewed as a conscience that tells programmers to “be careful!“), the author believes that byproducts of fear include tentative, grumpy, and uncommunicative programmers who are unable to absorb constructive criticism. When programming teams buy into TDD, they immediately see positive results. They eliminate the fear involved in their jobs, and are better equipped to tackle the difficult challenges that face them. TDD eliminates tentative traits, it teaches programmers to communicate, and it encourages team members to seek out criticism. However, even the author admits that grumpiness must be worked out individually! In short, the premise behind TDD is that code should be continually tested and refactored. Kent Beck teaches programmers by example, so they can painlessly and dramatically increase the quality of their work.
Albert Attard

Albert Attard is a Java passionate and technical lead at a research group. You can find him on . Over the past years Albert worked on various Java projects including traditional server/client applications, modular applications, large data handling applications and concurrent data manipulation applications to name a few. He has a BSc degree from the University of London (Homepage) and an MSc Information Security with the same university. His MSc thesis (Book) received the 2012 SearchSecurity.co.UK award (Website).

Leave a Comment