'Run each test in a new container

I have google test based test suite. Since the tests manipulate the filesystem and do other things that I don't want to be left behind in case of a test crash, besides just not playing nicely with running tests on parallel, I want to run each test case in a new container. I am currently using CTest (aka. CMake test) to run the gtest binary, but I am not very attached to either of these, so if the best option is some other tool, I can accept that.

Can anyone suggest a way to automate this? Right now I am adding each individual test case manually to CTest with a call to docker run as part of the test command, but it is brittle and time consuming. Maybe I am doing this wrong?



Solution 1:[1]

You can run your GTest runner with --gtest_list_tests to list all tests.

You can then loop through this list and call your GTest runner with --gtest_filter set to the name of specific test.

The format of the list is a bit awkward to parse though, so need some shell scripting skills to get the actual test names.

Check the exit code of the GTest runner the know whether the test succeeded or failed.

I do not know if this integrates well with CTest.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 rveerd