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 toString or 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.