Back to Blog
Developer Tools

Generate Test Data With UUIDs โ€” Creating Mock API Responses for Development

2026-06-03 5 min read

Good test data has realistic-looking IDs, timestamps, and structured relationships. Here is how to generate test data that mirrors production.

Writing tests without realistic test data is how you end up with tests that pass in development and fail in production. UUIDs as IDs, realistic names and emails, and proper date ranges make your tests actually useful. Here's how to generate all of it.

UUIDs for test IDs

Never use sequential numbers like 1, 2, 3 as test IDs. Real systems use UUIDs, and code that works with sequential IDs sometimes breaks with UUID strings. Use real UUIDs in tests:

// Generate test data with proper UUIDs
const testUser = {
  id: crypto.randomUUID(),
  name: "Alice Test",
  email: "alice@example.com",
  createdAt: new Date().toISOString(),
};

// Or a factory function
function createTestUser(overrides = {}) {
  return {
    id: crypto.randomUUID(),
    name: "Test User",
    email: `test-${Date.now()}@example.com`,
    role: "user",
    active: true,
    ...overrides,
  };
}

Seeding a database with test data

// Generate 100 test users
const users = Array.from({ length: 100 }, (_, i) => ({
  id: crypto.randomUUID(),
  name: `User ${i + 1}`,
  email: `user${i + 1}@example.com`,
  createdAt: new Date(Date.now() - Math.random() * 90 * 24 * 60 * 60 * 1000),
}));

// Insert into database
await db.users.createMany({ data: users });

Faker.js for realistic data

For tests that need realistic-looking data rather than just valid data, Faker.js generates names, addresses, emails, phone numbers, and more:

import { faker } from "@faker-js/faker";

const testUser = {
  id: faker.string.uuid(),
  name: faker.person.fullName(),
  email: faker.internet.email(),
  phone: faker.phone.number(),
  address: {
    street: faker.location.streetAddress(),
    city: faker.location.city(),
    country: faker.location.country(),
  },
};

Deterministic test data

Random test data can make tests flaky. For tests that need to be reproducible, seed the random number generator with a fixed value:

faker.seed(12345); // always produces the same sequence
const name = faker.person.fullName(); // always "Alice Johnson" (or whatever)

Generate UUIDs for test data quickly with our UUID Generator.

uuid test-data mock api developer

More Articles