20
20
Currently there are no native C++ bindings for subunit. However the C library
21
can be used from C++ safely. There is also a patch for cppunit
22
(http://cppunit.sourceforge.net/) to enable reporting via subunit
23
(cppunit-subunit-1.10.2.patch).
25
To use the patch, apply it and rebuild your cppunit. Then in your main do
27
// Create the event manager and test controller
28
CPPUNIT_NS::TestResult controller;
30
// Add a listener that collects test result
31
// so we can get the overall status.
32
// note this isn't needed for subunit...
33
CPPUNIT_NS::TestResultCollector result;
34
controller.addListener( &result );
36
// Add a listener that print test activity in subunit format.
37
CPPUNIT_NS::SubunitTestProgressListener progress;
38
controller.addListener( &progress );
40
// Add the top suite to the test runner
41
CPPUNIT_NS::TestRunner runner;
42
runner.addTest( CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest() );
43
runner.run( controller );
45
return result.wasSuccessful() ? 0 : 1;
49
See the c/README for documentation on the C bindings for subunit.
21
can be used from C++ safely. A CPPUnit listener is built as part of Subunit to
22
allow CPPUnit users to simply get Subunit output.
24
To use the listener, use pkg-config (or your preferred replacement) to get the
25
cflags and link settings from libcppunit_subunit.pc.
27
In your test driver main, use SubunitTestProgressListener, as shown in this
31
// Create the event manager and test controller
32
CPPUNIT_NS::TestResult controller;
34
// Add a listener that collects test result
35
// so we can get the overall status.
36
// note this isn't needed for subunit...
37
CPPUNIT_NS::TestResultCollector result;
38
controller.addListener( &result );
40
// Add a listener that print test activity in subunit format.
41
CPPUNIT_NS::SubunitTestProgressListener progress;
42
controller.addListener( &progress );
44
// Add the top suite to the test runner
45
CPPUNIT_NS::TestRunner runner;
46
runner.addTest( CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest() );
47
runner.run( controller );
49
return result.wasSuccessful() ? 0 : 1;