I have a set of unit tests using gtest as framework.
Build, and execute, and the output looks like this :
I'd like to have the output similar to the output when using cxxunit (.
when test pass, detail error when it fails). If possibly, with colors.
How to do this?
If I wasn't clear, I am looking for code and exact way how to do this.
The output should be something like :
Executing dummy_tests .....
../code/app/unit_tests/unittest_dummy.cpp:25: Failure
Value of: 2
Expected: 1
..
FAILED
I am trying to use this example and create custom listener. But the example doesn't have colorful output, and it prints lots of messages to the output.
As for the colorful output, developers implemented ColoredPrintf()
function.
As for the particular problem I am facing is lack of documentation :
- how to get information about whole tests suite at the program start? (I guess in the
OnTestProgramStart()
method) - how to get information about whether a test failed? (
OnTestProgramEnd()
? or other method?)
The documentation page you mention has a link to the sample code which answers your questions. You can enumerate test cases and tests in them in
OnTestProgramStart()
or later in this manner:The information about the test status can indeed be collected in
OnTestProgramEnd()
:The
ColoredPrintf()
is not available externally; you may just copy its code into your project.This answer linked to the example will more information with some information I was missing. This answer helped me get the seed value.
The header looks like :
And the source file :