Test data management is how you create, control and clean up the data your tests depend on. For end-to-end tests that means users, accounts, orders, settings and anything else a journey needs before step one, plus everything it leaves behind afterwards.
Get it wrong and tests fail for reasons that have nothing to do with your code. Most "flaky" E2E suites we hear about turn out to be test data problems.
Why test data breaks end-to-end tests
Unit tests mock their data and never touch a shared database. E2E tests run against a real app with a real database, so every test changes the state the next test sees. Four failure patterns keep coming up.
Collisions. Two tests use the same account at the same time. One changes the plan while the other is checking the invoice. Both are correct and one of them fails. On calls we reviewed for this piece, teams sharing a single staging environment described exactly this: concurrent test runs from different squads breaking each other.
Leftover state. A test passed yesterday and left a draft order behind. Today the cart isn't empty when the next test expects it to be.
Order dependency. Test B only passes because test A ran first and created the project it uses. Run B alone, or in parallel, and it fails. In an empirical analysis of flaky tests published at FSE 2014, Luo, Hariri, Eloussi and Marinov found test order dependency behind 12% of the flaky tests they studied, with async waits (45%) and concurrency (20%) ahead of it.
Drift between environments. Data that exists in staging doesn't exist in the preview, or production has a customer type that staging never had. Several teams on our calls described false failures that came down to differences between dev, staging and production data rather than bugs.
Martin Fowler's Eradicating Non-Determinism in Tests lists lack of isolation as the first cause of non-deterministic tests, and his fix applies directly: each test should set up the state it needs and not rely on anything else.
Four ways to get test data
| Approach | How it works | Pros | Cons |
|---|---|---|---|
| Seed scripts and fixtures | A script loads known records into an empty database before the run | Fast, repeatable, in version control | Drifts from what production data looks like; needs updating with every schema change |
| Create through the API | Each test calls your API to create the user, project or order it needs | Isolated per test, uses real business logic | Needs an API for everything; slower than seeding |
| Create through the UI | The test signs up and builds its own state by clicking | Tests the journey for real | Slow; a broken sign-up fails every test |
| Copy production, masked | A snapshot of production with personal data replaced | Realistic shapes and edge cases | Privacy risk if masking fails; large; goes stale |
Enterprise test data management tools focus on the fourth row: subsetting and masking production databases so regulated teams can test with realistic data. For most product teams running E2E tests, the first two rows do most of the work, and the third is reserved for the journeys you're actually testing.
A common split:
- Seed reference data that every test reads but none change: plans, product catalog, countries, feature flags.
- Create through the API the records a test will change: its own user, its own project, its own order.
- Create through the UI only when creating it is the thing under test.
Isolating test data
Isolation means no two tests can see each other's changes. In rough order of strength:
- Unique values per test. Add a run ID or timestamp to everything a test creates:
qa+run-8213-checkout@example.com, "Project 8213". Cheap, and it stops most collisions. - One account per parallel worker. Playwright's authentication docs describe this pattern for tests that change server-side state, keyed on the worker's index.
- One tenant or workspace per run. If your product is multi-tenant, create a fresh organisation for each test run and point every test at it.
- One database per environment. Each preview deployment gets its own database or database branch, seeded at startup. Nothing a pull request's tests do can reach another pull request.
Per-preview databases make testing each pull request practical. Teams on our calls without per-PR previews were sending every branch's tests to one shared staging, and the collisions grew with the team. Neon, PlanetScale and Supabase all offer database branching, and most preview setups can seed a fresh database on deploy. Our guide to preview environments covers the options.
Cleaning up
Every E2E test that creates data should have a plan for removing it. Options, from tidiest to most pragmatic:
- Teardown in the test. Delete what you created in an
afterEachor a fixture. Runs even when the test fails, if you set it up that way. - Throw the environment away. When the preview is deleted, its database goes with it. The cleanest cleanup is not having to do any.
- Tag and sweep. Mark everything tests create with a prefix or flag, and run a scheduled job that deletes tagged records older than a day. Useful on long-lived staging.
- Reset on a schedule. Restore staging from a known snapshot every night. Blunt, but it stops slow drift.
Test data in production
Testing in production after a deploy is useful, and it needs rules:
- Use dedicated test accounts, flagged in your database so analytics, billing and email campaigns ignore them.
- Use your payment provider's test mode or a dedicated low-value product, never a real customer's card.
- Prefer read-mostly checks. Create only what you can delete, and delete it.
- Keep credentials for test accounts out of the repository and out of anywhere shared widely.
Mocks vs real data
Mocking was the most commonly reported pain point with testing in the State of JavaScript 2024 survey, ahead of complex setup and slow tests. That matches what we hear. Mocks make tests fast and stable, and they also drift from the real service until a test passes against behaviour that no longer exists.
Daniel Mauno Pettersson, our co-founder and CEO, argues for testing as close to production as possible and moving away from mocked data wherever you can. In practice that means mocks for unit tests, sandboxes for integration and E2E tests, and real data only in the per-environment database you can throw away.
A test data checklist for E2E suites
- Every test creates or claims the data it changes, and nothing else changes it.
- Shared reference data is read-only for tests.
- Generated values include a run ID.
- Parallel workers never share an account.
- Each preview environment has its own seeded database.
- Created data is cleaned up by teardown, environment deletion or a sweep.
- Test accounts are flagged and excluded from analytics and billing.
- Credentials live in a secrets store, not in test files.
Where QA.tech fits
QA.tech, an AI testing platform, has two limits that matter here. Its agent can't write directly to your database, so seed data has to come from your own scripts, your API or the UI. And it doesn't clean up the data it creates, so the tag-and-sweep or throwaway-environment patterns above still apply. Test credentials are stored as configs and passed to the model during runs, so use dedicated test accounts rather than anyone's real login.
Inside those limits, the platform covers most of the patterns in this piece. Configs hold credentials and test values, with overrides per environment, so the preview, staging and production runs each use their own accounts. A test can call your API mid-run to create the record it needs. Dependencies pass output values between tests, so a test that creates an order hands its order number to the test that refunds it. Tests without dependencies run in parallel, each in its own browser session, with a concurrency limit you can set per environment.
FAQ
What is test data management? Test data management is the practice of creating, controlling, protecting and cleaning up the data that tests use, so tests are repeatable and don't interfere with each other or with real customers.
What is test data in software testing? Test data is any input or stored state a test depends on: user accounts, products, orders, settings, files and the values typed into forms.
How do you generate test data? Through seed scripts or fixtures for reference data, API calls from the test for data it will change, and data libraries such as Faker for realistic names, addresses and emails. Regulated teams also mask copies of production.
Should you use production data for testing? Only masked, and only when you need realistic shapes and edge cases. Unmasked production data in test environments is a privacy and compliance risk. Most E2E tests work better with data they create themselves.
How do you stop parallel tests from sharing data? Give each test unique values, give each parallel worker its own account, and give each preview environment its own database. Never let two tests change the same record.
How do you clean up test data after E2E tests? Delete it in test teardown, throw away the whole environment when the run ends, or tag test data and delete tagged records on a schedule.
