The test automation pyramid is a testing strategy introduced by Mike Cohn in his book Succeeding with Agile. The pyramid is a metaphor for thinking about testing in software, more specific about test automation. The pyramid consists of three layers:

Unit test layer

This layer represents the base of the pyramid and should have the highest number of automated tests. Unit tests are automated tests that verify the functionality of a single unit of code in isolation, such as a method or a class. They are usually fast, cheap to create, and easy to maintain. Examples of unit testing frameworks are JUnit for Java, NUnit for .NET, and pytest for Python.

Integration or API layer

The Integration or API layer sits in the middle of the pyramid and represents the medium number of automated tests. Service tests are automated tests that verify the functionality of a group of related units of code working together, such as a web service or an API. They are usually slower than unit tests and require more infrastructure setup, but they provide more coverage and catch integration issues.

End to End or GUI Layer

The GUI layer sits at the top of the pyramid and should have the lowest number of automated tests. UI tests are automated tests that verify the functionality of the user interface, such as clicking buttons, filling forms, and checking displayed data. They are usually slower, more brittle, and more expensive to maintain than unit and service tests, but they provide the most realistic user scenario testing. Examples of UI testing frameworks are Selenium WebDriver for web applications and Appium for mobile applications.

Goal of the pyramid

The goal of the test automation pyramid is to help with the creation of a testing strategy for software development teams. When you use it, it balances the different types of automated tests to have some benefits.

  • Improved testing efficiency: By focusing on writing more unit tests, which are faster and cheaper to run, teams can catch most bugs early in the development process, reducing the need for more expensive and time-consuming tests later on.
  • Increased testing coverage: By adding service tests and UI tests to the mix, teams can increase the scope of their testing and catch integration issues between different parts of the system.
  • Reduced maintenance costs: By focusing on tests that are easier to write and maintain, such as unit tests, teams can reduce the overall cost of maintaining their test suite over time.
  • Improved quality: By using the test automation pyramid to guide their testing efforts, teams can catch more bugs early in the development process, reducing the likelihood of bugs making it to production.

Who creates the tests?

Tests from the test automation pyramid can be created by different members of the software development team, depending on the type of test and the level of expertise required.

  • Unit tests: Developers are typically responsible for writing unit tests. These tests are focused on testing small pieces of code in isolation, and they require knowledge of the programming language and the codebase.
  • Service tests: Both developers and testers can create service tests. Service tests verify the integration and functionality of multiple services or APIs, and they require knowledge of the system architecture and the technologies used to build the services.
  • UI tests: Testers are typically responsible for writing UI tests. These tests verify the behavior of the application’s user interface and require knowledge of UI automation frameworks and tools.

It’s important to note that creating tests is a collaborative effort like I explained in Whole Team Approach. Team members should work together to create a comprehensive and effective test suite. Developers can work with testers to ensure that their code is testable and that the unit tests cover all relevant scenarios. Testers can provide feedback to developers on the behavior of the application, which can inform the creation of service and UI tests. By working together, the team can create a test automation strategy that maximizes testing efficiency and effectiveness.