Lesson 21 — Unit Testing: The Smallest Tests of All · Practical QA
LESSON VIEW
B-15 · BASIC · PRACTICAL QA

Lesson 21 — Unit Testing: The Smallest Tests of All

Objective: The inside-the-code layer that completes your map of EVERY type of testing.

⏱ ≈4 min full lesson · Converted from the B-15 module deck · English edition — Español · العربية · বাংলা in translation

⚡ Key Points

  • Inside, not outside — Every test so far worked from the OUTSIDE (open page, click, check).
  • Same bug, closer to the cause — UI test: “the total on screen is wrong.” Unit test: “the tax function turns 8.875% into 0.8875 — THERE's the bug.” Same…
  • The shape of a unit test — Written for this tutorial (labeled, as always): notice what's ABSENT — no page, no goto, no waiting.
  • The pyramid, complete — UNIT (many, tiny, instant, inside) → API (fewer, fast, machine-to-machine, B-11) → UI/JOURNEY (fewest, slowest, widest,…
  • Where TestGen fits — Honest status: TestGen's repo → unit-test module is roadmap P4-2, NOT built today.
  • Plug & chug: boundary table — Pick one rule (free shipping ≥ $75; 10% discount; age ≥ 18).

📖 Read

In ~4 minutes: the inside-the-code layer that completes your map of EVERY type of testing.

Inside, not outside: Every test so far worked from the OUTSIDE (open page, click, check). A UNIT test works from the INSIDE: take one small piece of code — a function, a rule — and verify it alone. No browser, no page, no network.

Same bug, closer to the cause: UI test: “the total on screen is wrong.” Unit test: “the tax function turns 8.875% into 0.8875 — THERE's the bug.” Same failure, wildly different distance to the cause. Unit tests are the fastest (thousands per second) and most precise — and need access to the code itself.

The shape of a unit test: Written for this tutorial (labeled, as always): notice what's ABSENT — no page, no goto, no waiting. Just input → expected output. And notice the cases: AT the line ($75) and one cent below — rules break at their boundaries. Code: test("free shipping at exactly $75", () => { | expect(shippingFor(75)).toBe(0); | }); | test("standard shipping below $75", () => { | expect(shippingFor(74.99)).toBe(6.95); | });

The pyramid, complete: UNIT (many, tiny, instant, inside) → API (fewer, fast, machine-to-machine, B-11) → UI/JOURNEY (fewest, slowest, widest, the only layer that sees what users see). Healthy projects are pyramid-shaped. An inverted pyramid — all UI, no units — is slow, flaky, and vague.

Where TestGen fits: Honest status: TestGen's repo → unit-test module is roadmap P4-2, NOT built today. The browser track (UI/API) is what's real. This module teaches the concept completely; only the generator is pending.

Plug & chug: boundary table: Pick one rule (free shipping ≥ $75; 10% discount; age ≥ 18). Write its boundary cases: at the line, just below, just above, zero, nonsense input. Five rows = a unit suite in embryo — and it's how professionals actually start.

Basic tier complete: you hold the whole map. The OOP track is beside you in the module map; Advanced awaits when you're ready.