Skip to main content

Claude Prompt to Build a Test Data Factory and Fixture System

Build a reusable test data factory with realistic fake data, relationship handling, states, and named fixture sets for common scenarios.

Vul de plaatshouders in

Edit the values, then copy your finished prompt.

Jouw Prompt
prompt.txt

                                

What this prompt does

This prompt designs a reusable test data factory system. You name the [framework], the [models] involved, and the AI builds a factory per model using [faker_library] for realistic fake data, defines [states] for common variations, wires relationships (belongsTo, hasMany, belongsToMany) with correct foreign keys, adds sequences for unique fields, and assembles named fixture sets for scenarios like [scenarios]. It also produces a seeder and helper methods for complex setups, following [language] conventions.

The structure works because it replaces fragile, hand-rolled test data with composable building blocks. States and relationships mean any test can request exactly the data shape it needs, and named fixture sets turn recurring scenarios — expired trial, team with billing — into one-line setups. That makes every downstream test faster to write and easier to read. The [models] and [states] variables tailor the whole system to your domain.

When to use it

  • You are cleaning up flaky tests caused by ad-hoc data setup.
  • You need factories with realistic data for [models] instead of hardcoded fixtures.
  • You want [states] like trial, premium, or archived available across the suite.
  • You need relationship-aware factories that set foreign keys correctly.
  • You want named fixture sets for recurring [scenarios].
  • You are seeding a complete test environment in one command.

Example output

You get a factory file per model in [framework] style, each producing realistic [faker_library] data with defined [states] and relationship handling. On top sit named fixture builders for your [scenarios], a seeder that assembles a full test environment, and helper methods for compound setups like a user with a subscription and team.

Pro tips

  • List [models] in dependency order so relationship wiring is unambiguous.
  • Choose [states] that map to real business conditions your tests assert against, not arbitrary labels.
  • Define [scenarios] precisely — each becomes a reusable fixture, so vague scenarios produce vague helpers.
  • Match [faker_library] to your framework's idiom so generated data uses the right API.
  • Use sequences for any genuinely unique field (emails, slugs) to avoid collisions in larger runs.
  • Review the relationship code; the model can guess foreign-key names that differ from your schema.

Frequently Asked Questions

Does it handle model relationships correctly?
It generates belongsTo, hasMany, and belongsToMany wiring with foreign keys for your `[models]`. Because it infers key names, review the relationship code against your real schema — custom or non-conventional foreign keys may need manual correction after generation.
What are factory states and why use them?
States are named variations of a factory, like trial or premium from `[states]`. They let a test request a specific condition in one call instead of overriding many fields manually, keeping setup concise and making the intent of each test obvious.
Can I use this outside Laravel?
Yes. Set `[framework]`, `[faker_library]`, and `[language]` to your stack. The concept of factories, states, relationships, and fixtures applies broadly, though the exact API — for example a Node factory library — will differ from Laravel's factory syntax.
How do the named fixture sets help?
Each `[scenarios]` entry becomes a one-line builder that assembles a complete data situation, such as a team with billing. This removes repetitive multi-model setup from individual tests, making them shorter, more readable, and far less prone to drift over time.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

Meer in Testing & QA Automation Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

Claude Code Expert · Online

👋

Hey there!

Quick Actions

WhatsApp Instant reply

Chat on WhatsApp

+880 1723 741224 · Instant reply

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

[email protected]

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support