← All posts

AI: generating realistic test data without copying your customer database

Copying production data to test with is tempting and risky. How to use a coding assistant to produce realistic, reproducible test datasets that contain no real data at all.

AI: generating realistic test data without copying your customer database

Key points

  • Ask the assistant for a generator script, not the data itself: the output is reproducible and reviewable.
  • Write edge cases (apostrophes, accents, empty fields) by hand; let the generator supply the volume.
  • Use reserved domains such as example.com: a test email must never be able to reach a real person.

Testing a billing screen or an import needs data that looks like the real thing. The most common shortcut is to copy the production database onto a dev machine, and it’s also the riskiest: personal data ends up on laptops, in backups and sometimes with contractors who had no business seeing it. Coding assistants offer a better route, provided you ask the right way.

Ask for a generator, not for data

Ask an assistant for “200 customers as JSON” and you get a frozen blob, usually repetitive, that nobody reviews and that has to be regenerated whenever the schema changes. On our projects we ask for a script instead:

Write a PHP script that generates customer fixtures with fakerphp/faker,
en_GB locale, fixed seed so the output is reproducible.
Constraints: emails on reserved domains only (example.com),
200 random customers PLUS a hand-written list of edge cases:
apostrophe, accents and hyphens, very long name, empty name.
Output: fixtures/customers.json. No real data.

A script takes a minute to review, lives in version control with the project and can be re-run when the data model changes. The fixed seed means two developers get identical data, which avoids tests that pass on one machine and fail on another.

The reviewed result

Here’s the script after review. We kept the library the assistant suggested but rewrote the edge-case list:

<?php
require __DIR__ . '/vendor/autoload.php';

$faker = FakerFactory::create('en_GB');
$faker->seed(2026); // same data on every run

// The cases that actually break applications, written by hand
$customers = [
    ['name' => "O'Connor", 'email' => 'apostrophe@example.com'],
    ['name' => 'Zoë Lefèvre-Saint-Hilaire', 'email' => 'accents@example.com'],
    ['name' => str_repeat('Very long name ', 15), 'email' => 'long@example.com'],
    ['name' => '', 'email' => 'no-name@example.com'],
];

for ($i = 0; $i < 200; $i++) {
    $customers[] = [
        'name'  => $faker->name(),
        'email' => $faker->unique()->safeEmail(),
    ];
}

@mkdir(__DIR__ . '/fixtures');
file_put_contents(
    __DIR__ . '/fixtures/customers.json',
    json_encode($customers, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)
);

safeEmail() only produces addresses on domains reserved for examples, and unique() prevents duplicates that would break a unique constraint in the database. Check details like these in the library’s documentation rather than taking the assistant’s word for it: that’s exactly where it tends to slip.

Edge cases aren’t random

Random generators produce data that’s too tidy: short names, no apostrophes, every field filled in. Yet apostrophes are what break a badly escaped query, long names are what overflow a PDF invoice, and empty fields are what trigger PHP warnings. We write those cases ourselves, based on the bugs the project has already hit.

The assistant is useful for filling gaps, though: ask “which edge cases am I missing for an address field?” and sort through the answer. Be wary of identifiers with check digits (IBANs, company registration numbers): assistants happily invent values that look right but fail validation. Generate them with a tested function, or run them through your own validator.

Keep test data harmless

One simple precaution avoids an embarrassing incident: no test email address should belong to a real domain. We’ve seen staging environments send invoice reminders to made-up addresses that, unluckily, existed. example.com and the .test top-level domain are reserved for this purpose and will never receive anything.

Apply the same thinking to phone numbers and postal addresses if they can trigger a text message or a letter. And if you really must start from real data, anonymise it before it leaves production, never afterwards.

FAQ

Can I share my database schema with the assistant?

Yes. Table structure contains no personal data and noticeably improves the output. What you shouldn’t share is the rows themselves.

Should generated fixtures go into version control?

We commit the script and, for small datasets used by automated tests, the generated file too. That way a code review shows when test data changes.

Want to test your application without exposing your customers’ data? We set up realistic, reproducible and compliant test environments.

Share LinkedIn Facebook X WhatsApp
</>

webtestudio

Web agency: custom WordPress sites, premium themes and SaaS software.

Discuss your project →