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.
Simply printing to stderr will work in the default test configuration.
Nope, searched through the headers and there is nothing about adding your own logs in the middle. Might be something to request. You could log an enhancement task if you want at http://code.google.com/p/googletest/issues/list
Take care.
You could write a wrapper for the default printer
PrettyUnitTestResultPrinter
to also print out test properties. You can get the default printer withlisteners.default_result_printer()
(see below). You would have to implementEmptyTestEventListener
and change the methodPrettyUnitTestResultPrinter::OnTestEnd()
(in gtest.cc) and use the results properties:test_info.result()->GetTestProperty(i)
like the printer for XML output:Then you can replace the default listener for your tests like it's done in the google test sample:
I have just used
std::cout
with ansi color codes in linux but I believe the codes work in windows since win 10 anniversary update.or just create a header file and some
#define
statements and include it in my tests. I also like to format the text to stick out a little more too.So my code would be: