Module 07 · Lesson 7.3
Reviewing Assistant-Written Tests
On this page
- What you will learn
- Why a passing test can still protect nothing
- A weak test file, as an assistant might write it
- The break-it-on-purpose check
- Replace the weak test with a strong one
- Step-by-step workflow
- Reviewing assistant tests, and recording what you changed
- 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 smoke alarm with a flat battery looks exactly like a working one. It sits on the ceiling, the light is on, and you feel safe. You only find out when you press the test button. A weak test is the same: it is green, it looks busy and it protects nothing.
Assistants write tests fast, and most of them pass. That is the problem, because a passing test is not the same as a useful one. In this lesson you learn the signs of weak tests. Then you press the test button on your tests: you break the code on purpose and see which tests notice, with real results from the Tidewell project.
What you will learn
- Recognise the common signs of a weak test, such as no assertion, a mirrored expected value or a swallowed error.
- Run the break-it-on-purpose check and read the before and after results.
- Replace a weak test with one that fails when the behaviour it covers is broken.
- Review a batch of assistant-written tests with a checklist and write a note of what you changed and why.
Before you start
- Completed Unit and Integration Tests, or have a test file of your own to review.
- Access to any capable AI assistant.
- Optional: Node.js and the project from earlier lessons, if you want to run the examples.
Why a passing test can still protect nothing
People trust green results. A hundred green tests feel like safety. But a test only protects you if it would fail when the behaviour it covers breaks. A test that cannot fail gives you false confidence, which is worse than no test, because nobody checks the thing it claims to check.
- Assertion
- A line in a test that compares a result with what you expect, and fails the test if they differ.
- Mock
- A stand-in for a real part, such as a fake database or a fake email service, that returns answers you choose.
- Mutation
- A small deliberate change to the code, such as turning a
<into<=, to see whether the tests notice. - Mutation testing
- Trying many mutations and counting how many the tests catch. A mutation the tests miss points at a weak test.
Assistants produce weak tests for an understandable reason. They read your code, and then they write tests that agree with it. If the code has a bug, the test agrees with the bug. Here are the signs to look for.
| Sign | What it looks like | Why it fails you |
|---|---|---|
| No assertion | The test calls the code and ends. Nothing is compared. | It passes unless the code crashes. Wrong answers go unnoticed. |
| Always true | It compares a result with itself, or checks something that cannot be false. | It can never fail, so it checks nothing. |
| Mirrors the code | The expected value is worked out with the same formula as the code, or copied from what the code printed. | A bug in the formula appears on both sides and cancels out. |
| Mocks the thing under test | The database or the rule is replaced by a fake, and the test checks the fake was called. | It tests the fake. The real code can be completely wrong. |
| Snapshot of wrong output | The test saves today's output and compares tomorrow's with it. | If today's output is wrong, the wrong answer is now the expected one. |
| Catches and ignores errors | The call sits in a try with an empty catch. | Every failure is swallowed, so the test always passes. |
| Far from the edge | Only easy values, such as 48 hours or 2 hours. | The mistakes live at the boundary, and nothing tests the boundary. |
A weak test file, as an assistant might write it
Suppose you asked an assistant for tests of the 24-hour rule and pasted the code. It might hand back this file. Read each test before you read the explanation, and ask of each one: what would make it fail?
// What an assistant first wrote for the notice rule. Every test passes. Most protect nothing.
import assert from "node:assert/strict";
import { test } from "node:test";
import { isInsideNoticePeriod, NOTICE_PERIOD_HOURS } from "./rules";
import { cancelBooking } from "./service";
import { freshDatabase, NOW } from "./seed";
import { asPatient, givenBooking, SLOT } from "./helpers";
const hoursFromNow = (hours: number) => new Date(NOW.getTime() + hours * 60 * 60 * 1000);
test("notice period works", () => {
assert.equal(isInsideNoticePeriod(hoursFromNow(48), NOW), false);
});
test("rule gives a consistent answer", () => {
const startsAt = hoursFromNow(24);
assert.equal(isInsideNoticePeriod(startsAt, NOW), isInsideNoticePeriod(startsAt, NOW));
});
test("cancelling a booking exactly 24 hours away", async () => {
const db = await freshDatabase();
const bookingId = await givenBooking(db, 1, SLOT.exactly24h);
try {
await cancelBooking(asPatient(db, 1), bookingId);
} catch {
// errors are expected here
}
});
test("notice period constant is set", () => {
assert.equal(NOTICE_PERIOD_HOURS, 24);
});- 'notice period works' checks one value, 48 hours away. It is far from the boundary and it does not mention a scenario id.
- 'rule gives a consistent answer' compares a call with an identical call. It is always true.
- 'cancelling a booking exactly 24 hours away' calls the service inside a
try, ignores every error and asserts nothing. It passes whatever happens, even a crash. - 'notice period constant is set' checks that the number is 24. It repeats a value from the code, and says nothing about whether the rule uses it correctly.
✔ notice period works (0.5631ms)
✔ rule gives a consistent answer (0.0897ms)
✔ cancelling a booking exactly 24 hours away (1437.045ms)
✔ notice period constant is set (0.3599ms)
ℹ tests 4
ℹ suites 0
ℹ pass 4
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 11787.6916All four pass. That is exactly what makes them dangerous: on the good code, they look the same as strong tests. Your times will differ, because they depend on your computer. The only way to tell them apart is to break something.
The break-it-on-purpose check
The check has three steps. Make one small change that should break a promise. Run the tests. If none fails, the tests did not notice. The classic change for this rule is on the boundary. 'At least 24 hours' is allowed, so exactly 24 hours is fine. Change the comparison from < to <= and exactly 24 hours becomes 'too close', which breaks FR-02.4 and the practice manager's decision.
You can do this by hand: change the code, run the tests, then undo the change with Git. The script below does it safely on a copy of the folder, so your real code is never touched. It runs each test file before and after the change and reports the difference.
// Make one deliberate change to a COPY of the code and see whether the tests notice.
import { spawnSync } from "node:child_process";
import { cp, readFile, rm, writeFile } from "node:fs/promises";
import { join } from "node:path";
export interface Mutation {
file: string;
from: string;
to: string;
}
export interface RunSummary {
passed: number;
failed: number;
failures: { test: string; message: string }[];
}
export function runTests(dir: string, testFile: string): RunSummary {
const run = spawnSync(process.execPath, ["--import", "tsx", "--test", "--test-reporter=spec", testFile], {
cwd: dir,
encoding: "utf8",
});
const count = (label: string) => Number(new RegExp(`^ℹ ${label} (\\d+)`, "m").exec(run.stdout)?.[1] ?? 0);
// In the "failing tests" part of the report, each failed test is followed by its error message.
const failures = [...run.stdout.matchAll(/^✖ (.+?) \([\d.]+ms\)\n\s+(.+)$/gm)].map((m) => ({
test: m[1],
message: m[2].trim(),
}));
return { passed: count("pass"), failed: count("fail"), failures };
}
export async function breakIt(sourceDir: string, mutation: Mutation, testFiles: string[]) {
const copyDir = join(sourceDir, "..", ".break-it");
await rm(copyDir, { recursive: true, force: true });
await cp(sourceDir, copyDir, { recursive: true });
try {
const path = join(copyDir, mutation.file);
const original = await readFile(path, "utf8");
if (!original.includes(mutation.from)) throw new Error(`Could not find "${mutation.from}" in ${mutation.file}`);
const before = testFiles.map((file) => runTests(copyDir, file));
await writeFile(path, original.replace(mutation.from, mutation.to));
const after = testFiles.map((file) => runTests(copyDir, file));
return testFiles.map((file, i) => ({ file, before: before[i], after: after[i] }));
} finally {
await rm(copyDir, { recursive: true, force: true });
}
}import { breakIt } from "./break-it";
// "At least 24 hours" is allowed. Changing `<` to `<=` makes exactly 24 hours count as too close.
const results = await breakIt(
import.meta.dirname,
{ file: "rules.ts", from: "startsAt.getTime() < earliestAllowed", to: "startsAt.getTime() <= earliestAllowed" },
["assistant-draft.test.ts", "rules.test.ts", "scenarios.test.ts"],
);
console.log("Change: in rules.ts, `<` becomes `<=` (exactly 24 hours now counts as too close)");
for (const { file, before, after } of results) {
console.log(`\n${file}`);
console.log(` before the change: ${before.passed} passed, ${before.failed} failed`);
console.log(` after the change: ${after.passed} passed, ${after.failed} failed`);
console.log(` verdict: ${after.failed > 0 ? "the change was CAUGHT" : "the change was NOT caught"}`);
for (const failure of after.failures) console.log(` failed: ${failure.test}\n ${failure.message}`);
}What each part does
breakItcopies the folder to a temporary place, runs the chosen test files, applies the one-line change to the copy and runs them again. It always deletes the copy at the end.runTestsstarts Node's test runner as a separate process and reads the counts and the failure messages from its report.- A
Mutationis just three things: the file, the text to find and the text to put in its place. The script stops with an error if the text is not found. - The report prints, for each test file, the results before and after, and a verdict.
Run it with npx tsx break-it-report.ts. It runs each test file twice, so it takes about a minute. Here is a real run.
Change: in rules.ts, `<` becomes `<=` (exactly 24 hours now counts as too close)
assistant-draft.test.ts
before the change: 4 passed, 0 failed
after the change: 4 passed, 0 failed
verdict: the change was NOT caught
rules.test.ts
before the change: 4 passed, 0 failed
after the change: 3 passed, 1 failed
verdict: the change was CAUGHT
failed: FR-02.4 exactly 24 hours away is allowed
AssertionError [ERR_ASSERTION]: exactly 24 hours away is allowed: inside should be false
scenarios.test.ts
before the change: 5 passed, 0 failed
after the change: 4 passed, 1 failed
verdict: the change was CAUGHT
failed: FR-02.4 a booking exactly 24 hours away can be cancelled online
Error: Online changes need at least 24 hours of notice. Please phone the clinic on 01632 960 123, Monday to Friday, 8:00 to 18:00.Read the verdicts. The assistant's draft passed before the change and after it: not caught. The strong tests noticed. rules.test.ts failed on the exact boundary with a message that says which promise broke. scenarios.test.ts failed too: the service refused a booking that should be allowed, so the test stopped with the clinic's own phone message. That is a failure of a different kind, an unexpected error and not a failed comparison, and it is still a catch.
One change tests one weakness. Tools such as Stryker try hundreds of changes automatically. For a first project, three or four hand-picked changes on your most important rules are a good start: flip a comparison, remove the ownership check, return early without saving. For the background, read Mutation Testing Explained: Why Code Coverage Lies to You.
Replace the weak test with a strong one
A strong test is the reverse of a weak one. It takes its expected value from the criterion, uses data that sits on the edge, and checks the outcome that a person would care about. These are the two tests that caught the change.
const hoursFromNow = (hours: number) => new Date(NOW.getTime() + hours * 60 * 60 * 1000);
const cases = [
{ id: "FR-02.1", name: "25 hours away is outside the notice period", startsAt: hoursFromNow(25), inside: false },
{ id: "FR-02.2", name: "23 hours away is inside the notice period", startsAt: hoursFromNow(23), inside: true },
{ id: "FR-02.4", name: "exactly 24 hours away is allowed", startsAt: hoursFromNow(24), inside: false },
{ id: "FR-02.4", name: "one millisecond under 24 hours is inside", startsAt: new Date(hoursFromNow(24).getTime() - 1), inside: true },
];
for (const { id, name, startsAt, inside } of cases) {
test(`${id} ${name}`, () => {
assert.equal(isInsideNoticePeriod(startsAt, NOW), inside, `${name}: inside should be ${inside}`);
});
}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");
});| Weak test | Sign | Strong replacement |
|---|---|---|
| notice period works (48 hours) | Far from the edge | FR-02.4 exactly 24 hours is allowed, and one millisecond under is inside. |
| rule gives a consistent answer | Always true | A fixed expected value from the criterion for each row of the table. |
| cancelling exactly 24 hours away (try and ignore) | No assertion, swallowed error | FR-02.4 asserts the status is cancelled. An error now fails the test. |
| notice period constant is set | Mirrors the code | Deleted. The cases already test the rule, and the constant is visible in the code. |
A review checklist for any assistant-written test
- Does the test name start with a scenario id, and does the scenario exist?
- Does it assert something about the result or the saved data?
- Does the expected value come from the criterion and not from the code?
- Is the test free of
trywith an emptycatch, and free of mocks of the code under test? - Does the data include the boundary, or only easy values?
- Could you name one change to the code that would make it fail? Did you try it?
Step-by-step workflow
Step 1: Read each test and ask what would make it fail
Go through the signs table. Mark every test that has no assertion, always passes, mirrors the code or mocks the code under test.
What you should see: A marked list of suspects.
Step 2: Pick the changes that should be caught
For each rule, choose one change that breaks a promise: flip a comparison, drop an ownership check, skip a save.
What you should see: A short list of deliberate changes.
Step 3: Run the check
Apply each change to a copy and run the tests before and after. Use the script or do it by hand and undo with Git.
What you should see: A verdict per test file: caught or not caught.
Step 4: Fix what was not caught
For every miss, write or repair a test whose expected value comes from the criterion. Run the check again.
What you should see: The same change now makes a test fail.
Step 5: Delete or replace the useless tests
Remove tests that mirror the code or can never fail. A smaller honest suite is better than a larger false one.
What you should see: No test remains that you cannot explain.
Step 6: Write the review note
Record which assistant-written tests you changed, kept or deleted, and why. This is a deliverable of the module.
What you should see: A dated note in docs/test-review-notes.md.
- Read
Look for weak signs
- Break
One deliberate change
- Run
Before and after
- Fix
Criterion-based expected value
- Note
What changed and why
A test earns its place by failing when it should.
Reviewing assistant tests, and recording what you changed
| Task | Assistant's part | Your part |
|---|---|---|
| Write tests | Drafts tests from the criteria. | Give it the criteria and not only the code. Run and review everything. |
| Review tests | Lists tests with weak signs and suggests a change that each should catch. | Try the changes yourself. Its claims are guesses until you run them. |
| Fix tests | Rewrites a weak test. | Check that the expected value matches the criterion, then run the check again. |
| Decide what to keep | Nothing. | Keep what you can explain. Delete the rest. |
The module assignment asks for a note on which assistant-written tests you changed, and why. Keep it short and honest. This is an example of what an entry looks like. The entries are illustrative.
# Test review notes
## 2026-11-19: notice period tests (assistant draft)
| Test | Verdict | Change | Reason |
| --- | --- | --- | --- |
| notice period works | Replaced | Table of cases, ids FR-02.1, FR-02.2, FR-02.4 | Only tested 48 hours. The boundary was untested. |
| rule gives a consistent answer | Deleted | None | Compared a call with itself. Could never fail. |
| cancelling exactly 24 hours away | Replaced | FR-02.4 now asserts the booking is cancelled | It ignored errors and asserted nothing. |
| notice period constant is set | Deleted | None | Repeated a value from the code. |
Checked by: changing the comparison in the notice rule from < to <=.
Result: the draft tests still passed. The replacements failed on the 24-hour boundary.
Not checked: moving a booking (not built yet).An example note. Write your own entries from your own reviews.
Conclusion and your next step
A green test is not proof of anything until you have seen it fail. Weak tests have recognisable signs: no assertion, a result compared with itself, a value copied from the code, a mock of the thing under test, a swallowed error, and no values near the boundary. The break-it-on-purpose check finds them, because one wrong change should turn at least one test red.
Your next step: pick your capstone's most important rule, make one change that should break it, and see whether your tests notice. Fix any miss, then write your review note. Then continue to Continuous Integration Pipelines, where the checks run automatically on every change.
For more on checking AI-generated code, read AI Code Review: Catching Bugs Before They Ship or Prompt Engineering for QA: Property-Based, Mutation, and Contract Testing with AI.
Reusable prompt
Test reviewer
Asks the assistant to review a test file against the criteria, name weak signs and propose a change that each test should catch, without rewriting anything.
You are reviewing tests. Do not rewrite them and do not change the code under test.
Fictional clinic: Tidewell Physiotherapy. Stack: TypeScript, node:test and node:assert/strict.
Rule confirmed by the practice manager on 2026-11-19: online changes need at least 24 hours of notice, and exactly 24 hours is allowed.
Criteria: FR-02.1 outside the notice period the booking is cancelled. FR-02.2 inside it the booking is unchanged and the patient is told to phone. FR-02.4 exactly 24 hours away is allowed.
Tests to review:
test("notice period works", () => { assert.equal(isInsideNoticePeriod(hoursFromNow(48), NOW), false); });
test("rule gives a consistent answer", () => { const s = hoursFromNow(24); assert.equal(isInsideNoticePeriod(s, NOW), isInsideNoticePeriod(s, NOW)); });
test("cancelling a booking exactly 24 hours away", async () => { try { await cancelBooking(ctx, id); } catch { } });
Tasks:
1. For each test, list the weak signs it has: no assertion, always true, mirrors the code, mocks the thing under test, snapshot of wrong output, swallows errors, far from the boundary. Say "none" if it has none.
2. For each test, name one small change to the code under test that the test would NOT notice, and one that it would.
3. Say which criterion each test is meant to protect, or "none".
4. List missing cases that a criterion implies. Do not write them.Show the reusable template
Replace each {{placeholder}} with your own details.
You are reviewing tests. Do not rewrite them and do not change the code under test.
Context: {{organisation_and_stack}}
Rules and decisions: {{confirmed_rules}}
Criteria: {{criteria}}
Tests to review:
{{tests}}
Tasks:
1. For each test, list the weak signs it has: no assertion, always true, mirrors the code, mocks the thing under test, snapshot of wrong output, swallows errors, far from the boundary. Say "none" if it has none.
2. For each test, name one small change to the code under test that the test would NOT notice, and one that it would.
3. Say which criterion each test is meant to protect, or "none".
4. List missing cases that a criterion implies. Do not write them.Expected output and limitations
A table with one row per test: the weak signs found, a change the test would miss, a change it would catch, the criterion it protects, and then a list of missing cases. It should not contain rewritten tests.
1. "notice period works": far from the boundary. Would miss: changing < to <=. Would catch: returning false for everything. Protects: FR-02.1 (weakly).
2. "rule gives a consistent answer": always true. Would miss: any change. Would catch: only a crash. Protects: none.
3. "cancelling a booking exactly 24 hours away": no assertion, swallows errors. Would miss: refusing the booking. Would catch: nothing. Protects: FR-02.4 in name only.
Missing cases: 24 hours minus one millisecond (FR-02.4 boundary); a check that FR-02.2 leaves the booking unchanged.Limitations to keep in mind
- The assistant's 'would catch' and 'would miss' lines are predictions. Prove them by making the change.
- It may praise a test because it is tidy. Neatness is not protection.
- It cannot know which behaviour matters to the client. That comes from your criteria and decisions.
Common errors and how to fix them
The suite is large and green, so everyone assumes it is safe.
Why it happens: Nobody has checked that the tests can fail. Coverage figures were taken as proof.
Fix: Run the break-it check on the most important rules. A high coverage number only says that lines ran, not that results were checked.
A test's expected value is copied from the code or from its first output.
Why it happens: The test was written by running the code and pasting the result.
Fix: Write the expected value from the criterion first. If the code disagrees, decide which of the two is wrong.
The assistant fixed a failing test by changing the expected value.
Why it happens: It was asked to make the tests pass, and the easiest way was to edit the test.
Fix: A failing test is information. Find out whether the code or the criterion is wrong, and only then change one of them. Record it in the review note.
Validation checklist
Tick each item once you have confirmed it.
Hands-on exercise
Review three weak Ferngate tests
Ferngate's rule is: taking more parts than are in stock is refused. An assistant wrote three tests for it. Name the weak sign in each, name one change to the code that each would miss, and rewrite the weakest as a strong test with a criterion-based expected value.
You will need
- Test A: calls takePart with stock 10 and quantity 3, and asserts nothing.
- Test B: takes 3 from 10, and expects the result
10 - 3, which is the same formula the code uses. - Test C: takes 12 from 10 inside a try, with an empty catch, and ends there.
- Criterion FER-02.1: taking more than the stock is refused, and the stock is unchanged.
Acceptance criteria
Your work is done when every one of these is true.
Hints (2)
- Test B is weak even though it asserts something. Ask where its expected value came from.
- What would a mechanic see if the refusal were silently removed? Would any of the three tests fail?
Show a model answer
A is a test with no assertion: it passes if the code does not crash, even if the stock is wrong. B mirrors the code: the expected value uses the same subtraction, so a wrong formula appears on both sides. C swallows the error, so it passes whether the refusal works or not. The rewrite should say 'FER-02.1 taking 11 from a stock of 10 is refused and the stock stays 10', with exact numbers, and a second row for 10 from 10, which is allowed and leaves 0. To prove it can fail, remove the refusal check from a copy of the code: the rewrite must fail, and A, B and C must still pass, which shows why they were not worth keeping.
Knowledge check
Choose an answer, then check it. Nothing is recorded — this is for you.
Show the answer and explanation
Answer: B. A test that cannot fail gives no protection. Passing is tempting as proof, but a test that asserts nothing useful passes too. Speed matters for how often you can run a test, not for whether it is any good.
Show the answer and explanation
Answer: B. The change turns an allowed case (exactly 24 hours) into a refused one. If nothing fails, no test sits on that edge. 'The code is correct either way' is tempting, but the two versions give different answers at the boundary, so one of them breaks a decision the practice manager made.
Show the answer and explanation
Answer: B. A mirrored expected value always agrees with the code, so a wrong formula is never caught. Length is not the issue, and nothing forbids a formula. The fix is an expected value taken from the criterion, written before you look at the code.
Frequently asked questions
What is a weak test?
A weak test passes even when the code is wrong. Common causes are having no assertion, comparing a result with itself, copying the expected value from the code and ignoring errors. You find them by breaking the code on purpose and seeing that nothing fails.
How do I know if my tests are good?
Make a small, deliberate mistake in the code and run the tests. If a test fails, it is doing its job. If nothing fails, a test is missing or weak. Also check that every test traces to a scenario in your acceptance criteria.
What is mutation testing?
Mutation testing changes your code in small ways, such as flipping a comparison, and checks that your tests fail for each change. Tools such as Stryker automate it. The break-it check in this lesson is the same idea, done by hand on one rule.
Is code coverage enough to trust my tests?
No. Coverage only shows which lines ran during the tests, not whether the results were checked. A test with no assertion can give full coverage and still protect nothing. Use coverage to find untested code, and use the break-it check to judge the tests themselves.
- 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.
- What is mutation testing?(opens in a new tab)
Stryker Mutator · Official documentation · Explains mutation testing and the tool family that automates it, including a JavaScript and TypeScript version.
- Assert(opens in a new tab)
Node.js · Official documentation · Reference for the assertion functions used in this lesson, including rejects and deepEqual.
- Test runner(opens in a new tab)
Node.js · Official documentation · How the built-in test runner reports results, and how to choose a reporter.
- The Practical Test Pyramid(opens in a new tab)
Martin Fowler · A guide to what to test at which level, useful when you decide which weak tests to replace.
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.