Chapter 19. Set the Table
When you begin writing tests, you will discover a common pattern (Bill Wake coined the term 3A for this).
-
Arrange— Create some objects.
-
Act— Stimulate them.
-
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 books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.