Deep dive
Good test data is minimal and purposeful:
- Factories reduce duplication and improve clarity.
- Snapshots or golden files should be reviewed and small.
- Isolation: clean DB or use transactions per test.
- Avoid brittle global fixtures shared by many tests.
Examples
Factory approach:
user = makeUser({ role: 'admin' })
order = makeOrder({ userId: user.id })
Common pitfalls
- Giant fixtures that hide intent.
- Sharing mutable fixtures across tests.
- Not cleaning up, causing order dependency.
Interview follow-ups
- When do you use factories vs fixtures?
- How do you seed data for E2E reliably?
- How do you keep fixtures in sync with schema changes?