C++ BOOST Unit Tests: Invert BOOST_CHECK_EQUAL for not equal

Viewed 216

Is there a way to check for inequality when writing Unit Tests with BOOST?

There is a macro BOOST_CHECK_EQUAL, however there does not appear to be a BOOST_CHECK_NOT_EQUAL macro.

I assume it must be possible to check for inequality in a BOOST Unit Test? I could not find anything from a duckduckgo search however.

2 Answers

The macro you're looking for is BOOST_CHECK_NE:

BOOST_CHECK_NE(a,b);
BOOST_CHECK_EQUAL(a,b);

Since accepting the answer I have discovered some further information:

BOOST_CHECK_NE(a, b)

does what I intended to do, however it has the side effect of requiring a/b to define a stream insertion operator<< for whatever type a/b is.

BOOST_CHECK(a != b)

doesn't require this, so I went with this option instead.

Related