O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Swing Extreme Testing

Book Description

The Extreme approach to complete Java application testing

  • Learn Swing user interface testing strategy

  • Automate testing of components usually thought too hard to test automatically

  • Practical guide with ready-to-use examples and source code

  • Based on the authors’ experience developing and testing commercial software

In Detail

Thorough testing is the basis of good software. Whether we use an agile development methodology such as Extreme Programming, or a more traditional approach, we must test our software at the unit level and application level. The tests must run automatically and cover all aspects of the software.

In this book, the authors draw on more than 20 years of experience to show how automated testing can be applied to a real commercial product.

This book will teach you how to automatically test user interfaces (Swing GUIs), the help system, internationalization, log files, spreadsheets, email, and web services, how to perform tests involving multiple JVMs, and a host of other things. These tests are applied at the module level (unit tests) and at the application level (function tests).

The authors have developed the test processes in the broader context of an Extreme Programming (XP) methodology. However, the testing techniques are certainly not specific to XP, and may be applied within any given development methodology.

Table of Contents

  1. Swing Extreme Testing
  2. Credits
  3. About the Authors
  4. About the Reviewers
  5. Preface
    1. What This Book Offers
    2. Roadblocks to Testing
      1. Roadblock 1: Last on the Waterfall
      2. Roadblock 2: Testing should be Done by Someone Else
      3. Roadblock 3: It's Too Hard to Test User Interfaces
      4. Roadblock 4: It's Too Hard to Develop and Maintain Test Code
      5. Roadblock 5: It's Too Expensive to Run Tests Often
      6. Roadblock 6: It's More Interesting to Develop "Real" Code
    3. Overview
    4. Examples and Code
      1. LabWizard
      2. Ikon Do It
      3. GrandTestAuto
      4. Source code
    5. What You Need For This Book
    6. Who Is This Book For
    7. Conventions
    8. Reader Feedback
    9. Customer Support
      1. Downloading the Example Code for the Book
      2. Errata
      3. Questions
  6. 1. What Needs Testing?
    1. An Example
    2. What Classes Do We Test?
    3. Test First—Always!
    4. What Classes Don't We Test?
    5. What Methods Need Testing?
    6. What Methods Don't We Test?
    7. Invoking Hidden Methods and Constructors
    8. Unit Test Coverage
    9. Who Should Implement the Unit Tests?
    10. What About Legacy Code?
    11. Where Does Integration Testing Fit In?
    12. Documentation of Unit Tests
    13. Testing at the Application Level
    14. Who Should Implement the Function Tests?
    15. Automated Test Execution
    16. A Hierarchy of Tests
    17. What Language Should Our Tests Be In?
    18. Is it Really Possible?
    19. Summary
  7. 2. Basics of Unit Testing
    1. A Simple Example
    2. The Default Implementation
    3. Test Cases
    4. Design by Contract and Non-Defensive Programming
    5. Test Code Example
    6. Bootstrapping Our Implementation
    7. Load Testing
    8. Summary
  8. 3. Infrastructure for Testing
    1. Where Should the Unit Tests Go?
    2. Where Should the Function and Load Tests Go?
    3. Management of Test Data
      1. What Do We Require of a Test Data Management System?
    4. Temporary Files
    5. Summary
  9. 4. Cyborg—a Better Robot
    1. The Design of Cyborg
    2. Using the Keyboard
    3. Mousing Around
    4. Checking the Screen
    5. Summary
  10. 5. Managing and Testing User Messages
    1. Some Problems with Resource Bundles
    2. A Solution
    3. The UserStrings Class
    4. ResourcesTester
      1. How ResourcesTester Works
    5. Getting More from UserStrings
    6. Summary
  11. 6. Making Classes Testable with Interfaces
    1. The LabWizard Comment Editor
    2. The Wizard
    3. A Test for Wizard
    4. A Test for Step
    5. Handlers in LabWizard
    6. Summary
  12. 7. Exercising UI Components in Tests
    1. The LabWizard Login Screen
    2. The Design of LoginScreen
    3. UI Wrappers
      1. The Correct Implementation of UILoginScreen
    4. A Handler Implementation for Unit Testing
    5. Setting Up our Tests
    6. Our First Test
    7. Further Tests
    8. Some Implicit Tests
    9. Other User Interfaces
    10. Summary
  13. 8. Showing, Finding, and Reading Swing Components
    1. Setting Up User Interface Components in a Thread-Safe Manner
    2. Finding a Component
    3. Testing Whether a Message is Showing
    4. Searching for Components by Name
    5. Reading the State of a Component
    6. Case Study: Testing Whether an Action Can Be Cancelled
    7. The Official Word on Swing Threading
    8. Summary
  14. 9. Case Study: Testing a 'Save as' Dialog
    1. The Ikon Do It 'Save as' Dialog
    2. Outline of the Unit Test
    3. UI Helper Methods
      1. Dialogs
      2. Getting the Text of a Text Field
      3. Frame Disposal
    4. Unit Test Infrastructure
      1. The UISaveAsDialog Class
      2. The ShowerThread Class
      3. The init() Method
      4. The cleanup() Method
    5. The Unit Tests
      1. The Constructor Test
      2. The wasCancelled() Test
      3. The name() Test
      4. The show() Test
      5. The Data Validation Test
      6. The Usability Test
      7. Summary
  15. 10. More Techniques for Testing Swing Components
    1. Testing with JColorChooser
    2. Using JFileChooser
    3. Checking that a JFileChooser has been Set Up Correctly
    4. Testing the Appearance of a JComponent
    5. Testing with Frames
      1. Frame Location
      2. Frame Size
    6. Testing with Lists
      1. List Selection Methods
      2. List Rendering
      3. List Properties
    7. Testing a JTable
    8. Testing with JMenus
      1. Checking the Items
      2. Using Menus with Cyborg
    9. Testing JPopupMenus
    10. Combo Boxes
    11. Progress Bars
    12. JSlider and JSpinner
    13. JTree
    14. Summary
  16. 11. Help!
    1. Overview
    2. What Tests Do We Need?
      1. An HTML File That is Not Indexed
      2. An index item for which there is no HTML file
      3. Broken links
      4. Incorrectly titled help pages
    3. Creating and Testing Context-Sensitive Help
    4. Executing HelpGenerator
    5. Summary
  17. 12. Threads
    1. The Waiting Class
    2. Concurrent Modifiers
    3. Concurrent Readers and Writers
    4. Proof of Thread Completion
    5. The Unit Test for waitForNamedThreadToFinish()
    6. Counting Threads
    7. Summary
    8. Further Reading
  18. 13. Logging
    1. Logging to a File
    2. Remember to Roll!
    3. Testing What is Printed to the Console
      1. Switching Streams
      2. Reading the Output From a Second JVM
    4. Summary
  19. 14. Communication with External Systems
    1. Email
      1. Using an External Email Account
      2. Using a Local Email Server
      3. Which Method is Best?
    2. Testing Spreadsheets
    3. PDF
    4. Serialization
    5. Files
    6. Summary
  20. 15. Embedding User Interface Components in Server-side Classes
    1. A Typical MVC System
    2. The Problem
    3. The Solution
    4. Which Approach Should We Use?
    5. Summary
  21. 16. Tests Involving Databases
    1. A Uniform Approach to Accessing the Database
    2. Persistence Testing
    3. Database Management
    4. Summary
  22. 17. Function Tests
    1. Specification of the Tests
    2. Implementation of the 'DeleteCase' Test
    3. Tests Involving Multiple JVMs
    4. Multiple JVMs with GUI Components
    5. Use of a Function Test as a Tutorial
    6. Testing a Web Service
    7. Summary
  23. 18. Load Testing
    1. What to Test
      1. Overnight 'Housekeeping' Takes Too Long
      2. Deleting Cases Takes Too Long
      3. The BMD Server is Too Slow to Start
    2. Measuring Time
    3. Measuring RAM Usage
    4. The Load Tests for LabWizard
    5. Profilers and Other Tools
    6. Summary
  24. 19. GrandTestAuto
    1. What is GrandTestAuto?
    2. Unit Test Coverage
    3. Advantages of Using GTA
    4. Getting Started
    5. Testing Overloaded Methods
    6. Testing Protected Methods
    7. Extra Tests
    8. Classes That Do Not Need Tests
    9. Day-To-Day Use of GrandTestAuto
      1. Running Just One Level of Test
      2. Running the Unit Tests for a Single Package
      3. Running the Unit Tests for a Single Class
      4. Running the Tests for a Selection of Packages
      5. Package Name Abbreviation
      6. Running Tests for a Selection of Classes Within a Single Package
      7. Running Individual Test Methods
      8. Running GTA From Ant or CruiseControl
      9. GTA Parameters
    10. Distributed Testing Using GTA
      1. How it Works—In Brief
      2. A Distributed Testing Example
    11. Summary
  25. 20. Flaky Tests
    1. A Flaky 'Ikon Do It' Unit Test
    2. Writing Reliable Tests
    3. Dealing with Flaky Tests
    4. Diagnostic Tools
    5. Tests That Do Not Terminate
      1. Non-Daemon Threads
      2. Remote Objects
      3. Server Socket Still Waiting
      4. Frame Not Properly Disposed
    6. Summary