~/qa-guides

~/qa-guides/test-data-design

>_ Test Data Design: Practical Examples and Reusable Datasets

Build repeatable datasets with linked orders, role and workspace variations, controlled expiry times, and a filled manifest for setup, isolation, reset, and maintenance.

Test designTest dataTest fixturesData integrity

Published

Short answer

Test data design defines the input values, related records, initial states, and environmental conditions needed to exercise a test condition and evaluate its result. A useful dataset includes both the data to provide and the evidence that it is ready for the intended test.

For example, testing whether a read-only user can edit an order requires an existing editable order, a verified membership, a valid proposed change, and an expected unchanged result. An arbitrary account and order ID cannot establish which condition caused a rejection.

The ISTQB Test Analyst syllabus, section 1.3.5, discusses test data requirements including purpose, dependencies, coverage, maintainability, confidentiality, and aging. The worked examples below use one fictional order-entry application to make those concerns concrete. Its roles, business rules, records, and outcomes are teaching examples, not requirements for another product.

How test data design differs from input selection

Equivalence partitioning helps choose representatives from classes of inputs. Test data design also prepares the surrounding conditions that let the selected input reach the behavior under investigation.

A quantity of zero may be a useful invalid representative. However, a request containing that quantity might be rejected first because its customer does not exist, its product belongs to another workspace, or its user cannot edit the order. Those are different observations.

Keep three objects separate:

  • A fixture is a prepared starting arrangement, such as a workspace containing users, products, and orders.
  • A test input is the value or action applied to that arrangement, such as changing one quantity to zero.
  • An execution record captures the actual arrangement, input, result, and evidence for one run.

The same fixture can support several inputs, but only if each test receives the required starting state. Reusing a fixture definition does not mean letting every test mutate the same live records.

Dataset size is also separate from coverage. Twenty-four prepared records do not mean twenty-four requirements were tested. Coverage depends on which conditions and observations the tests actually exercise.

Design a dataset around an observable question

1. Identify the decision the data must support

Write a specific question before generating records. For example: can a Viewer change a Draft order in their own workspace? This identifies the role, ownership, state, and operation that the data must represent.

Record the expected result independently of the application's current response. If the role policy is unclear, resolve that requirement before treating a rejection or successful update as correct.

Also identify where the result can be observed. A disabled button may be enough for a UI availability check. It does not establish that a submitted request was rejected or that stored order lines remained unchanged.

2. Describe the complete starting arrangement

List the records and conditions the operation depends on. Include relevant account state, membership, configuration, ownership, parent records, and time.

Separate a convenient label from a verified fact. An account named viewer might have an Editor membership after yesterday's test. An order named draft-order might already have been submitted. Read the actual values needed by the test.

Decide which setup facts can be verified through an ordinary application read and which need an approved fixture or administrative interface. A tested user may correctly be unable to inspect a record that the setup process must still verify.

3. Define a baseline and deliberate variants

Choose a valid baseline that reaches the intended operation. Derive variants by changing the condition being investigated while retaining the other prerequisites.

If a result must hold across many valid inputs, describe which values can vary independently. The property-based testing examples show how deriving a total from a per-person charge can hide a rounding bug in every generated fixture.

This is a diagnostic choice, not a rule that every test must vary exactly one field. Interaction tests deliberately combine conditions. They still need an explanation of the combination and an observable expected result.

Keep invalid submission data distinct from invalid stored state. Sending an unsupported quantity to a valid order can test validation. Inserting an impossible order directly into storage tests a different situation, possibly one ordinary users cannot create.

4. Prepare an independent result and a readiness check

Calculate expected totals from the declared fixture values. Specify exact identifiers for membership comparisons, and define time boundaries before execution.

A readiness check establishes that the preconditions are present. A product assertion evaluates what happened after the test action. If setup could not produce a Draft order, that test has not demonstrated whether editing a Draft works.

Treat setup failure as separate evidence. It may reveal a genuine application defect, an incompatible fixture, or an unavailable dependency, but it must not be silently counted as a successful negative test.

5. Plan the dataset's lifecycle

Record how the data is created, who can modify it, when it expires, and how each test obtains a fresh starting arrangement. Define how to identify and remove the records owned by a run.

Choose the preparation mechanism to fit the test. A supported UI flow can produce realistic business history. An approved fixture interface can prepare complex states efficiently. Direct storage writes may bypass important application behavior and need explicit readiness checks.

For CSV import tests, importing the fixture can itself be the operation under test. In that case, the uploaded rows and the initial target records are separate inputs; a successful import must not be assumed as a prerequisite.

A shared model for the worked examples

The examples use dataset orders-v1 in an isolated test environment. Its two workspaces are W-A and W-B. Logical labels such as O-A1 identify fixture records; a run must map them to the actual IDs returned by its setup mechanism.

These rules apply to the fictional application:

  • Active Editors can read, create, and edit Draft orders in their workspace.
  • Active Viewers can read orders in their workspace but cannot edit them.
  • A user without a workspace membership cannot read or change its orders.
  • Submitted orders are read-only, including for Editors.
  • An order's customer and products must belong to its workspace.
  • Line quantities are integers from 1 through 10, inclusive.
  • Prices are integer minor units in one test currency. There are no taxes, discounts, shipping charges, or currency conversions in this model.
  • An order total equals the sum of its line quantities multiplied by their stored unit prices.
  • Rejected edits preserve the existing order and lines; rejected creates add neither an order nor a line.

All three example datasets are parts of one baseline, B1. Its core inventory contains two workspaces, three users, three memberships, two customers, three products, three orders, four order lines, and four invitations: 24 records. Audit events and captured messages are outside this core count.

The fixed application test time is T0 = 2030-04-18T10:00:00.000Z. This is an artificial reference instant, not the publication date or the reader's current time.

Worked example 1: users, roles, and workspace ownership

Prepare a small, distinguishable actor dataset

Create three active users with exactly these memberships:

UserWorkspaceRole
U-A1W-AEditor
U-A2W-AViewer
U-B1W-BEditor

There are no other memberships for these users. In particular, U-B1 must not also be an Editor of W-A. An unnoticed second membership would change the expected result of the ownership test.

For run r17, example contact addresses are editor-r17@example.com, viewer-r17@example.com, and other-editor-r17@example.com. IANA maintains example domains for documentation. These addresses illustrate naming; they are not functioning test inboxes.

If setup sends notifications, route them to a controlled test mail capture service and verify that routing separately. Choosing an example address does not configure or disable delivery.

Use the same target and valid proposed edit

Use Draft order O-A1 in W-A, defined in the next example. Its initial total is 4000. The proposed edit changes its folder quantity from 2 to 3, leaving its other line unchanged. The independently calculated accepted total is 5250.

Run each probe from a restored B1:

  • Editor control: Authenticate as U-A1 and make the proposed edit. The saved folder quantity becomes 3, the total becomes 5250, and the other orders remain unchanged.
  • Role variant: Authenticate as U-A2 and attempt the identical edit against the identical order. The operation is denied; O-A1 retains its original lines and total 4000.
  • Workspace variant: Authenticate as U-B1 and target the same O-A1 using its known fixture ID. The operation is denied without disclosing its order details; the setup-side observer confirms no change.

The third actor is an Editor so that a different role does not provide an alternative explanation for the workspace rejection. The order remains Draft so that a state restriction does not hide either access condition.

Keep credentials and actor selection explicit. A browser session left logged in as U-A1 could make the Viewer probe look like an authorization defect. Verify the active identity before the action, rather than inferring it from which account the tester intended to use.

Detect a misleading setup before assigning a result

Suppose the Viewer probe is denied, but a readiness read shows O-A1 is Submitted. The observed denial is compatible with both the role restriction and the state restriction. It does not isolate the Viewer rule.

Restore a verified Draft, repeat the probe, and retain the original execution as an invalid setup for that question. If an earlier action unexpectedly submitted the order, investigate that observation separately.

This dataset covers the declared role and workspace contrasts. It does not represent suspended users, multiple memberships, invitation permissions, or every possible role combination. Add those records only when the test objective requires them.

Worked example 2: linked orders and independently calculated results

Prepare the parents and keep similar names distinguishable

Customer C-A belongs to W-A; customer C-B belongs to W-B. Prepare these products:

  • P-A1: workspace W-A, name Blue folder, unit price 1250.
  • P-A2: workspace W-A, name Desk pad, unit price 375.
  • P-B1: workspace W-B, name Blue folder, unit price 2100.

The repeated name is intentional. A setup process that locates products globally by display name could choose the wrong workspace's record. Resolve products through their recorded IDs and ownership, retaining names for readable evidence.

Create these orders and verify their states:

OrderWorkspaceCustomerStateTotal
O-A1W-AC-ADraft4000
O-A2W-AC-ASubmitted375
O-B1W-BC-BDraft2100

Their stored order lines are:

LineOrderProductQuantityUnit price
L-A11O-A1P-A121250
L-A12O-A1P-A24375
L-A21O-A2P-A21375
L-B11O-B1P-B112100

Create dependencies before the records that reference them: workspaces and users before memberships, workspaces before customers and products, and customers and products before completed order fixtures. Capture generated identifiers as each step succeeds.

Preparing O-A2 may require a supported submission flow. If the application maintains history or related records, assigning the text Submitted to one field is not necessarily a valid substitute. Verify the state and the prerequisites that the edit operation uses.

Reconcile the baseline before using it as an oracle

Calculate the totals independently:

  • O-A1: 2 * 1250 + 4 * 375 = 2500 + 1500 = 4000.
  • O-A2: 1 * 375 = 375.
  • O-B1: 1 * 2100 = 2100.

Workspace W-A has two orders and three lines, with combined order total 4375. Workspace W-B has one order and one line, with total 2100. The combined total is 6475, but that aggregate alone cannot establish correct ownership.

Check the line-to-order and product-to-workspace relationships as well as the counts. Four lines linked to the wrong orders could satisfy the count while invalidating the fixture. Similarly, a global total could remain correct if two orders' values were swapped.

The Editor control from example 1 changes L-A11 to quantity 3. Its expected new total is 3 * 1250 + 4 * 375 = 5250, an increase of 1250. Read the saved line and total; do not copy the application's displayed total into the expected-result field.

Separate state and validation variants

For the state probe, use U-A1 to attempt changing O-A2's pad quantity from 1 to 2. That quantity is valid, the actor is an Editor, and the customer and product belong to the workspace. Rejection should therefore exercise the Submitted-order restriction. The saved quantity remains 1 and the total remains 375.

For quantity validation, restore B1 and use U-A1 to attempt changing L-A12 on Draft O-A1 from 4 to 0. The request should identify the quantity problem and preserve both lines and total 4000.

Do not put quantity 0 into the stored baseline to prepare this case. The invalid value belongs in the attempted update. Otherwise, the test begins after the validation boundary it was meant to investigate.

The resulting evidence supports concrete API test cases: identify the actual actor and order, record the submitted change, and compare the response with the saved records. The fixture supplies preconditions and expectations; it does not replace those observations.

Add a relationship violation without corrupting the baseline

Use a separate create-order probe to investigate product ownership. As U-A1, target workspace W-A, customer C-A, and one line with quantity 1.

The valid control uses P-A1 and should create one Draft order and one line with total 1250. Capture the created records and remove them before another independent probe.

For the relationship variant, restore B1 and change only the selected product to P-B1. The product exists and the quantity remains valid, but it belongs to W-B. Creation is rejected, and no order or line is added in either workspace.

Verify the unchanged three-order, four-line baseline after rejection. A failure response accompanied by an empty saved order would violate this example's rejection contract. Sending a nonexistent product instead would test missing-record handling and could not establish the workspace relationship behavior.

Worked example 3: expiring data and a controlled clock

Declare what time means for this operation

The example application has a read-only invitation eligibility check. An invitation is available only when it is pending and the authoritative application time is strictly earlier than its expiry instant. A used invitation is unavailable even if its expiry is still in the future.

Checking eligibility does not accept or consume the invitation. These rules let the same pending record support repeated boundary observations. Adapt the setup if the real operation consumes a token or changes membership.

All four invitations belong to W-A and offer the Viewer role. Their issue time is T0 - 3600 seconds. Prepare the following states:

InvitationExpiry relative to T0StateResult at T0
I-Ready+60 secondsPendingAvailable
I-Edge0 secondsPendingUnavailable
I-Past-60 secondsPendingUnavailable
I-Used+60 secondsUsedUnavailable

I-Used was accepted by U-A2 at T0 - 30 seconds; its target address is the Viewer address from example 1. Its accepted history and the declared Viewer membership must agree. The pending invitations target three distinct synthetic addresses that have no workspace membership.

Use a supported preparation flow or fixture mechanism that can establish these relationships. Through normal invitation flows, first prepare only the Editor memberships for U-A1 and U-B1. At application time T0 - 3600 seconds, issue all four invitations with the declared expiry instants. Advance to T0 - 30 seconds and accept I-Used as U-A2, establishing the third membership. Then advance to T0 and verify the final baseline.

An approved fixture mechanism may establish the same arrangement directly if it preserves the required history and relationships. Either method must leave exactly the declared three memberships, rather than adding an unnoticed fourth membership.

Exercise the exact cutoff with one pending record

The actual expiry of I-Edge is 2030-04-18T10:00:00.000Z. With millisecond precision, check it at these authoritative application times:

  • 2030-04-18T09:59:59.999Z: available, because time is one millisecond before expiry.
  • 2030-04-18T10:00:00.000Z: unavailable, because equality is outside this example's valid interval.
  • 2030-04-18T10:00:00.001Z: unavailable, because time is one millisecond after expiry.

Confirm the record is pending before each observation. A consumed invitation could be rejected at every instant and hide an incorrect expiry comparison.

Control the clock used by the eligibility service. Changing only the browser's clock does not establish which instant the service evaluated. Record the effective service time with the result, and restore T0 after the probe.

Clock control also needs isolation. Two tests cannot independently freeze the same service at different times without coordination. Use separate instances, a supported scoped clock, or serialized access to that dependency.

The date and time testing guide covers different kinds of date values and time-zone behavior. Here, the data design question is how to keep this exact invitation and clock arrangement reproducible.

Make relative expiry a declared parameter

At T0 + 61 seconds, I-Ready is expired. A later test expecting an available invitation cannot reuse it unchanged and treat the resulting rejection as a product failure.

For a test whose objective is simply an available invitation, prepare expiry relative to its controlled start time and record the resulting absolute instant. For an expiry-boundary test, preserve the exact relationship to the boundary.

Do not silently refresh dates after a failure. That changes the input evidence. Preserve the failed arrangement first, then create a new identified fixture or execution with the intended time relationship.

Authentication, external providers, and scheduled jobs may use other clocks. Record those dependencies when they affect the test; do not assume a scoped application clock also changes an identity provider's token validity.

Reuse definitions while isolating mutable records

Give each run an ownership boundary

For run r17, allocate distinct workspace records and account identifiers. Run r18 receives different physical records even though both manifests use the logical labels W-A, U-A1, and O-A1.

Capture the logical-to-physical ID map at preparation time. If a generated identifier must have a particular format, use the application's identifier mechanism; a run prefix in a display name is not a replacement for a valid stored ID.

Scope observations to the run's actual workspace IDs. A query counting every order in a shared environment would include other testers' records and make the expected three-order count unreliable.

For ordinary test addresses, generate unique local parts while retaining the intended format. For a duplicate-address test, deliberately reuse the relevant address and record that relationship. Uniqueness is useful only when the test does not require duplication.

Restore more than the visible field

After the accepted edit, a new independent probe needs the full original arrangement: L-A11 quantity 2, L-A12 quantity 4, total 4000, and Draft state.

Restoring the total while leaving quantity 3 would produce an inconsistent baseline. Conversely, restoring the quantity without invalidating a cached total could make the first read misleading.

Choose a supported reset mechanism and verify the same readiness facts that the next test needs. Recreate the run's workspace when targeted restoration cannot reliably restore history, derived records, or pending work.

If the application updates a search index asynchronously, a successful setup write is not sufficient readiness for a search test. Wait for an observable condition, such as the required fixture IDs appearing in the relevant query, with an explicit timeout. Record an unmet condition as a preparation blocker.

Account for workers and partial setup

Track records as they are created. If setup fails after creating customers but before creating orders, a record of only the final workspace label may be insufficient for targeted cleanup.

Before deletion, stop or complete run-owned background work that could recreate records. Remove dependent lines before orders, then remove other run-owned dependents before their parent workspaces and users, following the actual relationships.

An application may require business deletion flows, soft deletion, or retained audit records. Define successful cleanup according to that environment's contract. Do not disable its constraints merely to force the tutorial's core count to zero.

After cleanup, verify that no active core fixture records or pending run-owned jobs remain in scope. Record any retained evidence and its location. An empty UI list alone does not establish that all dependencies were removed.

A reusable dataset manifest with a filled example

A dataset manifest describes a dataset version and the concrete arrangement prepared for one execution. It can be a shared document or a structured fixture record; it does not require a new tool.

Use fields that another tester can resolve:

  • Identity: dataset name, version, run ID, and preparation owner.
  • Purpose: the conditions this dataset supports.
  • Compatibility: relevant rule version, build, configuration, and environment.
  • Inventory: logical records, actual ID map, relationships, and deliberate omissions.
  • Time: clock source, precision, effective instant, and expiry rules.
  • Readiness: observations required before the test action.
  • Expected results: independently specified values and unchanged-record assertions.
  • Lifecycle: mutation ownership, reset method, cleanup boundary, and evidence location.

For the worked model, a filled example is:

  • Dataset and run: orders-v1, baseline B1, run r17, prepared by the QA tester for fictional build training-12.
  • Purpose: distinguish role, workspace, order-state, quantity, relationship, and invitation-time conditions.
  • Scope: two run-owned workspaces; ID map stored with r17's preparation record.
  • Inventory: 24 core records with the entity counts declared above; no additional memberships for the three actors.
  • Clock: eligibility service fixed at 2030-04-18T10:00:00.000Z, millisecond precision; external authentication uses its own unchanged clock.
  • Readiness: verify memberships, all order-line links, order totals 4000, 375, and 2100, and invitation states and expiry instants.
  • Named edit expectation: Editor changes L-A11 quantity to 3; expected O-A1 total 5250; other order totals remain 375 and 2100.
  • Reset: restore and verify B1 between independent probes; restore service time to T0 after clock probes.
  • Cleanup and evidence: remove run-owned active fixtures and jobs through the supported test mechanism; retain ID map, submitted changes, readiness reads, and results in r17's execution record.

This is a specification for preparation, not a claim that setup succeeded. The execution record must contain the actual IDs and observed readiness results. A future run gets its own ID map and evidence.

Maintain data when the product contract changes

Separate dataset versions from temporary mutations. Changing one quantity during a test creates an execution state; changing the fixture's intended rules creates a new version.

Suppose version 2 of the teaching product lowers the maximum line quantity from 10 to 8. Baseline quantities 2, 4, and 1 remain valid, so the core record counts and totals do not need to change. However, boundary variants must be reviewed.

Under version 1, quantity 10 is accepted and 11 rejected. Under version 2, quantity 8 is accepted and 9 rejected; quantity 10 is now invalid. Update the expected outcomes and the fixture's compatibility record together.

Use boundary value analysis to choose the appropriate boundary probes. Do not merely rename an old fixture file while leaving its expected acceptance result unchanged.

Retain the earlier dataset definition when it is needed to reproduce an earlier failure. Reproduction also needs a compatible product build and configuration. An old dataset name alone cannot recreate past behavior on a changed application.

When a new required field or relationship is introduced, add it through the supported preparation path and verify it explicitly. Avoid broad fallback defaults that make every old dataset appear valid while removing the distinction a test was designed to exercise.

Diagnose untrustworthy test data

When an observation disagrees with the expected result, preserve the actual input, ID map, readiness evidence, and build before resetting. Then determine which question can be answered.

If the declared prerequisites were verified and the action produced a wrong result, report the observed behavior with the smallest useful dataset. Remove unrelated records only after confirming that the failure still occurs; an apparently irrelevant relationship may be necessary.

Also inspect the comparison itself. A report that expects 4000 after the accepted Editor update is using the baseline oracle for a post-action state. The correct result for that execution is 5250. Preserve both expectations and identify which observation point each belongs to.

For generated datasets, retain the generated values and relationships needed to replay the run. A seed can help, but replay also depends on the generator version, execution order, configuration, and relevant external state.

FAQ

Yes, for a specific functional question when it represents the relevant rules, relationships, and observable outcomes. The worked baseline deliberately includes matching names in different workspaces and distinct order states. It does not reproduce production scale or traffic distribution. Performance, migration, or statistical behavior requires a dataset designed for those objectives.

No. The complete baseline makes the shared examples inspectable. A smaller profile can support a particular test if it preserves the necessary dependencies and contrasts. For example, a single-workspace role probe still needs distinct Editor and Viewer actors and a verified Draft order. Record the reduced profile and its omissions.

Yes. Both can use the same logical records, expected values, and readiness criteria. The preparation and reset mechanisms may differ. A manual tester needs resolvable identifiers and explicit reset instructions; automation needs those same facts as executable setup and checks. Neither should rely on a previous unrelated test leaving the right state behind.

Ready to turn this guide into a working QA project with statuses, comments, and CSV export?