Add a test to the project to be run by
add_test(NAME <name> COMMAND <command> [<arg>...] [CONFIGURATIONS <config>...] [WORKING_DIRECTORY <dir>] [COMMAND_EXPAND_LISTS])
Tests added with the
add_test(NAME) signature support using
in test properties set by
set_tests_properties(). Test properties may only be set in the
directory the test is created in.
add_test options are:
Specify the test command-line. If
<command>specifies an executable target created by
add_executable(), it will automatically be replaced by the location of the executable created at build time.
The command may be specified using
Restrict execution of the test only to the named configurations.
Set the test property
WORKING_DIRECTORYin which to execute the test. If not specified, the test will be run in
CMAKE_CURRENT_BINARY_DIR. The working directory may be specified using
New in version 3.16.
COMMANDarguments will be expanded, including those created with
If the test command exits with code
0 the test passes. Non-zero exit code
is a "failed" test. The test property
WILL_FAIL inverts this
logic. Note that system-level test failures such as segmentation faults or
heap errors will still fail the test even if
WILL_FALL is true. Output
written to stdout or stderr is captured by
ctest(1) and only
affects the pass/fail status via the
New in version 3.16: Added
add_test(NAME mytest COMMAND testDriver --config $<CONFIG> --exe $<TARGET_FILE:myexe>)
This creates a test
mytest whose command runs a
passing the configuration name and the full path to the executable
file produced by target
The command syntax above is recommended over the older, less flexible form:
add_test(<name> <command> [<arg>...])
Add a test called
<name> with the given command-line.
Unlike the above
NAME signature, target names are not supported
in the command-line. Furthermore, tests added with this signature do not
in the command-line or test properties.