Lesson 19.0

Orientation: why this chapter exists

Artifact: A clear picture of the test suite you'll have by the end of this chapter

1. The promise

You'll know what this chapter delivers, what you'll have built by the end, and why every chapter after this one assumes you wrote tests. About eight minutes at honest pace.

2. The mental model

Testing is the second half of writing software. The first half is making it work once. The second half is proving it still works on the thousandth change.

The first half is the exciting half. The second half is what you get paid for.

A test suite is the whole collection of tests for a codebase, run together as one command. A regression is a bug introduced by a change to code that used to work. Tests catch regressions before users do.

You arrived here with a working NestJS API from Ch 15 and a Next.js front-end from Ch 12. You leave here with a test suite that catches regressions before they land in production.

(SCREENSHOT: the unit page for 19.0 in the bootcamp web app — full window — table of contents on the right)

The chapter outcome is one number. By the end you'll have 80% line coverage on the Nest API and at least one Playwright happy-path that runs in continuous integration.

3. The chapter map

You'll walk this order. Each unit builds on the last.

  • The pyramid: why unit tests outnumber integration tests outnumber end-to-end tests.
  • Unit tests with Vitest against a pure function.
  • Test structure (arrange, act, assert) and test data factories.
  • The four kinds of test doubles: stub, fake, spy, mock.
  • What to mock, what never to mock.
  • Integration tests that boot the Nest module and hit a real Postgres database in a Docker container.
  • End-to-end tests with Playwright driving a real browser.
  • Snapshots, test-driven development, coverage that means something.
  • Flaky tests and how to fix them instead of retrying them.
  • A GitHub Actions workflow that runs every test on every pull request.

(SCREENSHOT: terminal running pnpm test against the Nest API with all tests passing — full window — green check marks visible)

The honest time commitment: sixteen content units across roughly four hours, plus three hours for the chapter assignment. Call it seven hours total.

(SCREENSHOT: GitHub Actions checks panel on a pull request with green check marks for unit, integration, and e2e jobs — full window)

One warning before you begin. Testing is the chapter most students skim because it's not as fun as building. The skim shows up six months later as a 3am pager. Don't skim.

A short note on tools. Vitest runs your unit and integration tests. Testcontainers spins up a real Postgres in a container so integration tests hit a real database. Playwright drives a real Chromium browser for end-to-end tests. GitHub Actions runs all of them on every pull request. One sentence each, because each gets a full unit later.

4. What you should be seeing

A clear picture of two things:

  1. By the end of this chapter, your Nest API has 80% meaningful coverage and your Next.js front-end has at least one Playwright test running in continuous integration.
  2. The chapter teaches the pyramid first, then walks bottom to top: unit, integration, end-to-end, then coverage, flakes, and CI.

If you can say those two things without looking back, you're done with this unit.

5. Common stumbles

  • You treat this chapter as optional. The next chapter on debugging assumes you've written tests. The chapter after that on refactoring requires a test suite you trust. Skipping here puts you on broken ground for the rest of the course.
  • You try to test your personal side project instead of the course's Nest API. The assignment is written for the API the course built. Rewrite it for your own at your own risk.
  • You skip ahead to Playwright because end-to-end tests feel impressive. They are the slowest, flakiest, most expensive tests in the suite. The pyramid exists for a reason. Walk the units in order.

6. You should know

1/17
Next