Generate Test Data Fixtures from a Schema
Reads a data schema (JSON Schema, TypeScript type, or table description) and returns four explicit fixture groups: happy path, boundary, invalid, and edge cases. Edge group must include Unicode, RTL, emoji, and injection payloads. Output is a ready-to-import JSON file.
When to use it
- You're seeding a test database and need realistic + adversarial fixtures.
- You're writing parameterized tests and need fixture arrays grouped by intent.
- You're testing input validation and want consistent boundary/edge coverage across fields.
- You're auditing existing test data for missing edge cases (Unicode, injection, max length).
The prompt
<role>You are a test data engineer who has been burned by Unicode and injection edge cases more times than you'd like to admit. You generate fixtures that find bugs in input handling, not fixtures that pass.</role> <context>Fixtures are consumed by parameterized tests. They live in version control as JSON. Each fixture file has four named arrays: happy, boundary, invalid, edge. Edge MUST include Unicode (BMP + supplementary), RTL languages (Arabic / Hebrew), emoji, zero-width chars, and at least one injection payload per string field.</context> <task>For the schema I provide, generate a fixtures JSON with four arrays:- happy: 3-5 valid representative records- boundary: valid records sitting exactly on each numeric/length limit (min and max), one per limit- invalid: records that should fail validation, one per rule, including just-outside values (min-1, max+1) for every limit- edge: 5-8 records including Unicode (multiple scripts), RTL, emoji, zero-width, null, empty string, max-length string at the boundary, and an injection payload per string field</task> <input>Schema (JSON Schema, TS type, or table): {schema}Additional constraints: {constraints}</input> <constraints>- Output is a single JSON object with four named arrays that parses with JSON.parse: no comments, no code expressions like 'a'.repeat(500); write long strings out in full.- Every record must conform to the field shape (so they can be deserialized): invalid means rule-violation, not malformed JSON.- Include a 'why' field on every boundary, invalid and edge record explaining what rule it tests.- Use realistic-looking values, not "foo" / "bar".- For injection payloads, include at minimum: SQL ('; DROP TABLE x;--), XSS (<script>alert(1)</script>), template ({{7*7}}).</constraints> <output_format>A JSON code block with the fixtures object, followed by a 1-2 sentence "Notes" paragraph listing any fields you couldn't generate edge cases for and why.</output_format> <approach>Before writing, identify which edge cases this schema's field types are vulnerable to.</approach>## RoleTest data engineer. Specializes in fixtures that find input-handling bugs (Unicode, injection, boundaries). ## ContextJSON fixtures in version control. Four arrays per file: happy, boundary, invalid, edge. Edge MUST include Unicode + RTL + emoji + zero-width + 1 injection payload per string field. ## TaskFor the schema below, produce fixtures JSON with: happy (3-5), boundary (valid records exactly on each min/max limit), invalid (one per rule, plus min-1 / max+1 for every limit), edge (5-8 covering Unicode/RTL/emoji/zero-width/null/empty/max/injection). ## Input- Schema: {schema}- Additional constraints: {constraints} ## Constraints- Single JSON object with the four named arrays; must parse with JSON.parse (no comments, no code like 'a'.repeat(500): write long strings in full).- All records conform to field shape (so they deserialize).- 'why' field on boundary, invalid and edge records explaining what rule is tested.- Realistic values, not foo/bar.- Injection payloads must include SQL, XSS, template-injection. ## Output formatJSON code block + 1-2 sentence Notes paragraph on uncovered fields. ## ApproachList the schema's edge-case vulnerabilities before generating values.Task: Generate test fixtures from a schema. Output schema:{ "happy": [...], "boundary": [...], "invalid": [...], "edge": [...]} For 'boundary', 'invalid' and 'edge' records, include "why": string explaining the rule being tested. Input:- schema (JSON Schema, TypeScript type, or column list): {schema}- constraints (optional): {constraints} Rules:- happy: 3-5 valid records- boundary: valid records exactly on each min/max limit, one per limit- invalid: one record per rule, plus min-1 / max+1 for every limit- edge: 5-8 records covering Unicode (BMP + supplementary), RTL, emoji, zero-width, null, empty, max-length, injection payloads (SQL, XSS, template) Output ONLY the JSON object. It must parse with JSON.parse: no comments, no code expressions, long strings written in full.Example
Input
Schema (TypeScript type):
{
email: string; // valid email format, max 254 chars
username: string; // 3-20 chars, alphanumeric + underscore
age: number; // integer 18-120
bio?: string; // optional, max 500 chars
role: 'user' | 'admin' | 'guest';
}Output
```json
{
"happy": [
{ "email": "alice@example.com", "username": "alice_42", "age": 28, "bio": "Software engineer in Berlin.", "role": "user" },
{ "email": "bob@example.org", "username": "bob_z", "age": 45, "role": "admin" },
{ "email": "carol@example.net", "username": "carol99", "age": 19, "bio": "", "role": "guest" }
],
"boundary": [
{ "email": "x@y.io", "username": "abc", "age": 18, "role": "user", "why": "username min length 3 (on)" },
{ "email": "x@y.io", "username": "twenty_chars_exactly", "age": 18, "role": "user", "why": "username max length 20 (on)" },
{ "email": "x@y.io", "username": "abcd", "age": 120, "role": "user", "why": "age upper boundary 120 (on)" },
{ "email": "x@y.io", "username": "abcd", "age": 18, "role": "user", "bio": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "why": "bio max length 500 (on)" },
{ "email": "a@b.c", "username": "abcd", "age": 18, "role": "user", "why": "email shortest possible valid form" }
],
"invalid": [
{ "email": "no-at-sign.com", "username": "abcd", "age": 25, "role": "user", "why": "email missing @" },
{ "email": "x@y.io", "username": "ab", "age": 25, "role": "user", "why": "username below min length 3" },
{ "email": "x@y.io", "username": "twenty_one_chars_long", "age": 25, "role": "user", "why": "username above max length 20" },
{ "email": "x@y.io", "username": "with space", "age": 25, "role": "user", "why": "username contains space (not alphanum/underscore)" },
{ "email": "x@y.io", "username": "abcd", "age": 17, "role": "user", "why": "age below min 18" },
{ "email": "x@y.io", "username": "abcd", "age": 25, "role": "owner", "why": "role not in enum" }
],
"edge": [
{ "email": "пользователь@пример.рф", "username": "user_ru", "age": 30, "bio": "Тестовый пользователь", "role": "user", "why": "Cyrillic in email local-part + domain (IDN)" },
{ "email": "x@y.io", "username": "user_jp", "age": 30, "bio": "日本語のテキスト", "role": "user", "why": "Japanese (CJK) in bio" },
{ "email": "x@y.io", "username": "user_ar", "age": 30, "bio": "مرحبا بالعالم", "role": "user", "why": "Arabic (RTL) in bio" },
{ "email": "x@y.io", "username": "user_em", "age": 30, "bio": "🚀🎉💯", "role": "user", "why": "Emoji (supplementary plane)" },
{ "email": "x@y.io", "username": "user_zw", "age": 30, "bio": "vis\u200bible", "role": "user", "why": "Zero-width space inside text" },
{ "email": "x@y.io", "username": "abcd", "age": 18, "bio": null, "role": "user", "why": "Explicit null for an optional string field (absent is not the same as null)" },
{ "email": "x@y.io", "username": "abcd", "age": 18, "bio": "'; DROP TABLE users;--", "role": "user", "why": "SQL injection payload in bio" },
{ "email": "x@y.io", "username": "abcd", "age": 18, "bio": "<script>alert(1)</script>", "role": "user", "why": "XSS payload in bio" },
{ "email": "x@y.io", "username": "abcd", "age": 18, "bio": "{{7*7}}", "role": "user", "why": "Template injection in bio: must render literally, never as 49" }
]
}
```
Notes: injection payloads target bio only, because email, username and role are format-restricted and those payloads already fail validation there. Email-format edge cases (IDN, plus-addressing, 254-char limit) deserve a dedicated email-edge-cases fixture set.Common pitfalls
- Edge group ships without Unicode or injection because the model defaults to 'safe' fixtures: constraints must force them.
- Just-outside values (min-1, max+1) get skipped unless the prompt asks for them per limit: they belong in the invalid group.
- Model produces fixtures with `foo` / `bar` values: unrealistic data hides bugs that surface only with real-looking strings.
- Invalid records sometimes break JSON shape (extra/missing fields): should fail validation, not deserialization. Re-prompt if so.
Tips
- If the schema has 10+ fields, split into two runs (group by entity) to keep boundary coverage thorough.
- Append the resulting fixtures to a `*.fixtures.json` file with timestamp; let your tests load them: easy to extend.
- For database-seeded tests, also generate Foreign Key relationships explicitly (separate prompt run per relationship).
- Re-run the prompt when the schema changes; diff old vs new fixtures to find which test cases need refresh.
- Models miscount long strings: check every max-length value with the character counter before committing the fixtures.
FAQ
What's the difference between a fixture and a factory?
A fixture is static data committed to the repo. A factory generates data at test time via code (`createUser({age: 25})`). Use fixtures for representative + edge cases you care about catching every run. Use factories for combinatorial variation. Most projects need both.
How do I keep fixtures in sync with the schema?
Generate fixtures from the schema itself (this prompt). On every schema change, re-run the prompt and diff the output. Or auto-validate fixtures against the schema in CI: broken fixtures fail the build.
When should I randomize fixture values?
Randomize when you want fuzzing-style coverage (find any bug). Keep fixed values when you want reproducible regression tests (find this specific bug again). For most QA work, fixed > random because flaky failures are worse than missed bugs.
Should injection payloads live in the same file as happy-path data?
Yes, in the 'edge' group. Splitting them creates fragility: engineers forget to run the security suite. Keeping them together means any test loop covers them.