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...
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.
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 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:
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.
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...
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.