Test Smells
Test smells are indicators of problems in test code — patterns that make tests fragile, unreadable, or unreliable.
- Mystery Guest — the test uses external resources, and thus is not self-contained.
- Resource Optimism — the test makes assumptions about the existence/absence of state from external resources.
- Test Run War — test code fails when multiple programmers are running them (shared state collisions).
- General Fixture — a fixture is over-general: it sets up more than any one test needs, making the tests harder to understand.
- Eager Test — a single test checks too many methods at once. Solution: separate into tests that each check one method.
- Lazy Test — several tests check the same method using the same fixture (duplication with little additional signal).
- Assertion Roulette — many assertions in one test, with no descriptive messages, making it hard to know which one failed.
- Indirect Testing — a test exercises its target class only through another class, so failures are hard to attribute.
- For Testers Only — the production class exposes methods that exist only to support testing.
- Sensitive Equality — the test relies on
toStringor similar fragile equality that breaks when formatting changes. - Test Code Duplication — the same test logic is copy-pasted across multiple tests instead of being factored out.