Having a good strategy for test automation can make it easier to implement test automation and reduce test maintenance costs. The test automation pyramid and automation test wheel can be of help when formulating a test automation strategy and plan. Test automation code should be clean code, and treated similarly to production code.
Christian Baumann spoke about test automation at Agile Testing Days 2022.
One of the challenges in automated testing is that too many people still see test automation as the holy grail, as the silver bullet that will solve all their quality and testing issues, Baumann said. In fact, it can be a great tool to support your testing, to create a safety net for your product, but it is a lot of effort to implement test automation properly, and it also comes with some maintenance cost, he added.
A test strategy and plan for test automation helps to achieve the mission for testing and describes how that mission can be accomplished; it provides guidance throughout the project, especially when things are unclear, and as a consequence, reduces the chance for failure, Baumann explained:
A strategy and plan defines what is in scope for the automation, and - of equal importance - what is not. It should define what to test, when to test, and how to test. Furthermore, it should clarify who does the automation and what shall be automated. And - crucial for automation - what tools, framework and programming language to use, and on what level to automate.
The strategy and plan for automation should be aligned with the overall test strategy and plan; eg. the tests that in the future will be executed by automation don’t need to be considered anymore for non-automated testing, Baumann said.
According to Baumann, test automation code should be valued and treated as the production code of the applications. He suggested using rules and principles from clean code also for test automation code:
Clean code can be read, understood and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.
InfoQ interviewed Christian Baumann about test automation and clean test code.
InfoQ: How can we apply the test automation pyramid and automation test wheel to automate testing?
Christian Baumann: I would like to quote Michael Bolton, who says "Good models are a set of guidelines that help us solve a problem." These models can be of great help when formulating a test automation strategy and plan.
The pyramid for example gives an idea of how much test automation effort to put in each level of the application:
- At the bottom, there should be a lot of unit tests. They are relatively cheap, in terms of efforts to create, but also in terms of execution time and maintenance effort.
- On the top, there should be very few tests on the GUI level, because they are expensive. It takes a lot of time and effort to create them, they are slow in execution, and also debugging and changing them is a lot of effort.
This is represented by the form of the pyramid: a wide base or foundation, but only a small top.
InfoQ: What can be done to create clean test code?
Baumann: The idea of clean code comes with a set of certain rules and principles to follow and apply when writing code. Most of them are relatively easy to understand and follow, for example the "KISS - Keep it simple stupid" idea: it originates from the US Navy and goes back to the 1960 already. It states that most systems should be kept as simple as possible; unnecessary complexity should be avoided, simply because less complex systems are less prone to errors. This principle can and should also be applied to code.