如何使用 cppunit 显示测试方法名称

发布于 2024-12-19 05:01:35 字数 929 浏览 2 评论 0原文

如何从点更改 cppunit 的输出,指示对测试的实际名称进行了多少次测试,或者至少是提供给测试调用者的字符串,如计算点并猜测哪个测试-它所代表的函数是非常低效的,如果出现分段错误,实际上会杀死整个程序。我确实只是找到了在断言失败的情况下更改错误输出的参考,但在一般输出上没有任何内容。

我的 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();

我希望有一些像这样的输出:

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

这样我就能够确定程序何时由于不可捕获的异常(如 SegFault)而崩溃。

但目前我的输出看起来像这样:

...........
Segmentation fault

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

水染的天色ゝ 2024-12-26 05:01:35

BriefTestProgressListener 完成以下工作:

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 );

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 );
温折酒 2024-12-26 05:01:35

您需要使用CppUnit::XmlOutputter。我不确定连接它的确切语法。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文