Test Data Setup
Workflow for creating maintainable test fixtures and factories
CLAUDE.md
When setting up test data:
- Create factory functions that generate valid test objects with sensible defaults.
- Allow overriding any field:
createUser({ role: 'admin' })to customize per-test. - Use realistic data: real-looking names, emails, and values — not “foo”, “bar”, “test123”.
- Create test data in each test’s setup, not in a shared global fixture that tests implicitly depend on.
- Clean up test data after each test to prevent state leakage.
- For database tests, use transactions that roll back after each test for fast, isolated cleanup.
Copy this workflow into your CLAUDE.md or agent config file so your agent follows this process automatically.