Unit Tests in Ancient C++

9 PM November 16, 2003

Since I’m off to work with C++ for a few months, I went and investigated CppUnit. CppUnit started life as a port of JUnit, but has gone on to develop some neat, C++-style features, such as the test registry.

Unfortunately, CppUnit requires a fairly modern C++ compiler. Since my client is using HP-UX 10.20, CppUnit won’t be an option.

Partly to address this need for a unit test framework, and partly as an exercise in getting my head around C++ again, I wrote my own, minature unit test framework. The source code is online, the most important file being unittest.h. The generated documentation is also online.

A quick To Do list:

  • Currently have just one CHECK macro, that checks an assertion is true. Should also make a CHECK_EQUAL, and possibly allow custom error messages.
  • Get the category mechanism working so that subsets of the unit tests may be run.
  • Factor out the test result display code from the UnitTestRegistry::run() method.
  • Display failing line numbers and file names.
  • Package appropriately for use in a larger project.

Being my first C++ code for quite some time, comments, suggestions and critique are very welcome.

By alang | # | Comments (0)
(Posted to Software Development and javablogs)
© 2003-2006 Alan Green