Swing Extreme Testing
Swing used to be a simple component offered as an add-on for Java. This plug-in can be used as a GUI (graphical user interface) to develop as an add-on for the Java application. It has the ability to emulate certain platforms eventually building a powerful application. With this plug-in, users will experience the full potential of Java as it uses its native capability and with the help of Swing, different web development languages are added to the application. Swing’s ability to emulate eventually made this plug-in one of the most popular and important tools in Java development that it eventually became part of Java development package.
The challenge for developers with swing though is testing its components. Testing is one of the fundamental steps in application development and apparently, testing Swing has become a challenge for developers. By itself swing is very easy to test but since it is used as an emulator, it is often changed according to the needs of the application. Changes in the application are common during the development process and swing has to adjust to these changes – eventually testing its components a little bit harder.
This book is available for purchase at packtpub.com Swing Extreme Testing
This book aims to answer those questions and guide the developers on properly testing the Swing plug-ins in as little time as possible. This book will deal with a very important testing technique: automation. Through automation, testing will be faster and development will eventually be easier.
Swing Extreme Testing by Tim Lavers Lindsay Peters This book is a practical guide to automated software testing for extreme Java programming using Swing GUIs with lots of ready-to-use real-life examples and source code for automated testing of the software components usually regarded as too hard to test automatically. Read Sample Chapter 9 -...
Outline of the Unit Test The things we want to test are Initial settings The text field is empty. The text field is a sensible size. The Ok button is disabled. The Cancel button is enabled. The dialog is a sensible size. Usability The Escape key...
Getting the Text of a Text Field The method is getText and there is a variant to retrieve just the selected text geshibot language Java 5" ... from UI Safely read the text of the given text component. public static String getText JTextComponent textComponent return getTextImpl textComponent true ;...
Unit Test Infrastructure Having seen the broad outline of the test class and the UI methods needed we can look closely at the implementation of the test. We ll start with the UI Wrapper class and the init and cleanup methods. The UISaveAsDialog Class UISaveAsDialog has methods for entering a name and for accessing the dialog buttons and...
The ShowerThread Class Since SaveAsDialog.show blocks we cannot call this from our main thread; instead we spawn a new thread. This thread could just be an anonymous inner class in the init method geshibot language Java 5" private void init Not really what we do... setup...then launch a thread to show the dialog. Start...
The init Method The job of the init method is to create and show the SaveAsDialog instance so that it can be tested geshibot language Java 5" private void init Note 1 names new TreeSet ; names.add new IkonName Albus" ; names.add new IkonName Minerva" ; names.add new IkonName...
The Constructor Test A freshly constructed SaveAsDialog should be in a known state and we need to check the things we listed at the start of this chapter. geshibot language Java 5" public boolean constructorTest Note 1 init ; Note 2 Check the title. assert UI.getTitle ui.dialog .equals us.label IkonMakerUserStrings.SAVE_AS...
The wasCancelled Test The first of our API tests is to check the wasCancelled method. We will basically do three investigations. The first test will call wasCancelled before the dialog has been cancelled. The second test will cancel the dialog and then call the method. In the third test we will enter a name cancel the dialog and then call wasCancelled ....
The name Test Like the wasCancelled method the name method is not thread-safe so our test class needs another boilerplate helper method geshibot language Java 5" From SaveAsDialogTest private IkonName enteredName final IkonName resultHolder new IkonName 1 ; UI.runInEventThread new Runnable public void...
The Data Validation Test The Ok button of the SaveAsDialog should only be enabled if the name that has been entered is valid. A name can be invalid if it contains an illegal character or if it has already been used. To test this behavior we type in an invalid name check that the Ok button is not enabled then type in a valid name and test that...