Tuesday, July 3, 2012

CppUnit configuration in VS 2008

I hope this post would be helpful those who are going to use C++ unit testing frame work. Even though  so many unit testing frame works are available out there, As far as I know CppUnit is better among them because of following functionality.

  • XML output with hooks for additional data (XSL format avaliable in release 1.10.2 needs some FiXing)
  • Compiler-like text output to integrate with an IDE
  • Helper macros for easier test suite declaration
  • Hierarchical test fixture support
  • Test registry to reduce recompilation need
  • Test plug-in for faster compile/test cycle (self testable dynamic library)
  • Protector to encapsulate test execution (allow capture of exception not derived from std::exception)

Configuration steps 


1) Download latest CppUnit framework from this website 
http://sourceforge.net/projects/cppunit/files/cppunit/1.12.1/


2) Create any folder (ex: CPPUNIT) at any directory and copy your downloaded 


3) If you are using Visual Studio 2005 or 2008, it wont compile out of the box.
Fix For Visual studio 2005 and 2008
Open file MsDevCallerListCtrl.cpp in the folder srcmsvc6testrunner.
Find the following line
#import "libid:80cc9f66-e7d8-4ddd-85b6-d9e6cd0e93e2" version("7.0") lcid("0")
 raw_interfaces_only named_guids
and change the version("7.0") to:
version("8.0") for VS 2005
version("9.0") for VS 2008
Now do a batch build for all configurations.
Dont worry about errors yet.
Go and look into the lib directory in the cppunit directory.
if you have cppunit.lib, cppunit_dll.lib and cppunit_dll.dll, then you are ready to go.
Adding the include and lib paths to Visual Studio environment

open Tools->Options.
Choose Projects and Solutions -> VC++ Directories
from the dropdown for "Show directories for" choose "Include Files"
and add(by clicking in the blank space on the bottom) -> <cppunit directory>include
for "Library files"
Add-> <cppunit directory>lib 


Now you have finished your configuration part . Follow CppUnit example program to run your test cases .:) 

No comments:

Post a Comment