= Frequently Asked Questions about CppUnit =

Feel free to add questions or answer ones that already exist

== Concepts ==

=== What are Plugins for ===
(answer needed)

== How do I? ==

=== How do I integrate CppUnit with CruiseControl? ===
(answer needed)

=== How do I run a subset of tests ===
(answer needed)

=== How would I use CppUnit for automated testing ===
(answer needed)

=== How do I print debug info ===
like what test is it that makes an segmentation fault?
(answer needed)

=== How do I stop abort() being called when a test fails? ===
Enable exceptions.  In GCC, compile with -fexceptions.  In VC++, use /EHsc (Enable C++ exceptions under Code Generation).

=== How do I get the name of the test from within the setUp function? ===
Neither the setUp() nor tearDown() functions know the name of the test being called, so you can't customize these for different tests.  If you need to setup the environment for a single test, include that setup with the test.  If several tests share the environment, then consider private data and functions, with each test calling the shared setup function.  If all but a few need the same environment, then consider putting it in setUp() and tearDown(), and adding extra code to the non-cooperative tests.  

=== How can I create test hierarchy (suite of tests that contains other suites)? ===
Use the CPPUNIT_TEST_SUB_SUITE() macro.  For instance:
{{{#!cplusplus
 #include <cppunit/extensions/HelperMacros.h>

 class MyTest {
   CPPUNIT_TEST_SUITE( MyTest );
   CPPUNIT_TEST( testBasic );
   CPPUNIT_TEST_SUITE_END();
 public:
   void testBasic();
 };

 class MySubTest : public MyTest {
   CPPUNIT_TEST_SUB_SUITE( MySubTest, MyTest );
   CPPUNIT_TEST( testAdd );
   CPPUNIT_TEST( testSub );
   CPPUNIT_TEST_SUITE_END();
 public:
   void testAdd();
   void testSub();
 };
}}}
My``Test will run testBasic, while My``Sub``Test will run testAdd, testSub, and testBasic.  See the [http://cppunit.sourceforge.net/doc/lastest/group___writing_test_fixture.html Writing Test Fixture] section of the documentation.  If you are testing a class heirarchy with abstract classes, CPPUNIT_TEST_SUITE_END_ABSTRACT() may also be useful, to create a test fixture that exercises pure virtual functions.


=== Is there a program, like JUnitDoclet, that will generate test skeletons automatically? ===
Probably not.  J``Unit``Doclet probably uses reflection, the ability of Java code to report information about itself.  For instance, you can query a Java class for all the public functions, then write a test framework with a test for each function.  

We don't have anything like reflection in C or C++, so writing a test skeleton generator would be a similar effort to writing a C/C++ compiler.  This is difficult, but not impossible, and there probably commercial tools that generate test skeletons for their own programs.  But none for CppUnit, that we know of.

----
