How to show testmethod names using cppunit
Asked Answered
S

2

5

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
Seppala answered 2/12, 2011 at 23:25 Comment(0)
A
1

You'll want to utilize CppUnit::XmlOutputter. I'm not certain on the exact syntax to hook this up.

Anaglyph answered 3/12, 2011 at 3:41 Comment(4)
how is that supposed to work? A piece of code how to pass this command line argument would be great.Seppala
It is a command line parameter... so when you are in your shell, you add it to the command line. ./test_binary_to_run --xmlAnaglyph
well, there is no form of passing on command line arguments inside my code, so this parameter will never reach the tool, and the homepage doesn't provide help there. Could you please write a small main, for visualization.Seppala
My apologies... the test executables we use at work process the command line parameter I mentioned, and call the appropriate code within CppUnit. I'll amend the answer as soon as I get a chance.Anaglyph
N
6

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 );
Nichols answered 5/11, 2012 at 22:7 Comment(0)
A
1

You'll want to utilize CppUnit::XmlOutputter. I'm not certain on the exact syntax to hook this up.

Anaglyph answered 3/12, 2011 at 3:41 Comment(4)
how is that supposed to work? A piece of code how to pass this command line argument would be great.Seppala
It is a command line parameter... so when you are in your shell, you add it to the command line. ./test_binary_to_run --xmlAnaglyph
well, there is no form of passing on command line arguments inside my code, so this parameter will never reach the tool, and the homepage doesn't provide help there. Could you please write a small main, for visualization.Seppala
My apologies... the test executables we use at work process the command line parameter I mentioned, and call the appropriate code within CppUnit. I'll amend the answer as soon as I get a chance.Anaglyph

© 2022 - 2024 — McMap. All rights reserved.