How to send custom message in Google C++ Testing Framework?

Yuriy Petrovskiy picture Yuriy Petrovskiy · May 11, 2013 · Viewed 48.3k times · Source

I use Google C++ Testing Framework for unit testing of my code. I use Eclipse CDT with C++ Unit testing module for output analysis.

Previously I used CppUnit it has macros family CPPUNIT*_MESSAGE that could be called like this:

CPPUNIT_ASSERT_EQUAL_MESSAGE("message",EXPECTED_VALUE,ACTUAL_VALUE)

And allows to send custom messages to test output.

Is there a way to include some custom text in google test output?

(Preferably the way that could include message to data that is read by existing programs for automated unit testing using google test.)

Answer

user2093113 picture user2093113 · May 11, 2013

The gtest macros return a stream for outputting diagnostic messages when a test fails.

EXPECT_TRUE(false) << "diagnostic message";