CppUnit is a unit test framework for C programming. It's the Java tool JUnit modeled.

CppUnit testing program units (most classes). To create a new test, a new class is created, which is extended with CppUnit macros. The methods of the class to be registered as a test. Within the methods of other classes can be tested now methods. This one tests usually whether a particular input produces a correct output. The results of the tests can be machine-readable displays XML as text output or with the provided GUI -based programs.


CppUnit has the following properties:

  • XML output with elements for additional information
  • Compiler -like text output to integrate with IDEs
  • Macros for the easy creation of test suites
  • Support for hierarchical tests ( tests that are composed of simpler tests)
  • Test registration for faster code generation
  • Test Plug -in for faster compile / test cycle (self testable dynamic library )
  • Protective mechanism to encapsulate test execution, allows the interception of exceptions that are not of the standard exception ( std :: exception ) are derived.
  • MfcTestRunner, one on the Microsoft Foundation Classes ( MFC) based test runner
  • QtTestRunner, one based on Qt 4 graphical test runner
  • Curse Test Runner, a curses -based test runner
  • WxWidgetsTestRunner, a wxWidgets -based test runner


This example shows a unit test. The calculator class is the object to be tested, KalkulatorTest the unit test. ( For the execution of the test program the starting point has to be modified. )

Class calculator

... class calculator {   public:    / / Calculate the root of k    squareRoot double (double k) {return sqrt (k); } }; class KalkulatorTest

# include   KalkulatorTest class: public CPPUNIT_NS :: TestFixture {   CPPUNIT_TEST_SUITE ( KalkulatorTest );   CPPUNIT_TEST ( testSqrt );   CPPUNIT_TEST_SUITE_END ();     public:    testSqrt void (); };   CPPUNIT_TEST_SUITE_REGISTRATION ( KalkulatorTest );   void KalkulatorTest :: testSqrt () {   Calculator lime;   CPPUNIT_ASSERT ( kalk.squareRoot (9 ) == 3); } Web Links

  • CppUnit homepage ( English)
  • CppUnit tutorial - Unit testing with C

Single Documents

  • Programming tool
  • Test Software