The second to last category of technical debt in my series on technical debt categories is Test Automation Debt. Let’s go!
What Is Test Automation Debt?
The paper Towards an Ontology of Terms on Technical Debt on which I’m basing my series defines test automation debt as:
the work involved in automating tests of previously developed functionality to support continuous integration and faster development cycles.
That is a fairly clear definition. As we develop code, we either write automated tests or don’t. People who know me, know I’m a big fan of automated tests and even test-driven development. In fact, I (and not only me) think it’s the best technique to avoid and reduce technical debt, complicated code, hard to maintain code and bugs.
If we choose not to write automated tests, we increase the likelihood of introducing other types of technical debt, like architecture debt, code debt, defect debt, design debt and even documentation debt (as tests can be regarded as documentation too).
But if we do write automated tests, they can contain technical debt too. For example, the tooling may be outdated, the test code may be in a bad state, documentation about the tests may be lacking, or the tests may be flaky (i.e. they sometimes succeed and sometimes fail, without having modified anything).
Another example is tests that are too closely tied to the implementation. If the implementation changes but not the behavior, ideally we don’t have to modify the test. If we do, this increases the amount of work required for refactoring and often causes teams to either not refactor or just remove the tests.
Causes Of Test Automation Debt
Test automation debt often stems from a lack of knowledge and expertise about automated testing. Any developer by now knows about unit tests. But I still encounter too many of them that aren’t skilled enough in the matter to make it part of their daily routine.
So they either don’t write tests (leading to test debt which we’ll cover in the next post) or they write bad tests.
And just like production code, test code must be maintained. Modifications to the production code will inevitably lead to modifications in test code. Over time, tests can become complex, flaky or slow.
Solving Test Automation Debt
To solve the problem of test automation debt, the team must regard their test code as any other code. It must adhere to code standards and best practices.
Yet there may be some subtle differences. For example, in production code, we tend to not want to duplicate code and so we invest in code reuse. In tests, I personally want a test to be readable on first sight and be isolated from other tests. Which sometimes means duplicating pieces of code.
Whatever your approach, we must write maintainable and stable tests. If tests have diverged from this ideal, we need to take some time to fix that (i.e. pay back the debt). If tests are flaky, the team must solve the underlying problem.
The Business Case For Reducing Test Automation Debt
Bad tests can lead to frustration. If teams can’t modify their tests easily, they will start to lose faith in the idea of automated testing. This also happens when teams can’t trust their tests (i.e. if they have flaky tests).
As teams start to lose trust in their tests, they either stop writing them or start removing them. This increases the chances of introducing bugs and technical debt.
Any software system of even modest size is difficult to test completely manually. Automated tests allow us to run a whole suite of tests that would take hours to do manually. It won’t find every bug in our code, but the benefits still remain huge:
- we win many hours back by not having to test things manually
- we can keep testing pieces of the software that aren’t in scope of our current task
- tests can serve as a piece of documentation on what is expected of a software module
- tests, when done right, push us toward a better architecture and design
This all leads to software and code with a higher internal quality and allows teams to work at a sustainable pace instead of grinding to a slow halt over the years.