Create Seed Data for Automated Testing

Generate deterministic, reproducible test data for unit tests, integration tests, and E2E test suites. Leverage the fixed seed for consistent fixtures.

Use Cases

Detailed Explanation

Reproducible Test Data

Automated tests need deterministic data — every test run should use the exact same input. The seed generator’s deterministic pseudo-random number generator (PRNG) makes this possible.

How Determinism Works

The generator uses a seeded PRNG (xoshiro128**). Given the same:

  1. SQL schema
  2. Row count
  3. Seed number

The output is byte-for-byte identical every time. This means you can generate your test data once, verify it, and be confident that future regenerations produce the same result.

Workflow for Test Suites

1. Define your schema (CREATE TABLE statements)
2. Generate seed data with a fixed seed (e.g., seed = 42)
3. Export as JSON for fixtures or SQL for database setup
4. Commit the generated file to your test directory
5. Reference it in your tests:
   - beforeAll: INSERT the seed data
   - afterAll: DELETE or rollback

JSON Fixtures Example

Export seed data as JSON and import it in your test:

import users from './fixtures/users.json';

describe('UserService', () => {
  beforeAll(async () => {
    await db.users.createMany({ data: users });
  });

  it('finds user by email', async () => {
    const user = await userService.findByEmail(users[0].email);
    expect(user).toBeDefined();
    expect(user.first_name).toBe(users[0].first_name);
  });
});

SQL Setup Scripts

For integration tests that run against a real database, export seed data as SQL INSERT statements and run them in your test setup:

-- test/setup.sql (generated by Database Seed Generator)
INSERT INTO users ("first_name", "last_name", "email") VALUES ('James', 'Smith', 'james.smith42@gmail.com');
...

Benefits of Deterministic Seeds

  • Reproducible failures: When a test fails, you can re-run it with the exact same data
  • Code review: Reviewers can regenerate the fixture to verify it
  • CI consistency: Every CI run uses identical data, eliminating flakiness from random data

Use Case

Your team runs integration tests against a PostgreSQL database in CI. Each test run needs a consistent set of users, products, and orders. You generate the seed data once with a fixed seed, commit the SQL file, and load it in the test setup step.

Try It — Database Seed Generator

Open full tool