Use Case

Deterministic Test Fixtures with MockHero Seeds

The Problem

Flaky tests are a plague on development teams. A common cause: test data that changes between runs. When your test asserts that the first user's email is a specific value but Faker generates a different email every time, the test passes locally and fails in CI.

Hardcoded fixtures solve the flakiness but create a maintenance burden. Every schema change requires updating every fixture file. For a project with 50 test files, that is hundreds of manual edits.

The Solution: MockHero API

MockHero's seed parameter produces identical output for identical input. Pass "seed": 42 and you get the exact same names, emails, UUIDs, and relationships every time. Change the schema and the data regenerates automatically.

Quick Setup

curl -X POST https://api.mockhero.dev/api/v1/generate \
  -H "x-api-key: mh_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
  "tables": [
    {
      "name": "products",
      "count": 3,
      "fields": [
        { "name": "id", "type": "uuid" },
        { "name": "name", "type": "product_name" },
        { "name": "price", "type": "decimal", "params": { "min": 10, "max": 100 } }
      ]
    }
  ],
  "format": "json",
  "seed": 12345
}'

Step-by-Step Guide

1. Define your test schema

Create a shared schema file that all tests reference. This is the single source of truth for your test data shape.

2. Get your MockHero API key

Sign up at mockhero.dev/sign-up.

3. Generate fixtures with a fixed seed

Write a fixtures/generate.mjs script that calls MockHero with a fixed seed and writes the results to JSON files.

4. Commit the fixtures

Since the data is deterministic, you can commit the JSON files. Regenerate them only when your schema changes.

5. Use in tests

Import the fixture JSON files in your test files. Assertions are stable because the data never changes between runs.

Complete Example

The fixture generator and test usage form the complete pattern. Run the generator once, commit the JSON, and your tests are stable forever (until you intentionally change the schema).

Why MockHero vs Faker / Manual Fixtures

  • Reproducibleseed parameter guarantees byte-identical output.
  • Self-updating — change the schema, re-run the generator, and fixtures match your new models.
  • Realistic — test with data that looks like production, not "Test User 1".

Get Started

Free tier, 1,000 rows/month. Sign up at mockhero.dev and end flaky tests with deterministic fixtures.

M

MockHero Team

Guides and tutorials for generating realistic test data with the MockHero API.

Start generating test data for free

1,000 rows/month on the free tier. No credit card required.

Get Your API Key

Related Articles