Typorithm · medium

14. Test data, isolation and privacy

qatestingtest-designindependent-practice
Saved on this device
Full lesson · 4 learning steps Open any exercise for focused practice
1

Step 1 of 4 · intro card

14. Test data, isolation and privacy

0%

Concept and contract

Give each test a known starting point without relying on production records.

A test’s data is part of its precondition. Shared mutable records can make otherwise correct checks depend on execution order. Start with small synthetic fixtures and give each test an isolated namespace, database or transaction according to the system’s actual persistence model.

Use fictional accounts and reserved example addresses. Real documents, tokens and private saved lists do not belong in a public learning package. A trace or screenshot can retain sensitive values even when the test script itself contains none.

Mechanism and worked example

The worked plan gives Alice and Bob separate saved sets within a test-specific namespace.

The worked plan gives Alice and Bob separate saved sets within a test-specific namespace. A second test receives a fresh namespace rather than inheriting the first test’s changes. This supports parallel execution without deleting a shared global fixture.

Browser-context isolation resets browser state, but it does not automatically reset server data. Coordinate the browser namespace and API setup explicitly. A fresh tab alone may share cookies, while a fresh context can still reach the same mutable server records.

Complete worked example

json

{
  "tests": [
    {
      "name": "save A",
      "namespace": "case-A",
      "caller": "alice",
      "initialIds": []
    },
    {
      "name": "save B",
      "namespace": "case-B",
      "caller": "alice",
      "initialIds": []
    }
  ],
  "cleanup": "Only the current namespace"
}
Reasoning
The same synthetic role id is safe when mutable account state is isolated.

Counterexamples and common mistakes

The weak plan reuses one account and saved list for every worker, then clears the whole collection.

The weak plan reuses one account and saved list for every worker, then clears the whole collection. One worker can erase another’s expected data. A cleanup hook does not make a dangerous global deletion safe merely because it runs after a test.

Avoid depending on wall-clock time or a random id whose failure value is never recorded. Use reproducible fixture inputs, injected time where needed and unique names only for isolation. Log enough nonsecret context to replay a failure.

Counterexample: what this check misses

json

{
  "namespace": "shared",
  "workers": 4,
  "cleanup": "Delete every saved record"
}
Reasoning
A shared global cleanup can invalidate another worker’s preconditions.

Independent practice: small task

Design two independent tests that each save r1 and verify one saved id.

Design two independent tests that each save r1 and verify one saved id. Give them separate namespaces and explain how cleanup is limited to their own data. Begin by writing the starting saved list for each test.

Then describe the behavior when both run concurrently. Optional extension: add a test that deliberately leaves its own state behind and verify that the other namespace remains unaffected. Do not run cleanup against any live account.

Step 1: Give both tests explicit empty saved lists. Step 2: Use different namespaces and scoped cleanup.

Practice starter: solve before reading the solution

json

{
  "testA": {
    "namespace": "TODO",
    "initialIds": "TODO"
  },
  "testB": {
    "namespace": "TODO",
    "initialIds": "TODO"
  },
  "cleanup": "TODO"
}
Reasoning
Write two independent empty starting states before discussing parallelism.
  • Hint 1: A fresh tab is not a new browser context.
  • Hint 2: Do not publish tokens or private traces.

Solution, tests and trade-offs

The solution assigns separate namespaces and the same empty starting list.

The solution assigns separate namespaces and the same empty starting list. Reusing r1 is safe because account state is partitioned by namespace. Each test can remove its own saved item without touching the other test’s data.

The verifier simulates both namespaces and checks that changing one leaves the other intact. This proves the local fixture’s isolation behavior, not every storage engine’s transaction semantics. Adapt the boundary to the real system before claiming equivalent isolation.

Practice solution and acceptance checks

json

{
  "testA": {
    "namespace": "case-A",
    "initialIds": [],
    "afterSave": [
      "r1"
    ]
  },
  "testB": {
    "namespace": "case-B",
    "initialIds": [],
    "afterSave": [
      "r1"
    ]
  },
  "cleanup": "Remove only records in the current test namespace"
}
Reasoning
The namespace is the ownership boundary for setup and cleanup.

Interview reasoning and next step

In interviews, distinguish browser storage isolation from server-data isolation.

In interviews, distinguish browser storage isolation from server-data isolation. Explain how you would reproduce a failed parallel run without retaining private payloads. Name the exact cleanup scope rather than saying that tests reset everything.

Next, summarize test evidence for a release decision. Counts become meaningful only when their denominator, scope and unresolved risks are visible.

Optional stretch — after the core task works: Leave one namespace dirty and verify the other remains independent.

Computer practice: download the companion lab at https://applydjinn.com/typorithm/qa-lab-20261105.zip. Read its README, install the pinned tools and run the accepted examples before attempting a starter. The mobile reader preserves your reading and self-check progress; the local lab runs browser tests separately.

Give each test a known starting point without relying on production records.