Help Center> CloudTest> Best Practices> Testing Pyramid and Continuous Automated Testing
Updated on 2022-09-29 GMT+08:00

Testing Pyramid and Continuous Automated Testing

In agile and DevOps development modes, products must be able to be released at any time. This document describes how to use the testing pyramid and continuous integration and continuous delivery (CI/CD) automated testing to implement efficient test feedback and ensure the quality of products released at any time.

Testing Pyramid

The test automation pyramid was first proposed by Mike Cohn in 2009 in his book Succeeding with Agile: Software Development Using Scrum. It was first proposed as a three-layer pyramid, which consists of the GUI tests, service tests, and unit tests from top to bottom. With the development of agile tests, there are some variants of the test automation pyramid. In practice, the service tests can also be regarded as API tests.

The triangle structure indicates that the recommended investment proportion for automation at each layer increases from top to bottom.

Martin Fowler has a comment on the testing pyramid, "Most importantly such tests are very brittle. An enhancement to the system can easily end up breaking lots of such tests, which then have to be re-recorded. You can reduce this problem by abandoning record-playback tools, but that makes the tests harder to write. Even with good practices on writing them, end-to-end tests are more prone to non-determinism problems, which can undermine trust in them. In short, tests that run end-to-end through the UI are: brittle, expensive to write, and time consuming to run. So the pyramid argues that you should do much more automated testing through unit tests than you should through traditional GUI based testing."

The test technologies involved in each layer of the testing pyramid have their own advantages and limitations. The upper-layer GUI tests are brittle (instability), time-consuming (execution efficiency), and the distance between the problem symptom location (UI) and the root cause location (code) is too long. The testing pyramid focuses on the test quality instead of quantity. It is recommended that the bottom-layer test investment be increased.

  • A higher layer leads to lower running efficiency, which slows down the build-feedback cycle of continuous integration.
  • A higher layer leads to higher development complexity, which slows down delivery progress when the team capabilities are limited.
  • End-to-end testing is more likely to bring uncertainty in test results.
  • A lower layer leads to stronger unit isolation, which makes it easier to locate and analyze problems.

In principle, the unit test needs to be undertaken by the developers. In many teams, the developers are insufficient, so they have to focus on function implementation first. In addition, due to a lack of investment and experience in the unit test, many teams do not perform the unit test or just do it reactively. Some have proposed the anti-patterns of the pyramid structure—the Ice-Cream Cone and the Cupcake.

The Ice-Cream Cone pattern, proposed by Alister Scott in 2012, inverts the ratio of GUI tests and unit tests in the testing pyramid to form an inverted pyramid. In addition, a large number of manual tests are added above GUI tests. Although anti-patterns are not recommended, they are indeed used frequently. At the early stages, most teams did not perform automated testing and completely relied on manual tests. Later, the teams started from function test automation and generated some GUI automated testing cases. This way of building automated testing from outside to inside leads to such an anti-pattern. This pattern has some problems in terms of test efficiency and test case maintainability. However, it is an inevitable path for many teams to build test automation capabilities. When problems are accumulated to a certain level, this pattern needs to gradually evolve to the testing pyramid.

Continuous Automated Testing

Continuous automated testing is to run automated testing during CI/CD and quickly report failures. It is first derived from the idea that developers obtain quick feedback through unit tests in the development environment. Continuous automated testing gradually matures with the development of CI/CD. Today, developers are required to update product and fix online problems more and more quickly. If manual tests are still used frequently or development and testing are completely separated, it is difficult to ensure that the test quality assurance activities are completed in a short time window. Therefore, automated testing needs to be embedded in the CI/CD process to ensure the quality of deliverables.

Continuous testing means that test activities are incorporated into the continuous integration, feedback, and improvement cycle. Continuous testing runs through the entire software delivery cycle. Continuous testing advocates early, frequent, and automated testing.

"Continuous" is reflected in the whole process of evolving deliverables from small granularity to finished software in the agile and DevOps processes, from white-box code tests to component module tests, API tests, E2E function tests, and even online tests in the production environment after delivery. Each stage maps the layers of the testing pyramid from bottom to top. The lower-layer tests are performed in the early stages, and the upper-layer tests are performed in the later stages. This is similar to each stage of the automobile manufacturing pipeline. After the assembly in each stage is complete, necessary checks are performed before the next stage starts. During software DevOps development, the pipeline carries the assembly, check, and test processes.

  • Shift-left testing and shift-right testing

    During continuous testing, test activities can go beyond the time, role, and department restrictions of traditional tests, and are developed into coherent and continuous quality assurance activities.

    Shift-left testing emphasizes that the test activities are carried out as early as possible. The testers participate in the activities in the early stages of a software project. The related test cases are defined before the function development to detect quality problems in advance. The developers participate in the tests.

    Shift-right testing emphasizes that test monitoring is performed in the production environment, and that user feedback is obtained in real time to continuously improve user satisfaction and product quality.

  • Test automation

    To achieve fast flow and quick feedback, continuous testing needs to be automated to improve efficiency. Therefore, automated unit tests, API tests, and E2E tests are embedded into the DevOps pipeline. Automated testing improves test feedback efficiency and reduces errors caused by human factors. Test automation not only automates the execution of test case scripts, but also implements all other activities that can reduce manpower input, such as automatic environment creation, deployment, monitoring, and data analysis.