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.)
The gtest macros return a stream for outputting diagnostic messages when a test fails.
There is no way of doing it cleanly in the current version of gtest. I looked at the code, and the only text output (wrapped in gtest "Messages") is shown if you fail a test.
However, at some point, gtest starts
printf
'ing to the screen, and you can leverage the level above that to get colors that are platform independent.Here's a hacked macro to do what you want. This uses the gtest internal text coloring. Of course the
internal::
namespace should be sounding off warning bells, but hey, it works.Usage:
Output:
Code:
You should define the below:
using this:
There is a quite simple and hacky way for doing it (without need of diving into internal classes or creating new custom classes).
Just define a macro:
and use
GTEST_COUT
(just likecout
) in your tests :And you'll see such result:
Credit goes to @Martin Nowak for his finding.
Refer to Mark Lakata's answer, here is my way:
Step1: create a header file, for example:
gtest_cout.h
Code:
Step2: use
GOUT
in your gtestUsage: