doctest-cmake

Integrate doctest single-header tests into CMake C++ projects.

Updated Jan 29, 2026
One-click install
npx skills add https://github.com/EvitanRelta/doctest-cmake --skill doctest-cmake
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: doctest-cmake
Source: https://github.com/EvitanRelta/doctest-cmake/tree/main
Command: npx skills add https://github.com/EvitanRelta/doctest-cmake --skill doctest-cmake

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Setting up the doctest single-header framework in CMake C++ projects can be verbose; this skill guides a clean pattern to enable tests colocated with implementation code, reducing boilerplate and keeping tests nearby.

Core Features & Use Cases

  • Colocated tests: Write tests in test_main.cpp alongside source files.
  • Doctest header integration: Use the header-only doctest library in your project structure.
  • CMake integration: Create a separate tests target that mirrors the main executable while keeping test code disabled in the app.

Quick Start

Create test_main.cpp with DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN and include doctest/doctest.h, then add a tests target in CMake alongside your main app.

Frequently Asked Questions about doctest-cmake

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

FAQPage Schema
How do I set up doctest in CMake with colocated tests?

Setting up doctest in CMake involves placing doctest.h under third-party/doctest, creating test_main.cpp with DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN, and adding a CMake tests target mirroring your main app sources.

What is the best way to integrate a header-only testing framework into a CMake C++ project?

Integrating a header-only testing framework like doctest requires adding the single header to your project, then configuring a separate CMake target for tests that compiles main app sources alongside your test runner.

Can I keep unit tests colocated with implementation code in CMake?

Yes, you can keep unit tests colocated with implementation code by creating a dedicated test runner file and a separate CMake tests target that mirrors the main executable while keeping test code disabled in the app.

Do I need a separate test runner when using doctest in CMake?

Yes, a separate test runner is needed when using doctest in CMake. You must create a test_main.cpp file containing the DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN macro to build alongside your main app target.

Why should I use colocated tests instead of a separate test directory?

Using colocated tests reduces boilerplate and keeps tests nearby your implementation code, making it easier to maintain and update unit tests alongside the source files they validate in C++ projects.