Module 07 · Lesson 7.1
From Criteria to Test Cases
On this page
- What you will learn
- From acceptance scenario to test case
- Choose the right test level: unit, integration or end-to-end
- Write the test cases as named automated tests
- Keep a traceability table for every Must scenario
- Step-by-step workflow
- Working with an assistant on test cases
- Conclusion and your next step
- Reusable prompt
- Expected output
- Common errors and fixes
- Validation checklist
- Hands-on exercise
- Knowledge check
- Frequently asked questions
- References
A driving examiner does not ask, 'Are you a good driver?' They carry a list of exact checks: stop at the red light, reverse round a corner, signal before turning. Your acceptance criteria are the examiner's rules. Test cases are the exact checks you run to see whether the rules are met.
In this lesson you turn the Tidewell cancellation scenarios into test cases with real data and clear expected results. You choose a test level for each one and write them as automated tests whose names match the scenario ids. Then you build a small traceability table, so you can prove that every Must scenario has a test.
What you will learn
- Turn each acceptance scenario into test cases with concrete data, an action and an expected result.
- Choose the right test level (unit, integration or end-to-end) for each case.
- Add boundary, permission and failure cases that the scenarios do not spell out.
- Name automated tests after scenario ids and keep a traceability table that shows every Must scenario is covered.
Before you start
- Completed Approvals for Consequential Actions, the last lesson of the previous module, and Acceptance Criteria, where the scenarios were written.
- Access to any capable AI assistant.
- Optional: Node.js and the project from earlier lessons, if you want to run the examples.
From acceptance scenario to test case
An acceptance scenario describes behaviour in the client's words: 'Given a booking more than 24 hours away, when the patient cancels it, then the booking is cancelled.' It is correct, but you cannot run it yet. Which booking? Away from when? What exactly do you look at to know it worked?
A test case answers those questions. It is one specific check, written down with exact data. Think of a building inspector's checklist: 'Open the fire door from inside; it must open with one push.' The scenario is the rule. The test case is the line on the checklist.
- Test case
- One specific check: the starting data, the action, and the result you expect.
- Automated test
- A test case written as code, so a machine can run it in seconds and as often as you like.
- Test level
- How much of the system a test uses: one function (unit), several parts together (integration) or the whole app in a browser (end-to-end).
- Test id
- A short label that ties the test back to a scenario, such as FR-02.1.
Here are the Tidewell cancellation cases. The clock is fixed at 30 November 2026, 10:00 UTC, so 'more than 24 hours away' means a real time. FR-02.1 to FR-02.3 come from Module 1. Two more were added since: FR-02.4 after the practice manager confirmed that exactly 24 hours is allowed, and FR-05.1 because FR-05 says every change records who made it and when.
| Test id | Level | Given (data) | Action | Expected |
|---|---|---|---|---|
| FR-02.1 | Integration | Patient A holds a booking that starts 25 hours from now. | Patient A cancels it. | Status is cancelled, in the response and in the database. |
| FR-02.2 | Integration | Patient A holds a booking that starts 23 hours from now. | Patient A cancels it. | Refused (422). The booking is still booked. The message gives 01632 960 123 and the opening hours. |
| FR-02.3 | Integration | Patient A holds a booking. Patient B is signed in. | Patient B cancels Patient A's booking. | Not found (404). The booking is still booked. |
| FR-02.4 | Unit and integration | A booking that starts exactly 24 hours from now. | The patient cancels it. | Allowed: the booking is cancelled. |
| FR-05.1 | Integration | Patient A holds a booking that starts 25 hours from now. | Patient A cancels it. | One history row: cancelled, by a patient, with id 1, at the time of the action. |
| NFR-01 | Integration | One free slot. Patient A and Patient B both want it. | Both book it at the same moment. | One booking (201) and one refusal (409). One live booking in the database. |
Where the extra cases come from
The three Module 1 scenarios are not enough on their own. Use the same questions you used when you wrote criteria, and ask them again about the test data.
- Boundary: test the value on the line, and one step either side. Here that is 24 hours exactly, and 24 hours minus one millisecond.
- Permission: test who must be refused. A patient may not touch someone else's booking (FR-02.3). After Module 6, add one case per role in the permission table, written against the permission code in
src/lib/permissions.ts. - Failure: what if the action fails part-way? The booking must not end up half-cancelled.
- Concurrency: what if two people act together? That is NFR-01, and you test it in the next lesson.
- Nothing: a patient with no bookings sees a clear message, not a blank page.
Choose the right test level: unit, integration or end-to-end
Not every check needs the whole system. A test that opens a browser is like test-driving a car on a track to check one bulb: it works, but it is slow, and when it fails you do not know which part broke. Test each rule at the lowest level that can show it.
| Level | What runs | Speed | Best for | Tidewell example |
|---|---|---|---|---|
| Unit | One function. No database, no network. | Milliseconds | Rules with many inputs, and boundaries. | isInsideNoticePeriod with 23 hours, 24 hours and 25 hours. |
| Integration | Several parts together, such as the service and a real database. | Around a second here | Where parts meet: SQL, constraints, ownership checks. | Cancel a booking and read the row back from PostgreSQL. |
| End-to-end | The running app, driven by a real browser. | Seconds each | A few key journeys, as a person would do them. | A patient opens My bookings, cancels, and sees the message. |
People call this the test pyramid: many fast unit tests at the bottom, fewer integration tests in the middle and a handful of end-to-end tests at the top. Martin Fowler's The Practical Test Pyramid (opens in a new tab) explains why. The same scenario can have tests at two levels. The boundary has a unit test, which is cheap and can try many values, and an integration test, which proves the whole path.
The tools are a choice, so name them in your project notes. This lesson uses Node's built-in test runner (Test runner (opens in a new tab)), run through tsx so it can read TypeScript. Vitest and Jest are common alternatives and work in a similar way. For end-to-end tests, Playwright (opens in a new tab) is the example in this program, and Cypress is another popular tool. Test files sit beside the code they test and end in .test.ts, as Module 3 decided.
Write the test cases as named automated tests
Now turn the table into code. The rule for names is simple: each test name starts with its scenario id. When a test fails, the report tells you which promise to the client was broken. This example uses the Module 4 backend, so the tests pass the patient id straight in. After Module 6, the same helper would create a signed-in session instead. The test ids stay the same.
First, a small helper file. Tests that all build their starting data the same way are easy to read. The seed data has four slots with known start times, and the clock is fixed, so every run gives the same answers.
// Test helpers: small, boring, and shared by every test file.
import type { PGlite } from "@electric-sql/pglite";
import type { BookingContext } from "./service";
import { NOW } from "./seed";
// Seed data (see seed.ts), with the clock fixed at NOW = 2026-11-30 10:00 UTC:
// slot 1 starts 23 hours away, slot 2 exactly 24 hours away,
// slot 3 starts 25 hours away, slot 4 starts three days away.
export const SLOT = { inside: 1, exactly24h: 2, outside: 3, farAway: 4 } as const;
export function asPatient(db: PGlite, patientId: number): BookingContext {
return { db, patientId, now: NOW };
}
// "Given a patient has a booking": insert it directly, so the test starts from a known state.
export async function givenBooking(db: PGlite, patientId: number, slotId: number): Promise<number> {
const { rows } = await db.query<{ id: number }>(
"INSERT INTO bookings (slot_id, patient_id, status, created_at) VALUES ($1, $2, 'booked', $3) RETURNING id::int AS id",
[slotId, patientId, NOW.toISOString()],
);
return rows[0].id;
}
export async function statusOf(db: PGlite, bookingId: number): Promise<string> {
const { rows } = await db.query<{ status: string }>("SELECT status FROM bookings WHERE id = $1", [bookingId]);
return rows[0].status;
}Shared by all the test files in this lesson and the next two.
SLOTnames the four seed slots by what they are for. A test that saysSLOT.exactly24hexplains itself.asPatientbuilds the context the service needs: the database, a patient id and the fixed clock.givenBookingis the 'Given' step. It inserts a booking directly, so the test starts from a known state and does not depend on the code it is checking.statusOfreads the booking back from the database. A test that checks the database, and not only the response, catches code that says 'cancelled' but saves nothing.
// Integration tests: the booking service with a real PostgreSQL engine (PGlite).
// Each test name starts with its scenario id from docs/acceptance-criteria.md.
import assert from "node:assert/strict";
import { test } from "node:test";
import { ApiError } from "./problem";
import { cancelBooking } from "./service";
import { freshDatabase, NOW } from "./seed";
import { asPatient, givenBooking, SLOT, statusOf } from "./helpers";
test("FR-02.1 cancelling outside the notice period cancels the booking", async () => {
const db = await freshDatabase();
const bookingId = await givenBooking(db, 1, SLOT.outside);
const result = await cancelBooking(asPatient(db, 1), bookingId);
assert.equal(result.status, "cancelled");
assert.equal(await statusOf(db, bookingId), "cancelled");
});
test("FR-02.2 cancelling inside the notice period leaves the booking unchanged and says to phone", async () => {
const db = await freshDatabase();
const bookingId = await givenBooking(db, 1, SLOT.inside);
await assert.rejects(cancelBooking(asPatient(db, 1), bookingId), (error) => {
assert.ok(error instanceof ApiError);
assert.equal(error.problem.status, 422);
assert.match(error.problem.detail, /01632 960 123, Monday to Friday, 8:00 to 18:00/);
return true;
});
assert.equal(await statusOf(db, bookingId), "booked");
});test("FR-02.3 someone else's booking is unchanged and looks like it does not exist", async () => {
const db = await freshDatabase();
const bookingId = await givenBooking(db, 1, SLOT.outside);
await assert.rejects(cancelBooking(asPatient(db, 2), bookingId), (error) => {
assert.ok(error instanceof ApiError);
assert.equal(error.problem.status, 404);
return true;
});
assert.equal(await statusOf(db, bookingId), "booked");
});
test("FR-02.4 a booking exactly 24 hours away can be cancelled online", async () => {
const db = await freshDatabase();
const bookingId = await givenBooking(db, 1, SLOT.exactly24h);
const result = await cancelBooking(asPatient(db, 1), bookingId);
assert.equal(result.status, "cancelled");
});
test("FR-05.1 a cancellation is recorded with who made it and when", async () => {
const db = await freshDatabase();
const bookingId = await givenBooking(db, 1, SLOT.outside);
await cancelBooking(asPatient(db, 1), bookingId);
const { rows } = await db.query(
"SELECT action, actor_role, actor_id::int AS actor_id, changed_at FROM booking_changes WHERE booking_id = $1",
[bookingId],
);
assert.deepEqual(rows, [{ action: "cancelled", actor_role: "patient", actor_id: 1, changed_at: NOW }]);
});What each part does
test("FR-02.1 ...", async () => { ... })registers one test. The name begins with the scenario id.- Each test follows the same three beats: Given (
givenBooking), When (cancelBooking), Then (theassertlines). Blank lines separate the beats. assert.equal(a, b)fails the test ifaandbdiffer.assert.rejectsexpects the call to fail, and lets you check how it failed. Here it checks the status and the phone number from the criterion.- FR-02.2 and FR-02.3 also check that the booking is still
booked. A refusal that still changes the data would be a bug, and the response alone would not show it. - Every test calls
freshDatabase(), so no test can disturb another.
Run the file from the kit folder with npx tsx --test --test-reporter=spec scenarios.test.ts. The --test flag tells Node to run the file as tests, and --test-reporter=spec gives the readable list. This is a real run. Your times will differ, because they depend on your computer.
✔ FR-02.1 cancelling outside the notice period cancels the booking (1184.209ms)
✔ FR-02.2 cancelling inside the notice period leaves the booking unchanged and says to phone (727.5313ms)
✔ FR-02.3 someone else's booking is unchanged and looks like it does not exist (750.8352ms)
✔ FR-02.4 a booking exactly 24 hours away can be cancelled online (1174.587ms)
✔ FR-05.1 a cancellation is recorded with who made it and when (1238.2848ms)
ℹ tests 5
ℹ suites 0
ℹ pass 5
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 15431.8358Keep a traceability table for every Must scenario
Traceability means you can follow a line from the requirement to the scenario to the test, and back. It answers two questions a client asks: 'Is everything we agreed being checked?' and 'Why does this test exist?' A table is enough.
| Scenario | Test id | Level | File |
|---|---|---|---|
| Cancel outside the notice period (FR-02.1) | FR-02.1 | Unit, integration, end-to-end | rules.test.ts, scenarios.test.ts, e2e/cancel-booking.spec.ts |
| Cancel inside the notice period (FR-02.2) | FR-02.2 | Unit, integration | rules.test.ts, scenarios.test.ts |
| Someone else's booking (FR-02.3) | FR-02.3 | Integration | scenarios.test.ts |
| Exactly 24 hours is allowed (FR-02.4) | FR-02.4 | Unit, integration | rules.test.ts, scenarios.test.ts |
| Changes are recorded (FR-05.1) | FR-05.1 | Integration | scenarios.test.ts |
| No double booking (NFR-01) | NFR-01 | Integration | concurrency.test.ts |
A table in a document goes out of date. A small script can check it for you. This one reads the test files and looks for each scenario id at the start of a quoted test name. It reports any Must scenario that no test mentions.
// Reads test files and reports which scenario ids appear in a test name.
import { readFile } from "node:fs/promises";
import { basename } from "node:path";
export interface Scenario {
id: string;
title: string;
}
export interface TestFile {
path: string;
level: "unit" | "integration" | "end-to-end";
}
export interface TraceRow {
scenario: Scenario;
tests: { level: string; file: string }[];
}
export async function traceability(scenarios: Scenario[], files: TestFile[]): Promise<TraceRow[]> {
const sources = await Promise.all(files.map(async (file) => ({ file, text: await readFile(file.path, "utf8") })));
return scenarios.map((scenario) => {
// The id must sit at the start of a quoted string: a test name, or a table entry that builds one.
const id = scenario.id.replaceAll(".", "\\.");
const startsAName = new RegExp(`["'\`]${id}(?=[ :"'\`])`);
const tests = sources
.filter(({ text }) => startsAName.test(text))
.map(({ file }) => ({ level: file.level, file: basename(file.path) }));
return { scenario, tests };
});
}import { join } from "node:path";
import { traceability, type Scenario, type TestFile } from "./traceability";
// The Must scenarios from docs/acceptance-criteria.md.
const MUST: Scenario[] = [
{ id: "FR-02.1", title: "Cancel outside the notice period" },
{ id: "FR-02.2", title: "Cancel inside the notice period" },
{ id: "FR-02.3", title: "Someone else's booking" },
{ id: "FR-02.4", title: "Exactly 24 hours is allowed" },
{ id: "FR-05.1", title: "Changes are recorded" },
{ id: "NFR-01", title: "No double booking" },
];
const LEVELS: Record<string, TestFile["level"]> = {
"rules.test.ts": "unit",
"scenarios.test.ts": "integration",
"concurrency.test.ts": "integration",
"e2e/cancel-booking.spec.ts": "end-to-end",
};
// Usage: npx tsx trace-report.ts scenarios.test.ts rules.test.ts
const files = process.argv.slice(2).map((name) => ({ path: join(import.meta.dirname, name), level: LEVELS[name] ?? "unit" }));
const rows = await traceability(MUST, files);
for (const { scenario, tests } of rows) {
const where = tests.length === 0 ? "NO TEST" : tests.map((t) => `${t.level}: ${t.file}`).join(", ");
console.log(`${scenario.id.padEnd(8)} ${scenario.title.padEnd(34)} ${where}`);
}
const missing = rows.filter((row) => row.tests.length === 0).map((row) => row.scenario.id);
console.log(missing.length === 0 ? "Every Must scenario has a test." : `Must scenarios without a test: ${missing.join(", ")}`);
process.exitCode = missing.length === 0 ? 0 : 1;Run it with only the file from this lesson: npx tsx trace-report.ts scenarios.test.ts.
FR-02.1 Cancel outside the notice period integration: scenarios.test.ts
FR-02.2 Cancel inside the notice period integration: scenarios.test.ts
FR-02.3 Someone else's booking integration: scenarios.test.ts
FR-02.4 Exactly 24 hours is allowed integration: scenarios.test.ts
FR-05.1 Changes are recorded integration: scenarios.test.ts
NFR-01 No double booking NO TEST
Must scenarios without a test: NFR-01The script found a gap: nothing tests NFR-01, so two people could still book the same slot without any test noticing. You close that gap in Unit and Integration Tests. The script exits with an error when a Must scenario has no test, which is what lets a pipeline block the change later.
Step-by-step workflow
Step 1: List the Must scenarios
Open docs/acceptance-criteria.md. Copy every Must scenario id into a table. Leave the Should ones for later.
What you should see: A table with one row per scenario and empty columns for level and file.
Step 2: Fill in concrete data
For each scenario, write the exact starting data and the fixed clock. 'A booking more than 24 hours away' becomes 'a booking 25 hours from 30 November 2026, 10:00 UTC'.
What you should see: A Given that anyone could set up without asking you.
Step 3: Write the expected result from the criterion
Take the Then line of the scenario. Do not run the code to see what it says. If the Then line is vague, send it back to the client.
What you should see: An expected result that is a promise, not a guess.
Step 4: Add boundary, permission, failure and concurrency cases
Ask the question list for each requirement. Mark any case that needs a business rule as 'Decision needed'.
What you should see: Typically two to four extra cases per Must requirement.
Step 5: Pick the lowest level for each case
Put rules with many inputs at unit level. Put database, ownership and permission cases at integration level. Keep end-to-end for a few key journeys.
What you should see: A level in every row.
Step 6: Write the tests and run the traceability check
Name each test with its id. Run the traceability script and fix any gap it reports.
What you should see: The script prints 'Every Must scenario has a test.'
- Scenario
Given, When, Then
- Test case
Data and expected result
- Level
Lowest that can show it
- Named test
Starts with the id
- Traceability
Gaps reported
Each step makes the previous one more exact. The last step keeps it true as the code changes.
Working with an assistant on test cases
An assistant is quick at listing cases, and it often remembers boundaries that people forget. It does not know your business rules, and it cannot know whether an expected result is right. Give it the scenarios and the decisions, and keep the judgement for yourself. The prompt library has a ready-made prompt: Test Case Design from Acceptance Criteria.
| Task | Assistant's part | Your part |
|---|---|---|
| Expand scenarios into cases | Proposes boundary, negative and permission cases. | Reject cases that no requirement supports. Mark rule questions 'Decision needed'. |
| Choose test data | Suggests values and edge values. | Check that each value is synthetic and that the clock is fixed. |
| Write expected results | Copies them from the scenarios. | Check each against the criterion. An expected result taken from the code is not a check. |
| Choose levels | Suggests a level for each case. | Move slow checks down to a cheaper level when you can. |
| Write the test code | Drafts the tests and the helpers. | Run them, then break the code on purpose, as in the next lessons. |
Conclusion and your next step
Acceptance scenarios say what must be true. Test cases give them exact data and expected results, and a level that keeps the checks fast. Naming each automated test after its scenario id lets a short script prove that every Must scenario is checked.
Your next step: build the test-case table for your capstone's Must scenarios, with levels, and write the first five tests with ids in their names. Then continue to Unit and Integration Tests, where you write the unit tests for the rules, add the concurrency test for NFR-01 and close the gap the script found.
For more on testing with an assistant, read Prompt Engineering for QA: Property-Based, Mutation, and Contract Testing with AI, or practise on a similar clinic in the Appointment Booking Portal project.
Reusable prompt
Test case designer
Turns acceptance scenarios into a table of test cases with levels and concrete data, and adds the cases you may have missed without inventing rules.
You are helping me design test cases. Do not write test code yet. Do not decide business rules.
Fictional clinic: Tidewell Physiotherapy. Stack: TypeScript, PostgreSQL (tests use PGlite, a real PostgreSQL engine inside Node), Node's built-in test runner.
Test levels: unit (one function, no database), integration (service plus database), end-to-end (a browser driving the running app).
Fixed clock for every test: 2026-11-30 10:00 UTC. Use synthetic data only (Patient A, Patient B).
Rule confirmed by the practice manager on 2026-11-19: a patient may change or cancel online only if the appointment starts at least 24 hours from now. Exactly 24 hours is allowed.
Scenarios:
FR-02.1 A patient cancels a booking more than 24 hours away: it is cancelled and the slot is freed.
FR-02.2 A patient tries to cancel a booking less than 24 hours away: it is unchanged and they are told to phone the clinic with its opening hours.
FR-02.3 A patient tries to cancel someone else's booking: it is unchanged and its existence is not revealed.
NFR-01 Two people changing the same slot cannot produce two bookings for it.
Tasks:
1. For each scenario, give one table row: test id (the scenario id), level, given data (concrete values), action, expected result. Take the expected result from the scenario wording only.
2. Propose extra cases for boundaries, permissions, failures part-way and concurrency. Mark each "Proposed" and give it an id such as FR-02.4.
3. If a case depends on a rule that I have not stated, write "Decision needed: ..." and name the role that should decide. Do not choose a value.
4. For each case, name the lowest level that can show it and say why in one line.
5. List any scenario that is too vague to turn into a test.Show the reusable template
Replace each {{placeholder}} with your own details.
You are helping me design test cases. Do not write test code yet. Do not decide business rules.
Context: {{organisation_and_stack}}
Test levels: unit (one function, no database), integration (service plus database), end-to-end (a browser driving the running app).
Fixed clock for every test: {{fixed_clock}}. Use synthetic data only.
Confirmed rules and decisions: {{confirmed_rules}}
Scenarios:
{{scenarios}}
Tasks:
1. For each scenario, give one table row: test id (the scenario id), level, given data (concrete values), action, expected result. Take the expected result from the scenario wording only.
2. Propose extra cases for boundaries, permissions, failures part-way and concurrency. Mark each "Proposed" and give it a new id.
3. If a case depends on a rule that I have not stated, write "Decision needed: ..." and name the role that should decide. Do not choose a value.
4. For each case, name the lowest level that can show it and say why in one line.
5. List any scenario that is too vague to turn into a test.Expected output and limitations
A table with one row per scenario (id, level, concrete given data, action, expected result), then a short list of proposed extra cases, any 'Decision needed' items with a role, and a list of vague scenarios.
FR-02.1 | integration | Patient A, booking starts 2026-12-01 11:00 UTC (25 h away) | Patient A cancels | status cancelled, slot free
FR-02.2 | integration | Patient A, booking starts 2026-12-01 09:00 UTC (23 h away) | Patient A cancels | refused, still booked, message gives phone and hours
FR-02.3 | integration | Patient A holds the booking, Patient B signed in | Patient B cancels it | not found, still booked
NFR-01 | integration | one free slot | two bookings at once | one success, one "slot taken"
Proposed FR-02.4 | unit | exactly 24 h away | cancel | Decision needed: allowed or refused? Role: practice manager.
Proposed FR-02.5 | integration | booking already cancelled | cancel again | unchanged, no second history row
Vague: FR-02.1 says "the slot is freed" but not who can see it or when.Limitations to keep in mind
- The assistant proposes cases from typical systems. Some will not apply to Tidewell and some important ones will be missing.
- It may copy an expected result from code you pasted, or invent one. Check every expected result against the criterion.
- A long list of cases is not a complete one. Completeness is judged against your Must scenarios and the traceability table.
Common errors and how to fix them
Test cases use vague data such as 'a booking soon' or 'some patient'.
Why it happens: The scenario wording was copied without adding exact values or a fixed clock.
Fix: Write real values, including the clock time, so that anyone can set up the same starting state.
The expected result is whatever the code returned the first time.
Why it happens: The test was written by running the code and pasting the output.
Fix: Write the expected result from the criterion before you run anything. If the code disagrees, one of them is wrong, and you decide which.
Every case is an end-to-end test.
Why it happens: End-to-end tests feel closest to what a user does.
Fix: Test each rule at the lowest level that can show it. Keep a few end-to-end tests for the key journeys.
Validation checklist
Tick each item once you have confirmed it.
Hands-on exercise
Test cases for a Ferngate requirement
Take the Ferngate requirement 'A mechanic can record a part taken for a job' and its scenarios from the Acceptance Criteria exercise. Write a table of test cases with ids, levels, concrete data, actions and expected results. Then write the names of the automated tests, with ids, for the Must cases.
You will need
- Your Ferngate scenarios for recording a part taken for a job.
- Note: a part has a stock count. Taking the last one leaves zero.
- Note: the low-stock threshold is 'to be agreed' with the owner.
- Note: mechanics share one tablet, and the workshop's connection is unreliable.
Acceptance criteria
Your work is done when every one of these is true.
Hints (2)
- Ask what a mechanic sees when they take a part that the system thinks is out of stock. That is another decision for the owner.
- A rule about numbers, such as 'stock cannot go below zero', can be checked by a unit test with no database.
Show a model answer
A strong answer starts with the main case: a mechanic takes one part for a job and the stock count falls by one, with the movement attributed to them. It then adds the boundary (stock 1 becomes 0, stock 0 refused or allowed — a decision for the owner), a part that does not exist, a wrong job number and a lost connection. The low-stock flag is a unit test with several values around the threshold, but the threshold itself stays 'Decision needed' until the owner agrees. The stock arithmetic is a unit test, because it needs no database. The recorded movement is an integration test, because the database must hold it. Each test name starts with its id, for example 'FER-01.1 taking one part reduces stock by one'.
Knowledge check
Choose an answer, then check it. Nothing is recorded — this is for you.
Show the answer and explanation
Answer: B. It states what a person would observe, and it comes from the criterion. 'Whatever it returns today' is tempting because it always passes, but it only records the code's behaviour, bugs included. 'The database is updated' is wrong here, because the rule is that nothing changes.
Show the answer and explanation
Answer: B. A rule with exact boundaries is cheap to check as a unit test, and the integration test proves the rule is really used. An end-to-end test is tempting because it feels real, but it is slow and fails without saying why. Leaving the boundary untested is the most common way for this rule to break.
Show the answer and explanation
Answer: B. It links requirements, scenarios and tests, so gaps are visible. It does not prove quality, which is the tempting reading: a test can be listed in the table and still check nothing.
Frequently asked questions
What is a test case?
A test case is one specific check. It says what data to start with, what action to take and what result to expect. An automated test is a test case written as code so a machine can run it.
What is the difference between unit, integration and end-to-end tests?
A unit test checks one function on its own. An integration test checks parts working together, such as a service and a database. An end-to-end test drives the whole running app, usually through a browser, like a real user.
How many tests do I need?
At least one for every Must scenario, plus the boundary, permission and failure cases that go with it. The number matters less than the coverage of what you promised. Add a test when you find a bug, so it cannot come back.
Can an AI assistant write my test cases?
It can draft them quickly and suggest cases you forgot. You must still check each expected result against your acceptance criteria, because the assistant may copy the code's behaviour or invent a rule. Give it the criteria, not only the code.
- Written by
- PromptFable Editorial
- Last updated 19 Nov 2026
- Review
- Reviewed by Waseem Nadir, Technical Reviewer
- Last reviewed 27 Nov 2026
References
Primary sources for the technical details in this lesson. Vendor platforms change — check the official page if anything here looks different from what you see.
- Test runner(opens in a new tab)
Node.js · Official documentation · The built-in test runner used in this lesson: test, assert, reporters and running TypeScript files through a loader.
- The Practical Test Pyramid(opens in a new tab)
Martin Fowler · A clear explanation of why most checks should be fast, low-level tests and few should drive the whole app.
- Installation(opens in a new tab)
Playwright · Official documentation · Getting started with Playwright, the end-to-end tool used as the example in this program.
- PGlite(opens in a new tab)
PGlite · Official documentation · The real PostgreSQL engine that runs inside Node, used for integration tests without a database server.
PromptFable is independent and is not affiliated with, endorsed by or sponsored by Anthropic, Google, OpenAI or any other vendor. Claude, Gemini, Google AI Studio and other product names are trademarks of their respective owners.