Generate unit tests, surface edge cases you hadn't considered, and strengthen weak suites — with Claude doing the typing and you owning the judgement of what "correct" means.
Read time13 min
LevelBasic → Advanced
Quiz3 questions
SectionBootcamp 2026
01 — what & why
Tests are how you trust AI-written code
You can't review every line forever. Tests are the durable proof that behaviour is what you intend — especially for code Claude wrote.
Have Claude generate tests, but you decide the cases that matter. It's great at covering the obvious paths and enumerating edge cases; you judge which are real. See the QA modules: Ticket Pipeline and Context Manager.
Ask Claude "what edge cases am I missing?" — it's one of its highest-value moves.
02 — the technique
Cover the happy path, then hunt edges
A good suite proves the feature works and pins down what happens at the boundaries.
✓
Start from behaviour
Test the acceptance criteria, not the implementation.
Coupling tests to implementation makes refactors painful.
03 — worked example (Leave Management)
Jest tests for calculateLeaveBalance
Cover the happy path and the edge cases you might not think of. At least one should fail if the logic breaks.
javascript
describe('calculateLeaveBalance', () => {
it('subtracts approved days from the allowance', () =>
expect(calculateLeaveBalance([{ status: 'approved', days: 3 }])).toBe(17));
it('ignores pending and rejected requests', () =>
expect(calculateLeaveBalance([{ status: 'pending', days: 5 }])).toBe(20));
it('handles a fully-used balance (zero)', () =>
expect(calculateLeaveBalance([{ status: 'approved', days: 20 }])).toBe(0));
it('is unaffected by an empty history', () =>
expect(calculateLeaveBalance([])).toBe(20));
});
✓
Edge cases covered
Zero balance, mixed statuses, empty history. Overlap/negative requests are rejected upstream (422).
✗
Watch out
Don't assert on internal calls — assert on the returned balance.
Now do this on YOUR project: ask Claude "what edge cases am I missing?" for your feature, then add tests for the real ones.
04 — integration testing
Beyond units: test the pieces working together
Unit tests prove one function is correct (slide 03, and the reusable unit-test skill). Integration tests prove the seams hold — the route hits the service hits the DB, or the UI actually renders and submits. Claude can drive these too, through the right tools.
Tool
What it tests
How Claude uses it
Vite (Vitest)
Fast unit + component/integration tests in a Vite/JS project — API handlers, React components with mocked boundaries
Generates and runs the spec; shares config across a monorepo's packages
Playwright MCP
Real end-to-end flows in a browser — log in, apply for leave, see it in the list
Claude drives the live browser via the MCP, asserts on what the user actually sees
Chrome DevTools MCP
Inspect a running page — console errors, network calls, the DOM — while a flow runs
Claude reads real console/network output to verify and debug the integration
Why a monorepo makes this easier. When the API, the web app, and shared types live in one repo (see Feature Development), a cross-layer test can import the real types, spin up the real handler, and drive the real UI — no version-drift between separately-versioned repos, one npm test at the root. A lone fullstack dev (or a QA engineer working against a black-box deploy) has to stub the other half and guess at contracts; the monorepo removes that guesswork.
Now do this on YOUR project: pick one user journey and have Claude write a Playwright end-to-end test for it, using the Chrome DevTools MCP to confirm there are no console/network errors along the way.
05 — best practices
Tests are how you trust AI code
Generate tests, then make them earn their keep on edges and behaviour — not implementation.
✓
Write failing tests first
Commit the failing test before writing implementation — the diff proves Claude fixed the code and didn’t just rewrite the test to pass.
✓
Reproduce before fixing every bug
Write a failing test that reproduces the bug, commit it, then fix — without it, the bug can silently reappear in any future refactor.
✗
Tests written after the implementation
Tests written after mirror what the code already does — they confirm existing behaviour but can’t catch the bugs the code was written with.
✗
Chase 100% coverage
80% is the practitioner standard; concentrate effort on payment, auth, and business-logic paths — coverage theatre on utility code wastes cycles.
Check your understanding
1. Why are tests especially important for AI-written code?
Correct.Not quite — the correct answer is highlighted above.
2. What is a high-value question to ask Claude about your tests?
Correct.Not quite — the correct answer is highlighted above.
3. What is wrong with a test that can never fail?
Correct.Not quite — the correct answer is highlighted above.
Basic · GuidedProject: Leave Management System
Generate unit tests for one function
Objective: get a focused unit-test suite for one function, covering the main paths.
prompt
Write unit tests for this function.
Cover the happy path and the obvious failure paths.
Use our test framework; assert on behaviour, not internals.
Pick one function with clear inputs/outputs.
Generate the tests and read each assertion.
Run them; confirm they pass and actually test something.
✓
Done when
Tests pass and each asserts a real behaviour.
✗
Watch out
Tests that assert on internal calls instead of results.
Discuss with your facilitator: which of the generated tests would fail if the function were subtly broken?
Intermediate · Semi-guidedProject: Leave Management System
Find and cover the edge cases
Objective: ask Claude to enumerate edge cases for a feature, pick the real ones, and add tests for them.
Ask "what edge cases am I missing?" for one feature.
Select the cases that are genuinely possible.
Add tests; watch at least one fail, then fix the code.
✓
Done when
New edge-case tests exist and drove at least one real fix.
✗
Watch out
Adding tests for impossible states while missing likely ones.
Discuss with your facilitator: which edge case surprised you, and why hadn't you thought of it?
Advanced · Open challengeProject: Leave Management System
Strengthen a weak suite
Objective: take an existing thin suite (or generate a feature then its suite) and improve coverage of the risky paths, including one integration-level test.
✓
Done when
Coverage of the risky paths improved, with a working integration test.
✗
Watch out
Chasing a coverage % with tests that can't fail.
Discuss with your facilitator: where is the remaining risk your tests still don't cover?