O'Reilly logo

Test Driven Development: By Example by Kent Beck

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 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 ...

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