Reviews
Swing Extreme TestingSwing Extreme Testing - The Constructor Test
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.
- public boolean constructorTest() { //Note 1 init()
//Note 2 //Check the title. assert UI.getTitle( ui.dialog() ).equals( us.label( IkonMakerUserStrings.SAVE_AS ) ) //Note 3 //Check the size. Dimension size = UI.getSize( ui.dialog() ) assert size.width > 60 assert size.width < 260 assert size.height > 20 assert size.height < 200 //Note 4 //Name field initially empty. assert UI.getText( ui.nameField() ).equals( "" ) //Name field a sensible size. Dimension nameFieldSize = UI.getSize( ui.nameField() ) assert nameFieldSize.width > 60 assert nameFieldSize.width < 260 assert nameFieldSize.height > 15 assert nameFieldSize.height < 25 //Ok not enabled. assert !UI.isEnabled( ui.okButton() ) //Cancel enabled. assert UI.isEnabled( ui.cancelButton() ) //Type in some text and check that the ok button is now enabled. ui.robot.type( "text" ) assert UI.isEnabled( ui.okButton() ) cleanup() return true }
Let's now look at the noteworthy parts of this code.
Note 1: In accordance with the rules for GrandTestAuto (see Chapter 19), the test is a public method, returns a boolean, and has name ending with "Test". As with all of the tests, we begin with the init() method that creates and shows the dialog. After the body of the test, we call cleanup() and return true. If problems are found, they cause an assert exception.
Note 2: The UI Wrapper gives us the dialog, and from this we can check the title. It is important that we are using the UI class to get the title of the dialog in a thread-safe manner.
Note 3: Here we are checking the size of dialog is reasonable. The actual allowed upper and lower bounds on height and width were found simply by trial and error.
Note 4: Although the UI Wrapper gives us access to the name field and the buttons, we must not interrogate them directly. Rather, we use our UI methods to investigate them in a thread-safe manner.
Swing Extreme Testing
- Swing Extreme Testing
- Swing Extreme Testing - Outline of the Unit Test
- Swing Extreme Testing - Getting the Text of a Text Field
- Swing Extreme Testing - Unit Test Infrastructure
- Swing Extreme Testing - The ShowerThread Class
- Swing Extreme Testing - The init() Method
- Swing Extreme Testing - The Constructor Test
- Swing Extreme Testing - The wasCancelled() Test
- Swing Extreme Testing - The name() Test
- Swing Extreme Testing - The Data Validation Test







