Reputation: 668
I'm learning how to use the Boost Test Library at the moment, and I can't seem to get test suites to work correctly. In the following code 'test_case_1' fails correctly but it's reported as being in the Master Test Suite instead of 'test_suite_1'.
Anyone know what I'm doing wrong?
#define BOOST_AUTO_TEST_MAIN
#include <boost/test/auto_unit_test.hpp>
BOOST_AUTO_TEST_SUITE(test_suite_1);
BOOST_AUTO_TEST_CASE(test_case_1) {
BOOST_REQUIRE_EQUAL(1, 2);
}
BOOST_AUTO_TEST_SUITE_END();
edit:
Ovanes' answer led me to understand the suite hierarchy better - in this case test_suite_1 is a sub-suite of the root suite which by default is named 'Master Test Suite'. The default logging only shows the root suite, which isn't what I expected by I can deal with it :)
You can set the root suite name by defining BOOST_TEST_MODULE - so an alternative version of the above example which gives the expected error message is:
#define BOOST_TEST_MODULE test_suite_1
#define BOOST_AUTO_TEST_MAIN
#include <boost/test/auto_unit_test.hpp>
BOOST_AUTO_TEST_CASE(test_case_1) {
BOOST_REQUIRE_EQUAL(1, 2);
}
Upvotes: 3
Views: 1133
Reputation: 1945
Also, once you define BOOST_TEST_MODULE, you don't need to define BOOST_AUTO_TEST_MAIN
Upvotes: 0
Reputation: 5673
It depends how you configure your logger to produce the report. For example passing to your example --log_level=all will result in the following output:
Running 1 test case...
Entering test suite "Master Test Suite"
Entering test suite "test_suite_1"
Entering test case "test_case_1"
d:/projects/cpp/test/main.cpp(9): fatal error in "test_case_1": critical check 1 == 2 failed [1 != 2]
Leaving test case "test_case_1"
Leaving test suite "test_suite_1"
Leaving test suite "Master Test Suite"
*** 1 failure detected in test suite "Master Test Suite"
Here is the link to the command line config options of Boost Test Framework.
Regards,
Ovanes
Upvotes: 2