Home > Software engineering >  C BOOST Unit Tests: Invert BOOST_CHECK_EQUAL for not equal
C BOOST Unit Tests: Invert BOOST_CHECK_EQUAL for not equal

Time:03-10

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.

CodePudding user response:

The macro you're looking for is BOOST_CHECK_NE:

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

CodePudding user response:

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