Printing additional output in Google Test

Greg Hewgill picture Greg Hewgill · Oct 28, 2011 · Viewed 68.6k times · Source

I'm using the googletest C++ testing framework. Normally the textual output of running a test looks like this:

[ RUN      ] MyTest.Fuzz
[       OK ] MyTest.Fuzz (1867 ms)

I would like to output some additional data in the same format, for example:

[ RUN      ] MyTest.Fuzz
[          ] random seed = 1319760587
[       OK ] MyTest.Fuzz (1867 ms)

I have found Logging Additional Information in the googletest documentation but that only seems to send structured data to the XML output, not the standard console output.

Is there a googletest function I can call inside my unit test that outputs text in this format? Manually sending data to cout works, but it doesn't include the usual coloured output so I have to explicitly indent the output by printing 13 spaces or whatever.

Answer

Martin Nowak picture Martin Nowak · Jan 27, 2014

Simply printing to stderr will work in the default test configuration.

std::cerr << "[          ] random seed = " << random_seed << std::endl;