ctest
CTest is a command line tool that is a part of the CMake build system. It is primarily used for running tests on CMake-built projects. Here are some key points about ctest:
-
Test Execution: CTest allows you to execute tests defined in your CMake project conveniently from the command line. It can run tests in parallel, making it efficient for large projects with numerous tests.
-
Test Discovery: It automatically discovers the tests defined in your project, and you can group them using regular expressions or by specifying specific test executable names.
-
Continuous Integration Integration: CTest is often used in conjunction with Continuous Integration (CI) systems like Jenkins, Travis CI, or GitLab CI. It provides an integration mechanism to run tests as part of the CI build process.
-
Test Output: CTest captures the output of the tests it executes, including both standard output and standard error. It can generate detailed reports and summaries of the test results, which can be helpful for identifying and fixing issues.
-
Test Labels: CTest supports labeling tests using user-defined attributes. This feature allows you to categorize tests based on their characteristics or requirements (e.g., performance tests, unit tests, integration tests, etc.). Labels can be used to selectively execute specific groups of tests.
-
Test Timeouts: CTest allows you to set time limits for individual tests. If a test exceeds the specified time limit, CTest can terminate it and mark it as failed.
-
Test Coverage: CTest provides support for code coverage analysis. By enabling coverage tracking, you can generate reports that show which parts of your codebase have been tested.
-
Dashboard Reporting: CTest can upload test results to a centralized dashboard server, such as the CDash web application. This allows for easy monitoring and visualization of test results across multiple projects or platforms.
Note: CTest is primarily used with CMake projects; however, it can also be used independently with custom test suites if the project follows a specific test executable naming convention.
List of commands for ctest:
-
ctest:tldr:0b190 ctest: Run all tests defined in the CMake project, executing 4 jobs at a time in parallel.$ ctest -j${4} --output-on-failuretry on your machineexplain this command
-
ctest:tldr:25e10 ctest: Run a single test based on its name, or filter on a regular expression.$ ctest --output-on-failure -R '^${test_name}$'try on your machineexplain this command
-
ctest:tldr:e74fe ctest: Show a list of available tests.$ ctest -Ntry on your machineexplain this command