How do you prepare test data?
Test data must be sufficient, isolated, reproducible and safe. It covers equivalence classes, boundaries, roles and states, each test has its own, a script creates it, and it holds no real personal data. The most reliable way is for the test to create its data through an API or SQL. A production copy is used only when irreversibly anonymised.
QA Fundamentals · Test documentation
A test passed yesterday and fails today because another test “used up” the test user. Where do you get data?
A shared account “test@test.com” with a balance of 5,000 UAH passed every case on Monday. On Tuesday someone made a transfer, the balance became 4,000 and the limit boundary case fails. There is no product defect, the data broke. Test data is part of every case’s preconditions and is treated like code: created, versioned, cleaned up. Below: where it comes from, what requirements it meets and why “create it inside the test” usually wins.
How it works and why. Good test data has four properties. Sufficient: it covers equivalence classes, boundaries, roles and states (a new user, one with history, blocked, different tariffs). Isolated: each test has its own, so order and parallel runs do not interfere. Reproducible: a script creates it, not hands, so the same state can be obtained at any moment. Safe: it holds no real personal data. ISTQB counts preparing test data as part of test implementation, and its requirements are recorded in the plan.
The life of test data
Where data comes from. Four sources, and they are not mutually exclusive:
| Source | Plus | Minus |
|---|---|---|
| Created by the test (API, SQL, factory) | isolated, reproducible | needs an API or database access |
| A ready set (seed, fixtures) | fast, stable | goes stale, tests share it |
| An anonymised copy of production | realistic volume and “dirty” data | hard to anonymise, a leak risk |
| Generated synthetic data | safe, any volume | may lack real anomalies |
Worked example: from a shared account to own data. For the limit cases we list the users we need. Every row is a state a script creates before the test:
User Limit Used Balance Purpose
new-user 10,000 0 5,000 a basic transfer
near-limit 10,000 9,000 5,000 limit boundary (case 014)
at-limit 10,000 10,000 5,000 refusal because of the limit
blocked 10,000 0 5,000 blocked user, refusal
big-tariff 50,000 0 80,000 another tariff
Creation looks like a call to a service endpoint of the test environment (an example):
POST /internal/test/users
Content-Type: application/json
{
"email": "qa+limit-0142@example.test",
"dailyLimit": 10000,
"usedToday": 9000,
"balance": 5000
}
A shared account or own data
Shared test@test.com
All tests share one state. The result depends on who ran what and when, and a failure has to be investigated like a defect.
A user per test
The test creates a user with the needed state and a unique email. Parallel runs do not interfere and the state is always known.
Limits and alternatives. A production copy gives realistic volume and shape of data but brings responsibility: masking a name is not enough, because under GDPR pseudonymised data is still personal and anonymisation must be irreversible. So generating data is safer. Time-dependent data (expiry dates, the day boundary) is better set explicitly than waited for. Load tests need large volumes, usually generated by a script. When there is no API to create data, direct SQL or a template restored from a database snapshot helps.
Common mistakes.
- Using real customer data “only in the test environment”: a personal data leak waiting for its moment.
- Covering only valid values: empty, boundary, very long ones and special characters stay unchecked.
- Not cleaning up: the database fills, uniqueness breaks, queries start returning extra rows.
- Not writing down where the data lives and how to restore it: a month later the whole team is searching.
Check yourself
A limit boundary case fails every other time. There is no defect. What is the likeliest cause and what to change?
Answer
Shared data: another test or person changed the balance or used limit. Each test should create its own user with a known state and a unique email, set up through API or SQL.
Why is a masked production copy (names and emails replaced) not enough to call the data safe?
Answer
Masking a few fields does not make data anonymous: the rest can be matched to identify a person. Pseudonymised data stays personal under GDPR. Generating synthetic data or anonymising irreversibly is safer.