๐ WAYPOINT LESSON
AAA & Test Naming
โญโญ intermediateโณ 12 min read๐ Lesson 90 of 180
The three-block shape, one behavior per test, and names that read like specifications.
AAA and tests that read like specs
Every good test has three blocks, visibly separated:
// Arrange โ build the world
var cart = new Cart();
cart.add(new Item("pen", 200));
// Act โ one behavior
int total = cart.totalCents();
// Assert โ one expectation
assertEquals(200, total);
Discipline that scales:
- One behavior per test โ two asserts of the same behavior are fine; two behaviors are not
- Name = scenario + expectation:
total_includes_quantity_multiplier, nottestTotal - No logic in tests (no loops, no ifs) โ if you need logic, you're re-implementing the subject under test
- Tests are the first reader of your API: if arranging is painful, the API needs a builder or factory
A failing test message should tell you what broke without opening a
debugger โ that's why checkEq(actual, expected, "what") takes a label.