Llewellyn Falco (here) and Arlo Belshee (here) both talk about the way that tests can provide the value of "specification": that tests can explain to another human what the program is supposed to do.
How does this compare to the values of catching bugs, informing design, and psychological reward? There's a subtle way in which focusing your energy on specification is hugely important.
What does it mean for to be a good spec?
- Name of a test is business value oriented.
- Expresses a single example of a business rule.
- Uses terminology from the problem domain.
- Meant to be read by a human. (programmer, not customer)
- At the appropriate level of abstraction for a human reader.
- Test doesn't make any non-business-value demands
This gets you the design feedback you need. You can only meet the goal of "test as spec" if you listen to the design feedback. You can't have a bunch of setup code (including mocks); that would distract from the core message of the test. The correct terminology gets pushed in to the system under test. These short, simple, straightforward tests are only possible when code is decoupled, and when each business rule is expressed in exactly one place (DRY).
Simple, decoupled tests are inherently fast.
When they fail, they tell you clearly why the failure matters.
It also gets you the comprehensive safety net: if you're focusing your attention on writing and satisfying the spec, all your code will have purpose and will will be covered by tests.
Because the test only makes demands for for business value, you are free to refactor without unnecessarily breaking tests.
This value appears when you focus on how tests are read, but also delivers value when tests are run and written.Simple, decoupled tests are inherently fast.
When they fail, they tell you clearly why the failure matters.
It also gets you the comprehensive safety net: if you're focusing your attention on writing and satisfying the spec, all your code will have purpose and will will be covered by tests.
Because the test only makes demands for for business value, you are free to refactor without unnecessarily breaking tests.