Why hand-typed fixtures break tests, how to model fake data that behaves like production, and a workflow for JSON, CSV and XML test data.
Most test suites start with a handful of hand-typed records: a user called "John Doe", an email like test@test.com, an order total of 100. These fixtures pass every test because they were written to pass. They rarely contain the things that break real systems: names with apostrophes, addresses that wrap across three lines, emails with plus signs, prices with three decimal places, or arrays that are empty instead of populated.
The result is a test suite that is green locally and red in production. Realistic generated data closes that gap by producing values with the same shape, length distribution and edge cases you will see from real users, without copying any real personal data into your repository.
The fastest way to get useful fake data is to describe the structure once and let a generator fill it in. Take one real response from your API (with personal fields removed), or the JSON example from your OpenAPI spec, and treat it as the template. Every key keeps its name and nesting; every value is replaced with a generator that matches its meaning: firstName produces a first name, createdAt produces an ISO date, price produces a decimal.
Matching the meaning matters more than matching the type. A field typed as a string could be a UUID, a country code, a slug or free text, and each breaks different code. Pick the most specific generator available. If a field is an enum in your backend, restrict the generator to exactly those values so you do not produce data your API would reject.
Good test data is mostly ordinary with a controlled amount of weirdness. When you generate a batch of records, include some that exercise boundaries: optional fields set to null, empty arrays, maximum-length strings, zero and negative numbers where the domain allows them, dates at month and year boundaries, and Unicode characters in names.
Keep the volume realistic too. A list view that looks fine with five rows may collapse with five hundred. Generating 1,000 records takes the same effort as generating 10, and it surfaces pagination bugs, slow renders and missing indexes long before a customer does.
JSON is the natural choice for API mocks, front-end development and document databases. CSV is better for spreadsheet imports, bulk-loading relational tables with COPY or LOAD DATA, and handing data to non-developers. XML still matters for SOAP services, many payment and travel integrations, and enterprise import formats.
Generate in the format your consumer reads instead of converting by hand afterwards. Nested JSON objects flatten awkwardly into CSV columns, so if the destination is a table, design the template flat from the start (for example address_city rather than address.city).
Never seed test environments by copying production records, even with a few fields masked. It creates compliance risk under GDPR and similar laws, and masked data tends to leak back into screenshots, bug reports and demos. Generated data has no owner and no consent requirements.
Use reserved values where possible: example.com and example.org domains for emails (they are reserved by RFC 2606 and never deliver), phone numbers from ranges set aside for fiction, and card numbers from your payment provider's published test list. That way a generated record that escapes into a real system cannot reach a real person.
1. Copy one representative response or schema example. 2. Paste it into a generator and map each field to a specific data type. 3. Generate a small batch and eyeball it for values that look wrong. 4. Add edge-case rules for nullable fields and boundaries. 5. Generate the volume you need in the format your consumer reads. 6. Commit the template, not the output, so the data can be regenerated when the schema changes.
Committing the template instead of thousands of generated rows keeps your repository small and makes it obvious, in review, how test data is produced. When a new field is added to the API, one line in the template updates every fixture.