Get the name of the BOOST TEST test set inside the test case

I am using BOOST TEST and I am wondering if there is a way to find out the test suite from within the test case . I know that I can find the test case name:

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

Is there any way to find out the package name as well?

My hull structure:

suite ---> case 1

______|--> case 2

______|--> case 3

thanks

+8
c ++ boost unit-testing boost-test
source share
1 answer

A unit_test has not only p_name , but also p_parent_id , which is the identifier of the test suite. Both of these properties inherit from test_unit , which is a common base class for unit_test and test_suite .

To get a set of IDs, we can see 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 element is test_unit_id , as is 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 the test_suite property, like unit_test , so you should find the name there.

+5
source share

All Articles