Code quality is a topic of prime importance in any software development cycle. It influences not only code functionality but also its maintainability, scalability, and long-term viability. Unfortunately, while we hope it is done for production code, it is often overlooked for test code. As a QA Manager, it’s crucial to understand and advocate for the necessity of high-quality code in both production and testing. Before discussing test code quality, let’s differentiate between test scripts and test code; it’s a crucial consideration.
Test Scripts vs. Test Code: The Distinction
We typically create Test scripts in one of two ways: using record-and-playback tools, then converting the results into scripts; or writing scripts line by line, action by action, as independent tests with limited or no reusability. While scripts seem simple to create and may be quick to deploy, they typically lack flexibility and are brittle, making them susceptible to breaking when things change. This can lead to regression gaps with abandoned scripts and other undesirable results. Test scripts are most suitable for simple, static workflows.
Conversely, test code involves writing code for test automation, ranging from unit tests to API tests to end-to-end tests. This approach often utilizes SDETs (Software Development Engineers in Test) or developers who know object-oriented principles, page object models, and data-driven testing principles. Typically needing fewer resources, it offers superior flexibility, robustness, and efficiency, making it ideal for complex projects with longer lifecycles or systems integral to an organization.
Why Does Code Quality Matter?
Code quality is the cornerstone of any reliable, robust, and efficient software system. Poor code quality can lead to bugs, security vulnerabilities, performance issues, and even system failures. On the other hand, high-quality code addresses these concerns while being easier to read, maintain, and extend, reducing the time and resources needed for debugging and shortening release cycles. High-quality code is good.
While the importance of production code quality is evident, test code quality is often overlooked, if not wholly ignored. We know what can happen with poor production code. Similarly, poor test code can lead to reduced regression testing, missed requirements, or even false positives or negatives, which are notoriously difficult to find. Good test code quality helps resolve these issues in the same way good production code quality helps resolve problems.
Remember, testing is your primary defense against software bugs and defects.
What’s More Important, Production Code Quality Or Test Code Quality?
Let me preface this with my experience across many large enterprise organizations: Code quality is challenging at the best of times, even with organizations having the best intent. And as large projects start running into delays, code quality is often an early victim.
A woman in an orange/red shirt thinking about a puzzling questionBack to the question: both production and test code quality are critical, but test code quality is more important than production code quality. Why, you ask?
Let’s answer that with another question. Which is better: a system with the best code ever but does not work as expected or a poorly written, unmaintainable system that does everything expected?
We all agree that a system that works as expected is preferred, regardless of the quality of its code.
The nature of development means bugs; the issue is how quickly you identify and fix them. The better you test, the quicker you find bugs. And the quicker you find bugs, the faster you fix them. So good testing is critical, and the more maintainable and sustainable your tests are, the quicker they can adapt as your system changes, letting you identify bugs sooner.
Since testing ensures the quality of your production system, and production code quality does not guarantee functionality, test code quality is critical to the success of your test system and, ultimately, your production system, which needs to work, regardless of its code quality.
Summary
This article underscores the importance of code quality for both software development and testing. It further differentiates between automated test scripts and test code, accentuating the latter’s superiority. We also see that test code quality can compensate for deficiencies in production code quality while protecting against bugs, explaining how test code quality adds as much if not more, value than production code quality.
Are you ready to challenge your views and see test code quality in a new light?
Author
Kim Filiatrault Founder and President
Kim has been in the IT industry for over 35 years, most of it in highly technical areas including generative technologies and test automation. In 2005, Kim specialized in Insurtech and helped many enterprise customers implement large projects. More recently, his company released CenterTest, its new test automation technology, based on his decades of test automation and generative technologies expertise and they have started helping companies revolutionize the way they test.
When not working, Kim enjoys off-roading with his Jeep, going to the UT Longhorns Football games, serving his local communities, and traveling.
Kimputing are an Exhibitor Sponsor at AutomationSTAR 20-21 Nov. 2023 in Berlin