cpp-unit-testing

Standardize C++ unit tests with GoogleTest and register them via smith_add_tests.

236|35|Updated Feb 24, 2020
One-click install
npx skills add https://github.com/llnl/smith --skill cpp-unit-testing-llnl
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: cpp-unit-testing
Source: https://github.com/llnl/smith/tree/main/skills/cpp-unit-testing
Command: npx skills add https://github.com/llnl/smith --skill cpp-unit-testing-llnl

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Ensures reliable, maintainable unit testing for Smith by standardizing the use of GoogleTest, colocating tests with code, and automatic registration with CTest.

Core Features & Use Cases

  • GoogleTest usage for unit tests near code
  • Tests living next to the component under test (e.g., src/smith/<component>/tests or src/tests)
  • Registration with CTest via the smith_add_tests macro

Quick Start

Add a unit test in the component’s tests/ directory and register it with smith_add_tests in CMake.

Frequently Asked Questions about cpp-unit-testing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I set up GoogleTest unit tests for my C++ components?

To register GoogleTest unit tests with CTest, use the smith_add_tests macro within your component's CMakeLists.txt file. This automatically registers the tests with CTest, ensuring deterministic and reliable execution during your CI pipeline.

What is the best way to colocate C++ unit tests with my source code?

The best way to colocate C++ unit tests is to place them directly next to the component under test, specifically inside directories like src/smith/component/tests or src/tests. This ensures maintainability and reliable unit testing alongside your codebase.

How do I standardize C++ unit tests to avoid unreliable CI pipelines?

Standardize C++ unit tests by colocating them with code under src/smith/component/tests or src/tests, and registering them with CTest via the smith_add_tests macro. This ensures deterministic test execution and resolves unreliable CI pipelines.

Do I need CMake and GoogleTest to set up C++ unit tests for Smith?

Yes, setting up C++ unit tests requires GoogleTest, CMake, and a minimal tests/ directory containing a CMakeLists.txt file. These dependencies are necessary to register tests using the smith_add_tests macro and execute them via CTest.

Why are my C++ unit tests unreliable or fragmented during CI?

C++ unit tests become unreliable or fragmented without standardized practices. Colocating tests with code under src/smith/component/tests and registering them with CTest via smith_add_tests ensures deterministic execution and resolves software testing inconsistencies.

Does GoogleTest work with CTest for C++ unit testing?

Yes, GoogleTest works with CTest for C++ unit testing. You can automatically register and execute GoogleTest cases with CTest by using the smith_add_tests macro in your component's CMakeLists.txt file within the tests/ directory.