The Testing Pyramid and the Testing Trophy
Compare the testing pyramid and the testing trophy for JavaScript apps: what each says about unit, integration and end-to-end tests, and how to choose.

Every team that writes tests ends up asking the same question: how many of each kind? Unit tests are fast and precise but can pass while the product is broken. End-to-end tests prove the product works but are slow and fragile. Two pictures have shaped the answer for years. The testing pyramid says to write many unit tests, fewer integration tests and very few end-to-end tests. The testing trophy, popularized in the JavaScript community, says to put most of your effort into integration tests, with a base of static analysis and a thin layer of unit and end-to-end tests. They are not rival laws. They are two answers to one trade-off, and each fits different code. This post explains both shapes, what each layer is for, why the trophy appeared, how they apply to a JavaScript application and how to choose a balance for your own project. The terms follow Martin Fowler's practical test pyramid and the Testing Trophy described by Kent C. Dodds. The examples use Vitest 4 on Node.js 24, and the ideas hold for any runner.
The trade-off behind both shapes
Tests differ along three axes. Speed: how long a test takes to run, which decides how often developers run it. Confidence: how likely a green result means the feature works for a user. Cost of maintenance: how often a test breaks for reasons unrelated to a real bug. A test at the bottom of the stack, close to one function, is fast, gives a precise failure and rarely breaks for unrelated reasons, but it says little about how the parts fit together. A test at the top, driving the real application in a browser, says a lot, and it is slow and breaks when a button moves.
You cannot have all three at once, which is why the shapes exist. They are advice about where on that line most of your tests should sit.
The testing pyramid
The pyramid has three layers. The wide base is unit tests: they test one function or class in isolation, with its collaborators replaced or absent, and run in milliseconds. The middle is integration tests, which test several units working together, perhaps with a real database or a real HTTP server. The narrow top is end-to-end tests, which drive the whole system through its real interface, such as a browser.
/\
/ \ end-to-end: few, slow, high confidence per test
/----\
/ \ integration: some
/--------\
/ \ unit: many, fast, cheap to run and diagnose
/------------\(a pyramid: the wider the layer, the more tests it should hold)The reasoning is economic. Because lower tests are faster and cheaper, you can afford thousands of them, and because they are precise, a failure points to the broken function. Higher tests are expensive, so you write only enough of them to confirm that the main paths work end to end.
A pyramid-shaped suite for a small Node.js service might look like this: many tests for pure functions such as price calculation, fewer tests that exercise the HTTP handlers with a test database and a handful of tests that drive the deployed service.
import { describe, expect, test } from "vitest";
import { totalWithTax } from "./price.js";
describe("totalWithTax", () => {
test("adds the tax rate to the subtotal", () => {
expect(totalWithTax(100, 0.2)).toBe(120);
});
test("rounds to two decimals", () => {
expect(totalWithTax(9.99, 0.07)).toBe(10.69);
});
}); ✓ price.test.js (2 tests)
Test Files 1 passed (1)
Tests 2 passed (2)These tests run in a few milliseconds and tell you exactly which rule broke. The weakness of an all-unit suite is that it can be completely green while the application is broken, because each unit works alone and the wiring between them is wrong.
The testing trophy
The trophy changes the proportions. From the bottom, it has static analysis, which means types and linting, catching whole classes of mistakes before any test runs. Then unit tests, a thin layer. Then the large middle: integration tests. Then a small cap of end-to-end tests.
____
/ e2e \ a few, for critical user journeys
/--------\
| |
|integration| the largest part: components and modules working together
| |
\--------/
/ unit \ for tricky logic
/----------\
| static | types, linting, formatting
------------(a trophy: a base of static checks, a modest unit layer, a large integration layer and a small end-to-end cap)The argument is that integration tests give the best return. They exercise real behavior, such as a component rendering with its children and handling a click, or a handler talking to a database, without the cost of launching a browser. And because they test through the public interface, they survive refactoring: you can rewrite the internals and the tests keep passing, since they never knew how the work was done. The slogan that goes with it is to write tests that resemble how the software is used.
Static analysis sits at the base for a reason. TypeScript and ESLint find typos, missing arguments, wrong types and unreachable code on every save, for almost no cost, and this removes a category of unit tests that would only check that you passed the right number of arguments.
A trophy-style test for a React component renders it, interacts like a user and checks what appears.
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { expect, test } from "vitest";
import { SignupForm } from "./SignupForm.jsx";
test("shows an error for an invalid email and a success message for a valid one", async () => {
const user = userEvent.setup();
render(<SignupForm />);
await user.type(screen.getByLabelText("Email"), "nope");
await user.click(screen.getByRole("button", { name: "Sign up" }));
expect(screen.getByRole("alert")).toHaveTextContent("Enter a valid email");
await user.clear(screen.getByLabelText("Email"));
await user.type(screen.getByLabelText("Email"), "[email protected]");
await user.click(screen.getByRole("button", { name: "Sign up" }));
expect(screen.getByRole("status")).toHaveTextContent("Thanks for signing up");
}); ✓ signup.test.jsx (1 test)
Test Files 1 passed (1)
Tests 1 passed (1)This single test covers the form's rendering, validation, event handling and messages, together. It does not know whether the form uses useState or a library, so rewriting it will not break the test.
What each layer is for
Understanding the purpose of each layer matters more than the shape.
Unit tests are best for logic with many cases and few dependencies: parsers, formatters, pricing rules, state machines, algorithms. They are quick to write and quick to diagnose. They are poor for code that mostly coordinates other code, where a unit test ends up asserting that the right methods were called, which tests the implementation and breaks on every refactor.
Integration tests are best for checking that parts agree with each other: a handler and its validation, a component and its store, a repository and a real database. They catch the wiring bugs that unit tests cannot. Their cost is setup, such as a test database or a mock server, and a failure points to a region, not a line.
End-to-end tests are best for the few journeys that must never break: sign up, log in, pay. They are the only tests that exercise the real browser, network and deployment together, and also the slowest and most prone to flakiness, because they depend on timing and the state of the environment.
Why the shapes differ
The pyramid comes from a time when integration and end-to-end tests were slow and painful, with heavy servers and manual setup, so keeping them rare was practical. Modern tooling changed the cost. In-memory databases, containers, fast test runners, mock servers at the network level and component testing libraries make integration tests cheap, which moves the economic balance toward the middle layer. The trophy reflects that change, and the emphasis on "resembling use" reflects a lesson about unit tests that mock everything: they pass, and the app still breaks.
There is also a difference in what the words mean. Many people's "unit test" is a test of a class with all of its collaborators mocked, and in the trophy view that kind of test is the one to limit. Other people's "unit" is any fast, isolated test, including one that uses real in-memory collaborators. The disagreement is often about definitions, so agree on your team's meaning before arguing about shapes.
Choosing a balance
Ask what kind of code you are writing. A library of pure functions, such as a date or parsing utility, is naturally a pyramid: almost everything is a unit test, since there is little to integrate. A front-end application is naturally a trophy: most of its value is in components working together with state and the network, so integration-style component tests dominate. A back-end API sits between: unit tests for domain rules, integration tests for endpoints against a real database and a few end-to-end checks.
Then look at your pain. If bugs keep appearing at the seams between modules while all the unit tests are green, move effort to integration tests. If your suite takes thirty minutes and developers stop running it, you have too many slow tests at the top. If refactoring breaks dozens of tests without changing behavior, your tests are coupled to implementation, and moving up a level, to the public interface, is the fix.
A practical default is to keep the suite fast enough to run on every save for the bottom layers, run integration tests on every push and run end-to-end tests on every merge or before release. Measure what the layers cost, in time and in flaky failures, and let the numbers from your own project, not a diagram, decide.
Whatever the shape, keep a few habits. Test behavior, not implementation. Give every failure a clear message. Delete tests that no longer pay for themselves. Treat flaky tests as bugs, since a test nobody trusts is worse than no test.


