5

I use boost::test to run integration tests on a class that creates directories and files. I would like these files to be named test-case specific so if I run into trouble I can easily find which test case left its directories/files around.

So I would like to use the test case name in the constructor of the fixture that I'm using, as demonstrated below. Is this possible at all, and how? I searched the boost::test manual but could not find this information.

e.g.

struct foo_fixture
{
    foo_fixture() 
    { 
        std::string case_dependent_name( BOOST_TEST_CASE_NAME ); 
        create_directory( case_dependent_name );
    }
};

BOOST_FIXTURE_TEST_CASE ( foo_case_one, foo_fixture )
{
   ...
}
BOOST_FIXTURE_TEST_CASE ( foo_case_two, foo_fixture )
{
   ...
}
andreas buykx
  • 12,608
  • 10
  • 62
  • 76

1 Answers1

7

I found this, and it works:

boost user group discussion

Essentially, you use the string member variable found on the test_unit instance:

boost::unit_test::framework::current_test_case().p_name
Dan B
  • 131
  • 1
  • 6