AI Hints
Home›CI/CD with GitHub Actions Tutorial›Fixing Builds and the Test Pyramid
CI/CD with GitHub Actions · Lesson 77 of 138

The Test Pyramid

Fast at the bottom.

⏱ 2 min read▶ Video at 1:28:17🎓 Free
Watch this lesson in the CI/CD with GitHub Actions courseWatch on YouTube ↗Full CI/CD with GitHub Actions course

Not all tests are equal. Some are tiny and fast, and others start a whole system and click through it. The test pyramid is a simple guide to how many of each you should have.

The Test Pyramid
From the video: The Test Pyramid
  • Tests come in sizes
  • Fast and small
  • Slow and big

The pyramid, bottom to top

At the bottom, many unit tests. They check one function, and run in milliseconds. In the middle, fewer integration tests. They check that parts work together, like your code and a database. At the top, a few end to end tests, that drive the whole app like a real user.

  1. Unit: many
  2. Integration: some
  3. End-to-end: a few
The pyramid, bottom to top
From the video: The pyramid, bottom to top

Comparing them

Unit tests are fast, cheap, and point straight at the problem. End to end tests give the most confidence that the real app works, but they're slow, and more likely to be flaky. A healthy suite has lots of the first kind, and just enough of the last.

KindSpeedFinds
Unitmillisecondsone function's bugs
Integrationsecondsparts not fitting
End-to-endminuteswhole-app problems

In the pipeline

This maps neatly onto CI. Run unit tests on every push. Run integration tests on pull requests, maybe with service containers. And run end to end tests before a deploy, or nightly, if they're slow.

keyvalue
Unitevery push
Integrationevery PR
End-to-endbefore deploy
Very slow?nightly

Summary

Many fast unit tests, some integration tests, and a few end to end tests. Next, a quiz on quality.

Key takeaways
  • Unit: many
  • Integration: some
  • E2E: few
Next up: Quality Quiz — test yourself