tdd: add tautological-test anti-pattern
Tests whose assertion is recomputed the way the code computes it pass by construction and give zero confidence. Add it as a peer of the existing implementation-coupling anti-pattern: a Philosophy principle, a per-cycle checklist gate, and a BAD/GOOD example pair in tests.md. Includes a patch changeset. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
a116824938
commit
43ea0884b0
3 changed files with 24 additions and 0 deletions
|
|
@ -13,6 +13,8 @@ description: Test-driven development. Use when the user wants to build features
|
|||
|
||||
**Bad tests** are coupled to implementation. They mock internal collaborators, test private methods, or verify through external means (like querying a database directly instead of using the interface). The warning sign: your test breaks when you refactor, but behavior hasn't changed. If you rename an internal function and tests fail, those tests were testing implementation, not behavior.
|
||||
|
||||
**Tautological tests** restate the implementation inside the assertion, so they pass by construction and give zero confidence. When the expected value is computed the way the code computes it — `expect(add(a, b)).toBe(a + b)`, snapshotting a figure you derived by hand the same way the code does, asserting a constant equals itself — the test can never disagree with the code: break the code wrong and the assertion breaks wrong with it. The expected value must come from an independent source of truth — a known-good literal, a worked example, the spec.
|
||||
|
||||
See [tests.md](tests.md) for examples and [mocking.md](mocking.md) for mocking guidelines.
|
||||
|
||||
## Anti-Pattern: Horizontal Slices
|
||||
|
|
@ -103,6 +105,7 @@ After all tests pass, look for [refactor candidates](refactoring.md):
|
|||
[ ] Test describes behavior, not implementation
|
||||
[ ] Test uses public interface only
|
||||
[ ] Test would survive internal refactor
|
||||
[ ] Expected values are independent literals, not recomputed from the code
|
||||
[ ] Code is minimal for this test
|
||||
[ ] No speculative features added
|
||||
```
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue