Exforsys.com
 

Sponsored Links

 

Swing Testing Tutorials

 
Home Tutorials Swing Testing
 

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



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.



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.



Read Next: Swing Extreme Testing - The wasCancelled() Test



 

 

Comments



Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    

Sponsored Links

 

Subscribe via RSS


Get Daily Updates via Subscribe to Exforsys Free Training via email


Get Latest Free Training Updates delivered directly to your Inbox...

Enter your email address:


 

Subscribe to Exforsys Free Training via RSS
 

 
Partners -  Privacy and Legal Policy -  Site News -  Contact   Sitemap  

Copyright © 2000 - 2010 exforsys.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape