Test Data Management

Test Data

// Definition

Provisioning, masking, refreshing, and tearing down data needed by tests. Done well, it's invisible. Done badly, it's the reason a third of tests fail on Mondays.

// Code Example

TypeScriptTest data factory with overrides
TypeScript
import { faker } from '@faker-js/faker';

type User = { id: string; email: string; role: 'admin' | 'user' };

const buildUser = (overrides: Partial<User> = {}): User => ({
  id: faker.string.uuid(),
  email: faker.internet.email(),
  role: 'user',
  ...overrides,
});

// Defaults for most tests
const user = buildUser();
// Override only what matters for this case
const admin = buildUser({ role: 'admin', email: 'admin@example.com' });

// Related terms

Learn more · Git for QA

Chapter 5 · Lesson 2: Managing Test Data and Fixtures in Git