test

AlexandrePrevot's avatarfrom AlexandrePrevot

Run unit tests using CTest. Use when user asks to run tests, test the code, check test results, or mentions test failures.

⭐0stars🔀0forks📁View on GitHub🕐Updated Jan 2, 2026

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.
nametest
descriptionRun unit tests using CTest. Use when user asks to run tests, test the code, check test results, or mentions test failures.
allowed-toolsBash, Read, Glob

Test Skill

Run unit tests for the OrderParserProcessor project using CTest.

Prerequisites

  • Project must be built with -DBUILD_TESTS=ON option
  • 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

  1. Find the build directory (search for directories like build/, cmake-build-*/, backend/build/, etc.)
  2. Check if tests were built (look for test executables or check CMake cache for BUILD_TESTS)
  3. If tests not built, rebuild with tests: cmake -B <build_dir> -DBUILD_TESTS=ON && cmake --build <build_dir>
  4. Identify which specific tests to run based on user request or context
  5. Run the specific tests using CTest with pattern matching
  6. Report test results (passed/failed counts)
  7. If tests fail, show failure details and relevant error messages

Test Commands

# 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
# 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 tests
  • connectivity/test/ - Connectivity module tests
  • Other component directories may have their own test/ subdirectories

Best Practices

  1. Run specific tests rather than the entire suite when working on a particular component
  2. Use parallel execution (-j2 or higher) when running multiple tests - some tests use timers
  3. List tests first with -N to see what's available
  4. Use pattern matching with -R to target relevant tests

Common Issues

  • No tests found: Ensure BUILD_TESTS=ON was set during CMake configuration
  • Test compilation errors: Check test source files in component test/ directories
  • Test failures: Review output with --output-on-failure flag
  • Build directory missing: Run build first with tests enabled
  • Wrong build directory: Search for actual build directory location
  • Tests taking too long: Use -j for 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