BuddingConcept
Readable Tests
A test is documentation that happens to execute. Tell the reader what you’re testing, not that you’re testing (Henney): name and body should let a reader reconstruct the intended behavior without opening the production code. Martin goes further: readability is perhaps even more important in tests than in production code.
Readability is what diagnosability degrades into at failure time: an unreadable test that fails tells you nothing. Part of Test Desiderata.
Measuring: comprehension audits and test-smell counts (assertion roulette, conditional test logic), both honest but soft. Thresholds need team calibration; there is no universal number.
Sources
- Kevlin Henney, Program with GUTs: “tell the reader what you’re testing, not that you’re testing.” (GUTs = Good Unit Tests.)
- Robert C. Martin, Clean Code, 2nd ed., ch. 15 (“Clean Tests”): readability is perhaps even more important in tests than in production code. (In the 1st edition this is ch. 9, “Unit Tests”.)