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.
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 stacktest.cc. For a more comprehensive exmple take a look at SuiteTest.cc.
RunTests.cc 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, AutoTestTest.cc, and AutoTestMain.cc for an example.
Better integration with doxygen