google test docs : command line args

The google test framework is pretty standard for C++ language, downside is it's not header-only, upside is it's pretty powerful and supports a load of platforms. Which is great if you work in an embedded or cross-platform setup. The makers of googletest (google, of course) currently prefer Bazel, but you can use CMake which I'm doing.

gtest.cc

Commandline args?

A thing that grinds me is how the docs are good but the commandline options are sprinkled all over the show unless you find the place where the code is in https://github.com/google/googletest/blob/main/googletest/src/gtest.cc . And so to bring it all into one place and add context here are the flags I often use with examples that fit my own context. A better explainer of most of the args are in the document "Advanced Topics" https://google.github.io/googletest/advanced.html . I'm not convinced this is an advanced topic, so the person writing the document is probably assuming people new to C++ will not read that topic until much later. When in fact it's needed quite early.

--gtest_fail_if_no_test_linked (flag) 

This flag is pretty much the only defence against silent failure for those cases where none of your tests get recognised by the framework and the binary runs and silently finds no tests. You have errors, but you have no tests that ran!

--gtest_output="xml:DATA/TestResultTests.xml" (file as argument)

Specifies XML (or Json) output format and where to drop the results. The default is in the working directory and that can just get messy for wildcard test result collectors in the CI/CD system.

--gtest_list_tests

--getest_filter="Suitename*"

Which corresponds to your TEST_F() or TEST() macro first identifier passed in. It's also thus possible to run all tests ending in the word serial:

--getest_filter="*Serial"

will run

TEST(TestOpen, ReadSerial)...

TEST(TestWrite, WriteSerial)...

--repeat (integer)

Is the other option I will use often enough.



Comments