Free Sample
+ Collection

Swing Extreme Testing

Lindsay Peters, Tim Lavers

The Extreme approach to complete Java application testing
RRP $23.99
RRP $39.99
Print + eBook

Want this title & more?

$12.99 p/month

Subscribe to PacktLib

Enjoy full and instant access to over 2000 books and videos – you’ll find everything you need to stay ahead of the curve and make sure you can always get the job done.

Book Details

ISBN 139781847194824
Paperback328 pages

About This Book

  • 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

Who This Book Is For

This book is for Swing developers who design and develop complex software for user interfaces that requires extensive testing. If you want to learn to test your Swing GUI components, this book is for you.

Table of Contents

Chapter 1: What Needs Testing?
An Example
What Classes Do We Test?
Test First—Always!
What Classes Don't We Test?
What Methods Need Testing?
What Methods Don't We Test?
Invoking Hidden Methods and Constructors
Unit Test Coverage
Who Should Implement the Unit Tests?
What About Legacy Code?
Where Does Integration Testing Fit In?
Documentation of Unit Tests
Testing at the Application Level
Who Should Implement the Function Tests?
Automated Test Execution
A Hierarchy of Tests
What Language Should Our Tests Be In?
Is it Really Possible?
Chapter 2: Basics of Unit Testing
A Simple Example
The Default Implementation
Test Cases
Design by Contract and Non-Defensive Programming
Test Code Example
Bootstrapping Our Implementation
Load Testing
Chapter 3: Infrastructure for Testing
Where Should the Unit Tests Go?
Where Should the Function and Load Tests Go?
Management of Test Data
Temporary Files
Chapter 4: Cyborg—a Better Robot
The Design of Cyborg
Using the Keyboard
Mousing Around
Checking the Screen
Chapter 5: Managing and Testing User Messages
Some Problems with Resource Bundles
A Solution
The UserStrings Class
Getting More from UserStrings
Chapter 6: Making Classes Testable with Interfaces
The LabWizard Comment Editor
The Wizard
A Test for Wizard
A Test for Step
Handlers in LabWizard
Chapter 7: Exercising UI Components in Tests
The LabWizard Login Screen
The Design of LoginScreen
UI Wrappers
A Handler Implementation for Unit Testing
Setting Up our Tests
Our First Test
Further Tests
Some Implicit Tests
Other User Interfaces
Chapter 8: Showing, Finding, and Reading Swing Components
Setting Up User Interface Components in a Thread-Safe Manner
Finding a Component
Testing Whether a Message is Showing
Searching for Components by Name
Reading the State of a Component
Case Study: Testing Whether an Action Can Be Cancelled
The Official Word on Swing Threading
Chapter 9: Case Study: Testing a 'Save as' Dialog
The Ikon Do It 'Save as' Dialog
Outline of the Unit Test
UI Helper Methods
Unit Test Infrastructure
The Unit Tests
Chapter 10: More Techniques for Testing Swing Components
Testing with JColorChooser
Using JFileChooser
Checking that a JFileChooser has been Set Up Correctly
Testing the Appearance of a JComponent
Testing with Frames
Testing with Lists
Testing a JTable
Testing with JMenus
Testing JPopupMenus
Combo Boxes
Progress Bars
JSlider and JSpinner
Chapter 11: Help!
What Tests Do We Need?
Creating and Testing Context-Sensitive Help
Executing HelpGenerator
Chapter 12: Threads
The Waiting Class
Concurrent Modifiers
Concurrent Readers and Writers
Proof of Thread Completion
The Unit Test for waitForNamedThreadToFinish()
Counting Threads
Further Reading
Chapter 13: Logging
Logging to a File
Remember to Roll!
Testing What is Printed to the Console
Chapter 14: Communication with External Systems
Testing Spreadsheets
Chapter 15: Embedding User Interface Components in Server-side Classes
A Typical MVC System
The Problem
The Solution
Which Approach Should We Use?
Chapter 16: Tests Involving Databases
A Uniform Approach to Accessing the Database
Persistence Testing
Database Management
Chapter 17: Function Tests
Specification of the Tests
Implementation of the 'DeleteCase' Test
Tests Involving Multiple JVMs
Multiple JVMs with GUI Components
Use of a Function Test as a Tutorial
Testing a Web Service
Chapter 18: Load Testing
What to Test
Measuring Time
Measuring RAM Usage
The Load Tests for LabWizard
Profilers and Other Tools
Chapter 19: GrandTestAuto
What is GrandTestAuto?
Unit Test Coverage
Advantages of Using GTA
Getting Started
Testing Overloaded Methods
Testing Protected Methods
Extra Tests
Classes That Do Not Need Tests
Day-To-Day Use of GrandTestAuto
Distributed Testing Using GTA
Chapter 20: Flaky Tests
A Flaky 'Ikon Do It' Unit Test
Writing Reliable Tests
Dealing with Flaky Tests
Diagnostic Tools
Tests That Do Not Terminate

What You Will Learn

  • What needs testing in a Java software project—the extreme testing approach
  • Managing test classes and test data
  • Useful tools for robotically testing Java applications
  • Managing and testing user interface components, and using UI wrappers in function testing
  • Setting up Swing GUI components in a thread-safe manner
  • Creating and testing a JavaHelp system for an application
  • Testing highly multi-threaded system and communication with external systems
  • Testing the logs produced by a software application
  • Embedding GUI components in server-side classes
  • Managing databases in a way that facilitates testing
  • Specifying and writing tests at the system level, tests using multiple JVMs
  • Basics of load testing
  • Exploring GrandTestAuto, a tool for test automation, coverage checking, and distributed testing
  • Dealing with intermittent test failures

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.


Read More