For several years I’ve been searching the best testing framework for C++ software, and now I reached a decision.
Actually, there are (at least) three kinds of automatic testing for C++ software:
- Static (unit) testing: It is to state which statements are legal and which are not legal, and let the compiler check that they are actually as stated.
- Dynamic unit testing: It is to state which is the expected result of some operations, compile and run the program, and let the testing framework check the operations return the expected values.
- (Dynamic) System testing. It is to run the actual hardware/software system, or an emulation of it, run a testing program that submit to the system under test the input that would be provided by the user, another application, or hardware devices, and check that the system under test behaves as expected. Sometimes it requires that the system under test has a backdoor to receive test input, and, as the check of the behavior of the system is manual, it is only a semi-automatic testing technique.
System testing is not C++-specific, and therefore I think there shouldn’t be C++-only system testing tools. In addition, it is rather application-kind-specific, meaning that system testing of a microcontroller system is quite different from system testing of a videogame, and both are quite different from system testing of an e-commerce website; therefore I think there shouldn’t be completely generic system testing tools.
On the contrary, static testing is something that make sense almost only for metaprogramming, i.e. generic source code that, according to directives by other, application-oriented code, generates more specific source code, that may then be compiled in an optimized way into machine code.
I still haven’t found a static testing tool superior to my own tool published on Dr. Dobb’s Journal.
When someone speaks about a “unit testing framework or tool” invariably means a dynamic unit testing framework or tool. There are really many of them, for many programming languages. The most famous ones are those of the xUnit family, derived from the SUnit framework designed and implemented for the Smalltalk language.
But for C++, there are even several unit testing frameworks that claim to be belong to the xUnit family.
After a feature comparison, and after having read some comments and opinions over the Web, I decided that my framework of choice is Google C++ testing Framework.
Its main defect is that it has a company name in its name and in the name of the initialization function. But, as it is open source, they can be removed.
Its main advantages are that:
- It is open source.
- It is multiplatform.
- It is available also for Microsoft tools and operating systems.
- It doesn’t require to enumerate the tests.
- It is quite fast to start.
- Its macros allow a really terse coding, but still auto-documenting.
- No need to duplicate information.