test
Run unit tests using CTest. Use when user asks to run tests, test the code, check test results, or mentions test failures.
When & Why to Use This Skill
This Claude skill automates the execution and management of unit tests using CTest within CMake-based environments. It streamlines the development workflow by identifying build directories, compiling test suites with the necessary flags, and running specific or parallel tests to ensure code reliability and rapid bug detection.
Use Cases
- Verifying code changes by running targeted unit tests for specific modules like backend or connectivity services.
- Automating the build-and-test cycle when tests are not yet compiled, ensuring the environment is correctly configured with -DBUILD_TESTS=ON.
- Reducing development wait times by executing test suites in parallel using multi-core processing flags.
- Debugging regression issues by listing available tests and running failing cases in verbose mode to capture detailed error logs.
- Performing health checks on the entire project codebase by running the full test suite and reporting pass/fail statistics.
| name | test |
|---|---|
| description | Run unit tests using CTest. Use when user asks to run tests, test the code, check test results, or mentions test failures. |
| allowed-tools | Bash, Read, Glob |
Test Skill
Run unit tests for the OrderParserProcessor project using CTest.
Prerequisites
- Project must be built with
-DBUILD_TESTS=ONoption - Tests are typically located in service directories under
test/subdirectories (e.g.,backend/test/,connectivity/test/) - Identify the build directory (check for existing build directories)
Instructions
- Find the build directory (search for directories like
build/,cmake-build-*/,backend/build/, etc.) - Check if tests were built (look for test executables or check CMake cache for BUILD_TESTS)
- If tests not built, rebuild with tests:
cmake -B <build_dir> -DBUILD_TESTS=ON && cmake --build <build_dir> - Identify which specific tests to run based on user request or context
- Run the specific tests using CTest with pattern matching
- Report test results (passed/failed counts)
- If tests fail, show failure details and relevant error messages
Test Commands
Run Specific Tests (Recommended)
# Run tests matching a pattern
ctest --test-dir <build_dir> -R <test_name_pattern> --output-on-failure
# Examples:
ctest --test-dir <build_dir> -R backend --output-on-failure
ctest --test-dir <build_dir> -R connectivity --output-on-failure
ctest --test-dir <build_dir> -R script_processor --output-on-failure
Run All Tests
ctest --test-dir <build_dir> --output-on-failure
Run with Parallel Execution (Recommended for speed)
# Use -j2 or higher to run tests in parallel
# Some tests use timers, so parallel execution speeds things up
ctest --test-dir <build_dir> -j2 --output-on-failure
# Adjust based on available CPU cores
ctest --test-dir <build_dir> -j4 --output-on-failure
List Available Tests
ctest --test-dir <build_dir> -N
Run Tests Verbosely
ctest --test-dir <build_dir> -R <pattern> --verbose
Rerun Failed Tests
ctest --test-dir <build_dir> --rerun-failed --output-on-failure
Build Tests (if not already built)
cmake -B <build_dir> -DBUILD_TESTS=ON
cmake --build <build_dir>
Test Organization
Tests are organized per service/component:
backend/test/- Backend service testsconnectivity/test/- Connectivity module tests- Other component directories may have their own
test/subdirectories
Best Practices
- Run specific tests rather than the entire suite when working on a particular component
- Use parallel execution (
-j2or higher) when running multiple tests - some tests use timers - List tests first with
-Nto see what's available - Use pattern matching with
-Rto target relevant tests
Common Issues
- No tests found: Ensure
BUILD_TESTS=ONwas set during CMake configuration - Test compilation errors: Check test source files in component
test/directories - Test failures: Review output with
--output-on-failureflag - Build directory missing: Run build first with tests enabled
- Wrong build directory: Search for actual build directory location
- Tests taking too long: Use
-jfor parallel execution or run specific tests with-R
Success Criteria
- Requested tests pass successfully
- No segmentation faults or crashes
- Test output is clear and informative
- Targeted tests run efficiently