How to build CppUnit with Eclipse
These instructions describe how to build CppUnit with Eclipse 3.1.1, CDT 3.0.1 under Windows XP using MinGW. AdamKiezun reports success with Eclipse 3.2.2 and CDT 3.1.2.20070215062.
The steps to build it with WinXP/Cygwin or under Linux should be very similar, although I haven't tested it. (See CppUnitOnLinux)
Download the CppUnit distribution file CppUnit-1.10.2.tar.gz and unpack it in a directory of your choice. From now on we will refer to this directory as $CppUnit .
Run MSys to open a command line shell, then cd to the directory where you extracted CppUnit and do:
./configure
There's no need to go any further than this with make, make install, etc. All we will need is the header $CppUnit/include/CppUnit/config-auto.h which has been generated in the step above.
- Go to Eclipse and create a Managed Make C++ Project to generate a library (either static or shared).
Import all .h and .cpp files in $CppUnit/src/CppUnit to the project.
Open the project properties configuration dialog (Alt + Enter) and add $CppUnit/include to the include path.
- If you're building a shared library you'll also need to define the variable CPPUNIT_DLL_BUILD.
- Finally, build the project (Ctrl + B).
- Now let's create a sample project to test our library.
Create a new Managed Make C++ Project to generate an executable and import the contents of this file into it: sample_text.zip. In the project properties configuration dialog:
Add $CppUnit/include to the include path.
Add the CppUnit library to the project (see screenshot below).
If you've built CppUnit as a shared library you'll also need to define the variable CPPUNIT_DLL.
Note that in my system the generated library is at "C:\home_Alex\projetos_eclipse\CppUnit2\Release\CppUnit.dll".
By running the executable you'll find out that all tests will pass. You may now play around and introduce errors in the Complex class methods to see CppUnit's diagnostic error messages when a test fails.
(optional) The compiler issues several warning messages of ignored pragmas in the CppUnit source. You may edit the source headers and comment those lines if you don't want to be bothered by these warnings in your projects.
Configure a GUI test runner
Now that you've sucessfully set up CppUnit to run from the console, you may wish to build a GUI test runner. Follow these step by step instructions for building QtTestRunnerWithEclipse.
Parsing Errors with Eclipse
As of writing this (05 Feb 2007), there's no way to get Eclipse CDT to parse the output of CppUnit and display the failures in the "Problems" view. CppUnit supports a variety of outputs that Eclipse CDT can parse, but the parser is simply not applied to the output of a post-build process.