Get BOOST TEST test suite name inside a test case

ⅰ亾dé卋堺 提交于 2020-01-03 08:24:01

问题


I'm using BOOST TEST and I wonder if there is a way to find out the test suite from inside the test case. I know that I can find test case's name by:

boost::unit_test::framework::current_test_case().p_name

Is there a way to find out the suite name also?

My suites-cases structure is:

suite ---> case 1

______|--> case 2

______|--> case 3

Thanks


回答1:


A unit_test has not only p_name but also p_parent_id, which is the ID of the test suite. Both those properties are inherited from test_unit, which is the common base class for unit_test and test_suite.

To get the suite from the ID, we can look at how current_test_case works:

test_case const&
current_test_case()
{
    return get<test_case>( s_frk_impl().m_curr_test_case );
}

The m_curr_test_case member is a test_unit_id, just like p_parent_id. So, to get the test suite of the current test case, you can use this:

framework::get<test_suite>(current_test_case().p_parent_id)

Finally, test_suite has a p_name property just like unit_test, so you should find the name there.



来源:https://stackoverflow.com/questions/18491113/get-boost-test-test-suite-name-inside-a-test-case

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!