O'Reilly logo

Swing Extreme Testing by Tim Lavers, Lindsay Peters

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

Chapter 2. Basics of Unit Testing

In this chapter, we will write and test a simple class. This will demonstrate how the "test first" approach introduced in Chapter 1 can be applied in practice. We'll also look at the use of "Design by Contract", and the form that unit tests take.

A Simple Example

Suppose we are implementing a collection class Relation representing a mathematical relation. A Relation of size N simply consists of a set of pairs of objects (ai, bi), where i = 1, 2,…, N. The set of objects {ai} is called the domain, and the set of objects {bi} is called the range.

A Simple Example

A relation between the letters {A, B, C} and the numbers {1, 2, 3, 4} is ...

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

Start Free Trial

No credit card required