Exforsys

Home arrow Reviews arrow Swing Extreme Testing

Swing Extreme Testing - The Constructor Test

Author: Packt Publishing     Published on: 11th Jul 2008

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.

Ads

Sample Code
  1. 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 }
Copyright exforsys.com


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.

Ads

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.



 
This tutorial is part of a Swing Extreme Testing tutorial series. Read it from the beginning and learn yourself.

Swing Extreme Testing

 

Comments