Search code examples
c++unit-testinggoogletest

How to reduce verbosity of googletest (overwrite two methods of the default listener)?


I would like to suppress overly verbose "RUN" and "OK" output lines from googletest, while maintaining all other output from the default listener.

https://github.com/google/googletest/blob/master/docs/advanced.md#defining-event-listeners describes:

(1) how to replace the default listener by a custom listener, or

(2) how to add an additional listener.

Unfortunately, this does not exactly solve my problem. Modification (1) would also suppress other messages, unless I reimplement them. Modification (2) does not overwrite the default methods, but only adds additional output.

For the wanted solution, my listener would inherit from the default listener, and not from EmptyTestEventListener.

How to achieve that?


Solution

  • The default listener is called PrettyUnitTestResultPrinter. It is implemented in src/gtest.cc. Unfortunately, it is not declared in a .h file. Therefore there is no straightforward way to inherit from it.

    Therefore the easiest solution to my problem is a brutal one: Copy all of googletest to a ThirdParty/gtest directory in my project, and patch src/gtest.cc. Just search for "RUN" and "OK" and delete the unwanted output commands.