Ctest not running Gtests under suite

Hello all,

I am running into an execution inconsistency between gtest and ctest. Our project is a legacy project that original had a recursive make system but has been updated to a cmake system collecting old tests as well as tests that have been converted to gtests. We are executing all tests through ctest using -R to select specific tests to run.

In converting some of our integration tests, tests that run a series of apps in a pipeline, I was trying to write a gtest suite level fixture, see the docs here. As per the gtest documentation this should run on a per suite basis, where the majority of our suites are defined by a fixture.

This is where ctest and gtest seem to diverge. If my suite is called Foo, and I run ctest -R Foo rather than running all tests under the Foo suite, ctest seems to select each tests individually and run the gtest executable as:
testexe --gtest_filter=“Foo.test1”
Running 1 test from 1 test suite.

testexe --gtest_filter=“Foo.test2”
Running 1 test from 1 test suite.

testexe --gtest_filter=“Foo.test3”
Running 1 test from 1 test suite.

(Other formatting ommited)
Where each test runs the setup and teardown for the test suite.

If I run the executable directly we see:
testexe --gtest_filter=“Foo*”
Running 3 tests from 1 test suites.
(Other formatting omitted)

The suite level fixture will be setup once, and torn down once since all tests are run together as a single suite.

My question is, does ctest retain some functionality with gtest that allows all suites to be run together? Is there some particular command line argument that should be supplied to maintain this behavior?

I haven’t been able to find any particularly good solutions. One such solution being override some ctest functionality through our cmake system, which is something I would like to avoid.

Hopefully that communicates the issues we are running into, and I appreciate all the work that yall do.

There is no integration between ctest -R and gtest_executable --gtest_filter, no. That would take non-trivial, specialized integration work. (Although if someone wanted to contribute this, I suspect that would be welcomed.) The existing gtest support is intended to support either running the whole suite as an individual test, or each individual test case as individual tests. If you are using the latter, this does mean that setup/teardown happens per individual ctest test. However, you also gain the ability to run tests in parallel with ctest -j.

Hi Adam. Did you find a good solution for this one. I have the same issue. Created the static methods SetUpTestSuite() and TearDownTestSuite() hoping these would be called once only, but since CTest calls the test executable once for each TEST_F, the tests are not treated as a Test Suite.