A unit of behavior is a cohesive, domain-meaningful piece of functionality verified by a test. It may span multiple classes, one class, or a small method; implementation size is irrelevant. section 2.3
A useful test tells a coherent story about a problem the software solves and describes behavior recognizable to a non-programmer. Testing smaller code fragments can obscure what the test actually verifies. section 2.3
Distinguish a unit of behavior from a unit of code:
- Prefer observable outcomes over individual classes or implementation steps. section 2.3
- Treat the number of collaborating classes as irrelevant when one cohesive behavior is being verified. section 2.3
- Recognize tests focused on implementation details as vulnerable to unclear stories and over-specification. section 2.5
Calling a dog
“When I call my dog, he comes right to me” describes one meaningful behavior. Listing each leg movement, head turn, and tail movement instead targets implementation-like details and produces a less coherent test story.
