← 返回命令列表

Linux command

ctest 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Run all tests in current build directory

ctest

Run tests with verbose output

ctest -V

Run specific test by name

ctest -R [test_name_pattern]

Exclude tests by name

ctest -E [exclude_pattern]

Run tests in parallel

ctest -j [4]

Run with timeout

ctest --timeout [60]

List available tests

ctest -N

Rerun failed tests

ctest --rerun-failed

Run tests for a specific configuration

ctest -C [Release]

说明

ctest is CMake's test driver program that discovers and runs tests defined in CMake projects. It executes tests defined via CMake's add_test() command and provides detailed reporting of pass/fail status. The tool supports parallel test execution, filtering by name or label, timeout enforcement, and rerunning failed tests. It integrates with CMake's build system and can be run from build directories after compilation. ctest is commonly used in CI/CD pipelines for automated testing, and its output can be formatted for various continuous integration systems. It handles test dependencies, fixture setup/teardown, and can export results to various formats including JUnit XML.

参数

-V, --verbose
Verbose output.
-R _regex_
Run tests matching regex.
-E _regex_
Exclude tests matching regex.
-j _n_
Run tests in parallel.
--timeout _seconds_
Per-test timeout.
-N
List tests without running.
--rerun-failed
Only run previously failed tests.
-L _label_
Run tests with specific label.
--output-on-failure
Show output only for failed tests.
-C _config_, --build-config _config_
Choose configuration to test (e.g., Debug, Release).
-VV, --extra-verbose
Enable more verbose output from tests.
--test-dir _dir_
Specify the directory in which to look for tests.
--stop-on-failure
Stop running tests after the first failure.

FAQ

What is the ctest command used for?

ctest is CMake's test driver program that discovers and runs tests defined in CMake projects. It executes tests defined via CMake's add_test() command and provides detailed reporting of pass/fail status. The tool supports parallel test execution, filtering by name or label, timeout enforcement, and rerunning failed tests. It integrates with CMake's build system and can be run from build directories after compilation. ctest is commonly used in CI/CD pipelines for automated testing, and its output can be formatted for various continuous integration systems. It handles test dependencies, fixture setup/teardown, and can export results to various formats including JUnit XML.

How do I run a basic ctest example?

Run `ctest` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -V, --verbose do in ctest?

Verbose output.