Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

C++ Unit Testing Framework


This is a C++ testing framework. It seems to be mostly functional. The goal was ease of use and hard to use incorrectly. The library is based on code presented by Chuck Allison in the C++ User's Journal, The Simplest Automated Unit Test Framework That Could Possibly Work.

The design is the system follows a Component/Composite pattern, where a UnitTest is the component, and the TestSuite is the composite (of UnitTests).

In brief, to instrument code create a class derived from UnitTest. Override void run_tests() with calls to _test(condition). Next, instantiate an instance of the derived class. UnitTest may be run directly or added to a TestSuite (all tests must be added from the heap or the program will segfault on exit).

At this point calling run() will execute the test and calling report(ostream) will print the results. Calling report(ostream) will also run the tests if they have not already been run. Using an output operator with a TestComponent will invoke report(ostream) (which will in turn invoke run()).

Invoking run() will produce no output until report is called.

Using libccunit

libccunit is meant to be used within (x)emacs. The failure reports follow the format:

file:line: error

Thus, running a test program within emacs will allow you to skip to any failed tests as if the failures were compile errors.

To see an examle of how to implement some simple tests see For a more comprehensive exmple take a look at shows how to setup a collection of nested tests.

And for those who are truly lazy, there is now an AutoTest facility (dedicated to J.S.). To use the auto test functionality, include the AutoTest.hh header file, and add the following code to your test implementation files:

namespace {
  registerTest<MyTest> myTest;

Take a look at AutoTestTest.hh,, and for an example.

Dale K. Hawkins <>

Release notes


Improve documentation

Better integration with doxygen

Generated on Tue Apr 2 15:33:22 2002 for libccunit by doxygen 1.2.14 written by Dimitri van Heesch, © 1997-2002

Project hosted on sourceforge SourceForge Logo