Use enum classes with Boost Test

Another solution is to use BOOST_CHECK(myEnumValue == MyEnumClass::MyEntryB), instead of BOOST_CHECK_EQUAL. This works for me, I'm assuming that for a simple true/false check, boost doesn't need to print out the enum class.


You can disable printing of the type in question with BOOST_TEST_DONT_PRINT_LOG_VALUE(). From the Boost docs:

typedef std::pair<int,float> pair_type;

BOOST_TEST_DONT_PRINT_LOG_VALUE( pair_type )

In this case should you get a mismatch, the test error message will tell you, but it but won't print the actual differing values.


The problem is that Boost.Test has to print the value in case they are not equal, and it uses operator<< on a stream to do that.

In this case there's no cleaner way than to simply define operator<< on an std::ostream or to static_cast to an int, that I can see.

On the other hand, libraries like Catch do not have that requirements, and they probably use some macro magic to accomplish it.