Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show testmethod names using cppunit

Tags:

c++

cppunit

How do I change the output of cppunit from dots, indicating how many tests are done to the actual names of the tests, or maybe just at least the string which was given to the test-caller, as counting the dots and guessing which test-function it represents is quite unproductive, in case of an Segmentation Fault which actually kills the whole program. I did just find reference for changing the error-output in case of a failed assert, but nothing on the general output.

The suite function of my Testclass:

static CppUnit::Test *suite() {
                CppUnit::TestSuite *suiteOfTests = new CppUnit::TestSuite( "Map Parser" );
                //string to state
                suiteOfTests->addTest( new CppUnit::TestCaller<Parser_test>("string to state I",&Parser_test::test_string_to_state_I));
                ....
                return suiteOfTests;
}

Main.cpp

CppUnit::TextUi::TestRunner runner;
runner.addTest( Parser_test::suite() );
runner.run();

I would love to have some output like this:

string to state I : OK
string to state II : OK
...

as then I am able to determine when the program crashed due to a non-catchable exception, like a SegFault.

But at the moment my ouptut looks like this:

...........
Segmentation fault
like image 353
Sim Avatar asked Dec 02 '11 23:12

Sim


1 Answers

A BriefTestProgressListener does the job:

CppUnit::TestResult controller;

CppUnit::TestResultCollector result;
controller.addListener( &result );        

CppUnit::BriefTestProgressListener progressListener;
controller.addListener( &progressListener );

CppUnit::TestRunner runner;
runner.addTest( CppUnit::TestFactoryRegistry::getRegistry().makeTest() );   

runner.run( controller );
like image 57
BrendanB Avatar answered Oct 10 '22 07:10

BrendanB