Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Collaboration  ›  Lesson

Unit, Integration and E2E Tests

Unit Testing 14 minUnit tests check one piece, integration tests check the joins between pieces and end-to-end tests check a whole user journey; in an AI product most of them fake the model, and each must be shown able to fail.

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.

Picking tests for Pantry PalStep 1 of 4
  1. 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.

quick drill

Which test best catches the allergy filter mishandling "PEANUTS" in capitals?

quick drill

The server saves itemName, but the database field is called item_name. Which test catches this?

quick drill

Why fake the AI model in most automated tests?

quick drill

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.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainWhich test catches it?

For Pantry Pal's new shared-pantry feature, name one unit test, one integration test and one E2E test you would write, say which bug each would catch, and explain how you would check that the tests are real.