Unit, Integration and E2E Tests
Every time Asha's assistant changes Pantry Pal, something might break far from the change. She cannot click through every screen after every edit. Automated tests do the clicking for her, but each kind catches a different sort of bug.
The rule
Unit tests check a piece, integration tests the joins, end-to-end the whole journey.
- Unit test — one small piece on its own, such as a single function. Fast and precise: when it fails, you know exactly what broke.
- Integration test — several pieces working together, such as a server route and the database. It catches bugs at the joins: mismatched field names, missing data, broken wiring.
- End-to-end (E2E) test — a scripted browser acts like a user in the real app. It proves a whole journey works, but it is slower and breaks more easily when the design changes.
The usual balance is a pyramid: many unit tests, fewer integration tests, and a handful of E2E tests for the journeys that must never break.
test("removes dishes that contain an allergen", () => {
const dishes = [{ name: "Satay noodles", ingredients: ["noodles", "peanuts"] }];
expect(removeAllergens(dishes, ["peanuts"])).toEqual([]);
});Two rules matter for an AI product:
- Fake the model in most tests. Real model calls are slow, cost money and give different answers each time. Unit and integration tests use a stand-in that returns a fixed answer; the quality of real answers is the eval set's job.
- Make sure each test can fail. Assistants sometimes write tests that pass whatever the code does. Break the code on purpose once. If the test still passes, it tests nothing.
You do not have to write tests by hand to benefit from them. Ask the assistant to add them with each slice, then read the test names: they should read like your acceptance checks.
The shortcut
Where would this bug live? Inside one piece → unit test. Between pieces → integration test. Only visible to a user clicking through → E2E test.
The allergy filter
One function with clear inputs and outputs. Unit tests: the one above, plus cases for capital letters and for "peanut" versus "peanuts".
Drills
Answer fast — trust the rule.
Which test best catches the allergy filter mishandling "PEANUTS" in capitals?
The server saves itemName, but the database field is called item_name. Which test catches this?
Why fake the AI model in most automated tests?
A test written by the assistant still passes after you delete the code it tests. What does that mean?
Remember
- Unit tests check a piece, integration tests the joins, end-to-end the whole journey.
- Ask "where would this bug live?" and keep the pyramid: many unit, fewer integration, few E2E.
- Trap: tests that cannot fail, and tests that call the real model every time.
