Skip to content
tezvyn:

The Testing Trophy: Prioritize Integration Tests

Source: kentcdodds.comMediumHow cards are made

The Testing Trophy: Prioritize Integration Tests

The Testing Trophy flips the classic pyramid, arguing for "mostly integration tests" to maximize your return on investment. It's for UI apps where testing component interactions gives more confidence than isolated unit tests.

Why it exists

Classic testing models like the Testing Pyramid didn't perfectly map to the realities of modern UI development. In component-based apps, many bugs aren't in a single function's logic but in the seams between components. A new mental model was needed to reflect the high return on investment from testing these interactions.

The mental model

The Testing Trophy is a visual guide for test distribution, shaped by ROI. Imagine a trophy: a wide middle section (Integration Tests), a smaller base (Unit Tests), and a small top (End-to-End Tests), all standing on a large platter (Static Analysis). This shape emphasizes that the bulk of your effort should be on integration tests because they provide high confidence at a reasonable cost.

How it works

The trophy categorizes tests by scope and purpose. Static analysis (like TypeScript or ESLint) forms the foundation, catching errors before runtime. Unit tests verify the smallest pieces of logic, like a single function, in isolation. Integration tests, the core of the trophy, check that several units work together as expected—for example, a form component with its input fields and a button. End-to-end (E2E) tests sit at the top, automating a real user journey through the entire application. The trophy advises writing a lot of integration tests, fewer unit and E2E tests, and relying heavily on static analysis.

When to use it

This model is ideal for JavaScript applications, especially those built with component-based frameworks like React, Vue, or Angular. Use it when you want to write tests that are resilient to refactoring and provide strong confidence that your application works for users. It's the philosophy behind popular tools like Testing Library.

When not to use it

The Testing Trophy is explicitly framed for UI applications. While the principle of ROI is universal, the specific distribution might not apply to backend services or libraries with complex, isolated algorithms. For those, a more traditional testing pyramid with a larger base of unit tests might be more appropriate. Don't treat the trophy's shape as a dogmatic rule for every project.

One canonical example

Consider a login form component. A unit test might check that the email validation function works correctly. An E2E test would launch the app and simulate a full login. The Testing Trophy's sweet spot, the integration test, would render the entire form component, simulate a user typing into the fields, click submit, and assert that the correct API call was attempted. This tests the collaboration of all the form's parts without the slowness of a full E2E test.

Interview question

According to the Testing Trophy, what is the primary reason for prioritizing integration tests in UI applications?

  • a.They offer the most comprehensive coverage of all possible user paths, similar to end-to-end tests.
  • b.They effectively identify bugs in component interactions, providing high confidence at a reasonable cost.Correct
  • c.They are simpler to write and maintain than unit tests for complex component logic.
  • d.They are the fastest type of test to run, significantly speeding up the development process.
Why?

The card states that integration tests are prioritized because they address bugs in the 'seams between components' and offer 'high confidence at a reasonable cost.' While integration tests cover interactions, end-to-end tests are designed for the most comprehensive simulation of user paths.

Just read this? Test yourself on what you have been reading.

Read the original → kentcdodds.com

You just looked this up. Could you explain it out loud?

That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on testing — each one lists the topics its interview covers.

See open roles