Reputation: 650
This is my structure
MyApp
├── CMakeLists.txt
├── src
│ ├── CMakeLists.txt
│ ├── config
│ ├── controller
└── tests
├── CMakeLists.txt
├── config
│ ├── CMakeLists.txt
│ ├── configurationtest.cpp
│ └── main.cpp
├── controller
├── CMakeLists.txt
├── controllertest.cpp
└── main.cpp
When I want to execute my tests I have to select ControllerTests and Run it. Same thing for ConfigurationTest, individually.
I would like to add something in the top-level CMakeLists.txt of Tests to be able to run all tests in subdirectories. This is my top-level tests CMakeLists.txt
project(MyAppTests)
include_directories(${GTEST_INCLUDE_DIRS})
include_directories($ENV{GMOCK_DIR}/include)
add_subdirectory(config)
add_subdirectory(controller)
Each subdirectories have a main.cpp, and add_executable
. In the configuration CMakeLists.txt there is that line :
add_test(NAME ConfigurationTests COMMAND ConfigurationTests)
Upvotes: 1
Views: 1379
Reputation: 42902
Using ctest executable does gives you some more flexibility over using the predefined RUN_TESTS
target. I'm using the following call - executed inside my binary output directory - to run all my tests:
ctest.exe -C Debug -j 16 --no-compress-output -T Test --timeout 600
I do want
Debug
configuration of the tests16
tests in parallelno-compress-output
because I prefer this formattingTest
the software by loading CTestTestfile.cmake
and execute the defined tests
Testing\...\Test.xml
which e.g. can be evaluated by Jenkins xUnit Plugin)600
secondsUpvotes: 1
Reputation: 1121
CMake should have automatically generated a target RUN_TESTS
that lunch all the tests defined in your project.
If it is not here, you may have forgotten to set BUILD_TESTING
option to ON
:
CMake will generate tests only if the enable_testing() command has been invoked. The CTest module invokes the command automatically when the BUILD_TESTING option is ON.
Upvotes: 1