Why frozen test fixtures are a problem on large projects and how to avoid them
2 days ago
- #testing
- #best-practices
- #fixtures
- Frozen test fixtures become problematic in large projects because changes can falsely break many unrelated tests due to implicit assumptions.
- Bad solutions include creating new fixtures for each test (leading to bloated fixtures) or modifying fixtures ad-hoc within tests (reinventing factories poorly).
- The right solution is to write tests that only verify the specific property they are meant to test, avoiding dependencies on fixture details.
- Example 1: Instead of asserting exact collection matches, test inclusion/exclusion to avoid fixture freezes.
- Example 2: For ordered collections, test sorting properties rather than exact sequences to maintain flexibility.
- Fixtures and factories both have trade-offs; pragmatic developers use whichever (or both) suits the project best.