Software QA FYI - SQAFYI

Crash Course in using CppUnit


This document will introduce you to a testing framework called CppUnit. CppUnit is a C++ port of the JUnit testing framework developed by Erich Gamma and Kent Beck. It is ported by Michael Feathers. The main purpose of CppUnit is to support developers in doing their unit testing of C++ programs. For students using the C++ language for the project, we expect you to use CppUnit extensively for your testing purposes. Recall that one of the required program quality attributes for your project is reliability. CppUnit can be used to help you achieve that.

This document can be considered a "port" of the JUnit Guide I wrote. In particular, this document talks about using CppUnit in MS Visual C++ 6.0. As in the JUnit Guide, I have included only the bare minimum to get you started. I will first go through the installation of CppUnit in the next section, followed by a description of how to use CppUnit using a sample program. Next, I will suggest some ways of organizing your project and test codes before ending the document with pointers to some useful references.

Installing CppUnit
Installation of CppUnit can be broken down into the following steps:
Download CppUnit and unzip the archive into a location of your choice. For the rest of this document, I will assume that you have unzipped your archive to the directory C:\ and hence the source files are located in C:\CppUnit.

Test your installation to ensure that CppUnit is working:
Start the Visual C++ IDE. Select File->Open. Change the "Files of type" to "Workspaces". Go to C:\CppUnit\ms\culib directory and open the workspace culib.dsw.

Next, select Build->Rebuild All to create the culib.lib library.
Select File->Open again and go to C:\CppUnit\ms\TestRunner directory to open the workspace TestRunner.dsw. Similarly, select Build->Rebuild All to create TestRunner.dll.
Select File->Open and go to C:\CppUnit\ms\HostApp directory to open the workspace HostApp.dsw.
After this, select Build->Rebuild All to compile the application. Run the application by selecting Build->Execute HostApp.exe. The TestRunner gui will appear. Just click on the Run button to run the tests.

Full article...

Other Resource

... to read more articles, visit

Crash Course in using CppUnit