Is there a function in boost::test that can return error value?
boost, c++, unit-testing
Solution
Boost provides a macro `BOOST_WARN_MESSAGE` (and `BOOST_CHECK_MESSAGE` and `BOOST_REQUIRE_MESSAGE` as well). In your case it could be used like this:
i=3;
j=4;
bool isEqual = i==j;
BOOST_CHECK(isEqual);
BOOST_WARN_MESSAGE(isEqual, "Failure since i = " << i << " and j = " << j);
Further info is found here.
Problem
Boost Test Library is a very useful unit test framework. However, one thing I feel uncomfortable is that during the unit test if errors happen it will inform the user but not the program itself. Let me make my point clear by using BOOST_CHECK as an example: ``` i=3; j=4; BOOST_CHECK(i==j); ``` The above test case will fail. So, checking the details to find why this test fails will be very interesting. In this case, printing some variables or performing more complicated operations such as writing a file to the disk in the program will be necessary if it knows that the unit test fails. However, BOOST_CHECK will not return a value to denote the test is successful or not. A perfect function should work like this: ``` i=3; j=4; if(Enhanced_BOOST_CHECK(i==j) == failed) { // print some internal varaibles. // or write some data to a file in the disk } ``` So my question is: does BOOST Test Library support this functionality? Thanks.