Unit testing is a best practice in any modern methodology, including Agile development. With automatic unit testing in place, if we introduce a bug into the software, one or more tests will fail and we’ll know about it immediately. This piece will focus on explaining the specific importance of unit testing when it comes to developments in C++.
We’ve been writing in C++ for almost 30 years now, and we use software development tools, which improved over time. Yet, because of the intricacies of C++ and its different variants, testing tools did not become as advanced as Microsoft’s Visual Studio .NET tools or Eclipse for Java. For example, the testing tooling for C++ in Visual Studio lags behind the tools for the other languages supported in Visual Studio.
Without good software testing and development tools, it is hard to write quality code, and become more productive. More bugs enter the code, which makes us go slower and may introduce instability into the system. Where the tools are weak, we need unit tests even more.
But tooling is just one part of the problem. Some companies have code bases that can be almost 30-years old, which are not ‘testable’. They mostly work, but what happens when we discover a bug there? Fixing the bug without tests in place may be riskier than leaving it! On the other hand, nobody in their right mind would change the 30-year-old legacy code that works, just to make it fit for testing. That would be just as risky.
Because of these problems, unit testing adoption in C++ is slower than in other languages. Which is paradoxical: The importance of unit testing in C++ is evidenced by the many mission-critical systems (automobile, medical devices, etc.) that are written in C or C++. There is regulation in place for systems like this, for that reason. Yet we don’t do enough to ensure bugs don’t get in.
But all is not lost. There are tools for unit testing in C++. They may be not as easy to use, but this is a small price to pay, in order to make sure the products are top quality. This may even save lives.
To learn more, download Isolator++ for Windows or Linux.