6

I am using Boost.Test library for implementing unit test cases in C++. Suppose I have two suites such as

BOOST_AUTO_TEST_SUITE(TestA)
BOOST_AUTO_TEST_CASE(CorrectAddition)
{
BOOST_CHECK_EQUAL(2+2, 4);
}

BOOST_AUTO_TEST_CASE(WrongAddition)
{
    BOOST_CHECK_EQUAL(2 + 2, 5);
}

BOOST_AUTO_TEST_SUITE_END()

BOOST_AUTO_TEST_SUITE(TestB)
BOOST_AUTO_TEST_CASE(CorrectAddition)
{
bool ret = true;
    BOOST_CHECK_EQUAL(ret, true);
}
BOOST_AUTO_TEST_CASE(WrongAddition)
{
    BOOST_CHECK_EQUAL(2 + 2, 5);
}
BOOST_AUTO_TEST_SUITE_END() 

and I would like to run only say suite 'TestB', how shall I execute it. I really thank for your time and help. Sorry if this question is been posted or documented else where.

Jørgen Fogh
  • 7,516
  • 2
  • 36
  • 46
sprasad
  • 75
  • 1
  • 3

2 Answers2

5

Conform to this documentation, the OP should call the unit test executable with the following parameter

--run_test=TestB

to run only the unit tests of test suite TestB.

If the unit test CorrectAddition of all test suites shall be run, then the parameter is

--run_test=*/CorrectAddition

Wildcard ability of Boost.Test is quite powerful, hence the parameter could also be written as

--run_test=*/C*
CKE
  • 1,533
  • 19
  • 18
  • 29
2

Assuming you are using the library-supplied main entry point, command-line parsing, etc., and haven't rolled your own, you can select specific test suites and test cases by name or pattern via a command-line switch at run time.

See this page in the documentation for a good example.

bjlaub
  • 2,707
  • 21
  • 12
  • Would be nice if there was some hint of the steps required to get to the "example" part. Or is that some kind of sacred treasure that must be hidden like chronic masturbation disorder tendency ? – niken Aug 13 '21 at 16:58