I would like to make groups of CTests to improve readability with a structure like this:
How can I do this? My current CMakeLists.txt:
cmake_minimum_required(VERSION 3.20)
project(Test)
set(CMAKE_CXX_STANDARD 14)
enable_testing()
add_executable(env environment.cpp)
add_test(Environment env)
add_subdirectory(unit) # Includes tests 'UserInterface' and 'Test2'
The tests in the subdirectory are not grouped together when I run it:
CodePudding user response:
CTest
doesn't support this, as it's not a classical unit testing framework, but rather a convenient way to "run stuff" that is already configured (in most cases) to be built with CMake
.
What you can do is:
- Impose a naming scheme, e.g. prefix tests by a common identifier. For all tests that are registered with
add_test(foo_...)
, you can run this group withctest -R foo_
for example. - Associate setup- and teardown-like test with a set of tests (have a look at test properties like
FIXTURES_CLEANUP
). However, this doesn't give you structure per se, it only ensures a certain existing test is run as a setup/teardown before/after the test in question.