Chapter 19. Set the Table

When you begin writing tests, you will discover a common pattern (Bill Wake coined the term 3A for this).

  1. Arrange— Create some objects.

  2. Act— Stimulate them.

  3. Assert— Check the results.

Invoke test methodInvoke setUp firstInvoke tearDown afterwardInvoke tearDown even if the test method failsRun multiple testsReport collected results

The first step, arrange, is often the same from test to test, whereas the second and third steps, act and assert, are unique. I have a 7 and a 9. If I add them, I expect 16; if I subtract them, I expect –2; and if I multiply them, I expect 63. The stimulation and expected results are unique, but the 7 and the 9 don't change.

If this pattern repeats at different scales ...

Get Test Driven Development: By Example now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.