FSD Frontend System Design

Chapter 4 · Testing

Revision sheet

Every lesson's idea and recap on one page. Read it before an interview, or print it.

  1. 4.1Testing Overview

    Buy the most confidence per second of CI time — that ratio decides the shape of your suite.

    • Optimise for confidence per second of CI, not for coverage percentage.
    • Push detail down the pyramid, confidence up.
    • An ignored suite and no suite protect you equally.
  2. 4.2Unit & Integration Testing

    Unit tests prove one thing in isolation; integration tests prove the seams between them hold.

    • The difference is scope and what you mock, nothing else.
    • Mock at the network boundary; module mocks test your file layout.
    • Assert on what the user sees, not on how the code got there.
  3. 4.3E2E and Automation Testing

    A real browser walking a real user journey — few of them, and none of them flaky.

    • Few tests, high value, real browser, money paths only.
    • Every sleep is a latent flake; wait on assertions instead.
    • Seed via API, stub third parties, isolate data per test.
  4. 4.4A/B Testing

    Ship two versions to real users, measure one metric, and let the data decide.

    • Sticky, deterministic, server-side assignment; render on first paint.
    • Log exposure on render, not on assignment.
    • One primary metric, one guardrail, a fixed duration, and no peeking.
  5. 4.5Performance Testing

    Turn performance into a build gate with numbers, so regressions fail CI instead of shipping.

    • Budgets in CI beat performance sprints, because they prevent instead of repair.
    • Lab numbers gate merges; field numbers tell you the truth.
    • Median of three runs, p75 of real users.
  6. 4.6Test-Driven Development

    Write the failing test first — it forces you to design the interface before the implementation.

    • Red, green, refactor — and the red step is what proves the test works.
    • TDD is an interface design tool that produces tests as a by-product.
    • Reproduce every bug with a failing test before you fix it.
  7. 4.7Security Testing

    Automate the scans that never get done manually, and put them in the pipeline as gates.

    • Automate the boring scans and put them where they block, not where they nag.
    • SAST reads code, DAST attacks the app, SCA reads your lockfile — you need all three.
    • Header presence is testable; write it as a normal assertion.
  8. 4.8[BONUS] Testing React Components

    Query the way a user finds things, act the way a user acts, assert on what a user sees.

    • Role and label queries first; getByTestId is an admission of defeat.
    • getBy now, queryBy for absence, findBy for async.
    • userEvent over fireEvent, MSW over module mocks, states over internals.

Capstone

Write the test plan for a search-with-autocomplete feature across all four layers — unit, integration, E2E, and performance — and say what each layer alone would miss.