Fragile Test

Tests that fail due to unrelated changes.

Meszaros, xUnit Test Patterns

Signs of Use (Symptoms)

  • Tests break when UI formatting changes (but logic is unchanged).
  • Tests break when database schema changes (but behavior is unchanged).

Why it is bad (Consequences)

  • Maintenance burden: Tests require constant fixing.
  • Loss of trust: Developers disable or ignore fragile tests.

Refactoring Solution

  • Test behavior, not implementation.
  • Use mocks for volatile dependencies.
  • Avoid testing private methods.

Code example

Bad

Good