The agile testing pyramid helps testers understand how to implement automated testing. This valuable guide was originated by agile expert, Mike Cohn.
The pyramid provides a starting place for new QA testers to jump off from, and it gives a 'single source of truth' for established QA testers to refer back to. In doing so, it meets a range of needs. This is what we're talking about:
First off, yes, there are many other ways of visualizing this process. A diagram that illustrates something this complex or abstract is never going to tell the whole story.
Over the years the number of tiers, arrows, asterisks and thought bubbles added to this diagram could make your head spin. We're keeping the visual simple, and will unpack some of the nuance here.
'It costs almost five times more to fix a coding defect once the system is released that it does to fix it in unit testing.'
— Paul Grossman, IT consultant, in 'Automated testing ROI: fact or fiction?'
The two categories at the bottom of the pyramid - unit and component testing - represent those types of testing that benefit most from automation.
As your testing process matures, you may start to recognize opportunities for:
These benefits are much more evident at the base of the pyramid, so if you're considering automating your testing, that's where to start. Why? Well...
Unit testing focuses on individual pieces of code—the smaller the better. This enables you to get a detailed view of the code’s quality and performance. And because these units require limited functionality to run, you get feedback fast. As such, it makes sense to automate these tests. Furthermore, automated unit testing makes it easier to pinpoint where the problems are, so you can more quickly remediate them.
Component testing comes after the unit testing and tests objects independently, such as modules, classes, and programs. These tests are more thorough than unit testing and often need access to a database or other components, so are slower than unit tests. That said, because you can define inputs and expected outputs, you can easily create automated tests without involving the user interface (UI).
Automating unit and component tests makes the testing process faster, more predictable, and repeatable. But then comes integration testing. And that’s where the question of automation becomes a little more complicated.
Integration testing combines the individual software modules and tests them together as a group. It verifies whether or not the modules and services that make up your software work well together while exposing any defects in how they interact. This is especially important when different developers have worked on different components.
How much ground an integration test covers will impact how long the test takes. And the longer the test, the more disruptive it will be to your shorter running tests, such as unit and component tests. There are a number of ways around this:
The bottom line is that you must consider your process, environment, and testing needs carefully, and create a strategy that gives you the best in development efficiency, test coverage, and resource utilization. In the end, properly planned and executed integration automation will supercharge your testing efforts and deliver repeatable results with less instance of human error.
And, there’s no definitive answer to exactly when you should stop automating your tests. But as you move up the hierarchy, the return on investment is less (and naturally reaches a zero point at the moment you hit manual and exploratory tests, which are non-automated). The earlier and more often in the process you test, the better and more cost-effective the outcome.
As you move higher up the agile testing pyramid, you encounter issues like:
For example, UI tests break easily, often because the UI structure changes over time. Low-level tests are faster and more stable, so this is where we recommend you put the vast majority of your effort. Then, write very few higher-level tests, like end-to-end tests. Use tools like Selenium to avoid the testing ice-cream cone.
At the start of your journey, the agile testing pyramid can look pretty unscalable. But, if you break it down, that summit is closer than you might think. For more information about testing types, see our article on software testing basics.