PacktLib: Swing Extreme Testing

Swing Extreme Testing

Credits

About the Authors

About the Reviewers

Preface

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?

Summary

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

Summary

Infrastructure for Testing

Where Should the Unit Tests Go?

Where Should the Function and Load Tests Go?

Management of Test Data

Temporary Files

Summary

Cyborg—a Better Robot

The Design of Cyborg

Using the Keyboard

Mousing Around

Checking the Screen

Summary

Managing and Testing User Messages

Some Problems with Resource Bundles

A Solution

The UserStrings Class

ResourcesTester

Getting More from UserStrings

Summary

Making Classes Testable with Interfaces

The LabWizard Comment Editor

The Wizard

A Test for Wizard

A Test for Step

Handlers in LabWizard

Summary

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

Summary

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

Summary

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

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

JTree

Summary

Help!

Overview

What Tests Do We Need?

Creating and Testing Context-Sensitive Help

Executing HelpGenerator

Summary

Threads

The Waiting Class

Concurrent Modifiers

Concurrent Readers and Writers

Proof of Thread Completion

The Unit Test for waitForNamedThreadToFinish()

Counting Threads

Summary

Further Reading

Logging

Logging to a File

Remember to Roll!

Testing What is Printed to the Console

Summary

Communication with External Systems

Email

Testing Spreadsheets

PDF

Serialization

Files

Summary

Embedding User Interface Components in Server-side Classes

A Typical MVC System

The Problem

The Solution

Which Approach Should We Use?

Summary

Tests Involving Databases

A Uniform Approach to Accessing the Database

Persistence Testing

Database Management

Summary

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

Summary

Load Testing

What to Test

Measuring Time

Measuring RAM Usage

The Load Tests for LabWizard

Profilers and Other Tools

Summary

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

Summary

Flaky Tests

A Flaky 'Ikon Do It' Unit Test

Writing Reliable Tests

Dealing with Flaky Tests

Diagnostic Tools

Tests That Do Not Terminate

Summary

Index