Test Data Factory
ELI5 — The Vibe Check
A Test Data Factory generates realistic test data on demand. Instead of copying production data or maintaining huge fixture files, you call a factory: 'give me a user with 3 orders and a premium subscription.' Clean, consistent, and each test gets exactly the data it needs.
Real Talk
Test data factories (Factory Bot, Fishery, Factory Boy) generate test fixtures programmatically with configurable attributes, traits, and associations. They support default values, sequences, lazy evaluation, and nested object creation. Factories produce consistent, isolated test data without maintaining static fixtures.
Show Me The Code
// Using Fishery
const userFactory = Factory.define<User>(({ sequence }) => ({
id: sequence,
name: `User ${sequence}`,
email: `user${sequence}@test.com`,
role: 'member'
}));
const admin = userFactory.build({ role: 'admin' });
When You'll Hear This
"The test data factory generates a complete user with orders and payments in one line." / "Factories are better than fixtures — they're always in sync with the current schema."