Two MoTacon attendees are on the left. The MoTaacon logo is in the center, and to the right a prompt to Get Your Ticket.

The Test Automation Pyramid

The Test Automation Pyramid image
The pyramid is a visual heuristic and practical strategy for structuring automated testing. It visually represents the ideal balance of different types of tests. The concept remains the same: test early, test often, and concentrate your efforts where they're most efficient. There are several versions of the pyramid, and this definition relates to the Ministry of Testing model used in the Software Testing Essentials Certificate (STEC). 

  • Unit Tests. This bottom layer is the wide base, where the largest number of tests are performed. Unit tests are focused on the smallest testable parts of the code. We're talking about individual functions, methods, or classes, tested in complete isolation. They're incredibly fast and the most reliable to execute, pinpoint bugs with precision, and are generally cheaper to fix because you catch issues right as the code is being written.
  • API Tests. Next, above unit tests are API (Application Programming Interface) tests. These tests verify the functionality of your application's APIs directly, bypassing the user interface. They check if the various services or modules within your system can talk to each other correctly. They're faster and more stable than UI tests because they don't rely on the visual elements of the application. This is like checking if the pipes and wires behind the walls are properly connected and sending the right signals. You'll have fewer of these than unit tests, but more than UI tests. 
  • Integration Tests. Next up are Integration tests. These focus on how different modules, services, or how systems interact with each other. This is about verifying the interfaces and data flow between separate parts. Essentially, they connect layers and test real flows. For example, testing how your application interacts with an external database, a third-party service, or another microservice. They're slower than API tests, but still faster than UI tests, and they help uncover bugs that only appear when components are combined. 
  • UI Tests. This is the top of the pyramid. UI (User Interface) tests, sometimes known as end-to-end tests, simulate a real user interacting with the application through its GUI (graphical user interface). They run through user workflows, from start to finish. While essential for verifying the full user experience, they are the slowest, most brittle, as they can break with small UI changes, and the most expensive to maintain. You want a small, focused set of these to confirm critical user journeys work as expected. This is about making sure the user can do the essential things with the product. 

To sum up, build your testing from the ground up. Get the vast majority of your test coverage at the fast, stable, and cheap-to-fix lower levels. Use the other levels appropriately for your context, and make sure you don't have an imbalance or an anti-pattern, sometimes called an 'inverted pyramid'. That's basically an upside-down version where you have a lot of costly UI tests and few unit tests.
The “Test Pyramid” is a metaphor, defined by Mike Cohn in his book Succeeding with Agile, that tells us to group software tests into buckets of different granularity. It also gives an idea of how many tests we should have in each of these groups.

Stick to the pyramid shape to come up with a healthy, fast and maintainable test suite: Write lots of small and fast unit tests. Write some more coarse-grained tests and very few high-level tests that test your application from end to end.

Don't become too attached to the names of the individual layers in Cohn's test pyramid. Given the shortcomings of the original names it's totally okay to come up with other names for your test layers, as long as you keep it consistent within your codebase and your team's discussions.
Explore MoT
From test cases to AI-ready quality data: why structure matters image
Learn how to structure and organize test management data as an AI-ready foundation that gives AI systems richer context for testing insights and workflows.
MoT Software Testing Essentials Certificate image
Boost your career in software testing with the MoT Software Testing Essentials Certificate. Learn essential skills, from basic testing techniques to advanced risk analysis, crafted by industry experts.
Into The Motaverse image
Into the MoTaverse is a podcast by Ministry of Testing, hosted by Rosie Sherry, exploring the people, insights, and systems shaping quality in modern software teams.
Subscribe to our newsletter