Comparing CppTest and CppUnit I would go with CppTest. CppTest has less hidden framework and IMO easier to understand and implement. I personally like to see the main entry point. I have also included Boost Unit Testing Framework. It is not xUnit based. I am not a fan, but if you are already using the Boost Library it would be nice to incorporate.
CppTest vs CppUnit
•Ease of creating a unit test and test
suite. Both CppUnit and CppTest create
unit tests of class methods, with the
class itself derived from some
tool-provided Test class. The syntax
for CppTest is slightly simpler,
though, with the test registration
happening inside the class
constructor. In the case of CppUnit,
the additional macros
CPPUNIT_TEST_SUITE and
CPPUNIT_TEST_SUITE_ENDS are needed.
•Running the tests. CppTest simply
calls the run method on the test
suite, while CppUnit uses a separate
TestRunner class whose run method is
invoked for running the tests.
•Extending the testing hierarchy. In
the case of CppTest, it is always
possible to extend the previous test
suite by creating a new class that
inherits from the old one. The new
class will define some additional
functions that add to the unit test
pool. You simply invoke the run method
on the object of the new class type.
CppUnit, in contrast, requires that
you use the macro
CPPUNIT_TEST_SUB_SUITE along with
class inheritance to achieve the same
effect.
•Generating formatted output. Both
CppTest and CppUnit have the ability
to customize the output. However,
although CppTest has a useful,
predefined HTML output formatter,
CppUnit does not. However, CppUnit
exclusively supports XML formatting.
Both support text and compiler style
formats.
•Creating test fixtures. To use test
fixtures, CppUnit requires that the
test class be derived from
CppUnit::TestFixture. You must provide
definitions for the setup and
tear-down routines. In the case of
CppTest, you need to provide
definitions only for the setup and
tear-down routines. This is definitely
a better solution, as it keeps the
client code simple. •Predefined
utility macro support. Both CppTest
and CppUnit have a comparable set of
macros for asserts, handling floats,
and so on.
•Header files. CppTest requires that
you include a single header file,
while CppUnit client code must include
multiple headers, like HelperMacros.h
and TextTestRunner.h, depending on the
features used.
http://www.ibm.com/developerworks/aix/library/au-ctools3_ccptest/index.html?ca=drs-
CPPTEST
#include “cppTest.h”
class myTestWithFixtures : public Test::Suite {
void function1_to_test_some_code( );
void function2_to_test_some_code( );
public:
myTestWithFixtures ( ) {
TEST_ADD (function1_to_test_some_code) {...};
TEST_ADD (function2_to_test_some_code) {...};
}
protected:
virtual void setup( ) { ... };
virtual void tear_down( ) { ... };
};
int main ( )
{
myTestWithFixtures tests;
Test::TextOutput output(Test::TextOutput::Verbose);
return tests.run(output);
}
http://www.ibm.com/developerworks/aix/library/au-ctools3_ccptest/index.html?ca=drs-
CPPUNIT
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/ui/text/TextTestRunner.h>
#include <cppunit/extensions/HelperMacros.h>
class mystringTest : public CppUnit::TestFixture {
public:
void setUp() { ... };
void tearDown() { ... };
void function1_to_test_some_code() { ... };
void function2_to_test_some_code() { ... };
CPPUNIT_TEST_SUITE( mystringTest );
CPPUNIT_TEST( function1_to_test_some_code );
CPPUNIT_TEST( function2_to_test_some_code );
CPPUNIT_TEST_SUITE_END();
};
CPPUNIT_TEST_SUITE_REGISTRATION( mystringTest );
with out macros
int main ()
{
CppUnit::TestSuite* suite = new CppUnit::TestSuite("mystringTest");
suite->addTest(new CppUnit::TestCaller<mystringTest>("checkLength",
&mystringTest::checkLength));
suite->addTest(new CppUnit::TestCaller<mystringTest>("checkValue",
&mystringTest::checkLength));
// client code follows next
CppUnit::TextTestRunner runner;
runner.addTest(suite);
runner.run();
return 0;
}
http://www.ibm.com/developerworks/aix/library/au-ctools2_cppunit/
Boost Unit Testing Framework
#include <boost/test/unit_test.hpp>
using namespace std;
struct CMyFooTestFixture
{
CMyFooTestFixture() { ... } //SetUp
~CMyFooTestFixture() { ... } //TearDown
void function1_to_test_some_code(CMyFoo& foo) { ... };
void function2_to_test_some_code(CMyFoo& foo) { ... };
}
BOOST_FIXTURE_TEST_SUITE(MyFooTest, CMyFooTestFixture);
BOOST_AUTO_TEST_CASE(function1_to_test_some_code)
{
CMyFoo foo;
function1_to_test_some_code(foo);
}
BOOST_AUTO_TEST_CASE(function1_to_test_some_code2)
{
CMyFoo foo;
function1_to_test_some_code(foo);
}
BOOST_AUTO_TEST_SUITE_END();
http://www.beroux.com/english/articles/boost_unit_testing/