Version 0.x Modules Testing Modules & Scripts Test Suite
February 13, 2025 at 1:11 AM Edit on GitHubTest Suite
The define_test_suite()
function is used to group related test cases into a
test suite.
Table of Contents
Parameters
The following parameters are accepted:
- < name >: Human readable name of test suite. The parameter is also used to label tests (see labels).
DIRECTORY
: Path to directory that contains test-cases.MATCH
: (optional), Glob pattern used to match test-case files. Defaults to*_test.cmake
(see match pattern).
Rebuild Required
Changes to function define_test_suite()
parameters requires you to rebuild your project, before the changes take effect.
Example
include("rsp/testing")
define_test_suite("unit" DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/unit")
define_test_suite("integration" DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/integration")
Given the above shown example, when define_test_suite()
is invoked, it will recursively search for files¹ in the
specified directory. Each file is then included into the
current CMake scope. This means that calls to define_test_case()
and
define_test()
are registered (tests are added to ctest).
After you have built your CMake project, you will be able to run the tests.
ctest --output-on-failure --test-dir <your-build-directory>/tests
¹: See match pattern.
Match Pattern
By default, only files that match *_test.cmake
will be processed by define_test_suite()
. If this is not to your
liking, then you can specify a custom match pattern:
define_test_suite(
"unit"
DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/unit"
MATCH "*Test.cmake"
)
Labels
The < name >
parameter is used to automatically used as a label
for all tests within the test suite. This allows you to use ctest’s label regex
functionality and thereby only run the tests from the suite that you wish.
ctest --output-on-failure \
--label-regex "integration" \
--test-dir <your-build-directory>/tests