The Testing Pyramid is a visual aid used to find the right balance of test types. Here are some notes about how it works and suggestions I've collected over time:
- The bulk of your tests are unit tests at the bottom of the pyramid. As you move up the pyramid, your tests gets larger, but at the same time the number of tests (the width of your pyramid) gets smaller.
- Google suggests a 70/20/10 split: 70% unit tests, 20% integration tests, and 10% end-to-end tests. The exact mix will be different for each team, but in general, it should probably retain that pyramid shape. The key thing is to avoid these anti-patterns:
- Inverted pyramid/ice cream cone. Mostly end-to-end tests, few integration tests, and even less unit tests.
- Hourglass. A lot of unit tests, then many end-to-end tests where integration tests should be used. The hourglass has many unit tests at the bottom and many end-to-end tests at the top, but few integration tests in the middle.
- E2E tests are useful, but should be the least number of tests of its kind that you write. Focusing on quality over quantity is the most valuable thing you can do.
Photo credit: Google Testing Blog
- From easiest to most difficult to write: snapshot, unit, integration, E2E
- From least to most important*: snapshot, unit, integration, E2E
* where the level of importance is directly proportional to the confidence you have that your tests are reflective of your app working as intended
In the next few blog posts I'll be discussing each type of testing and recommended best practices, specifically for React applications.