Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
D

doctest

> 测试质量
Open source

The fastest feature-rich C++11/14/17/20/23 single-header testing framework

6.8K stars0 likes5 views
WebsiteGitHub

About

The fastest feature-rich C++11/14/17/20/23 single-header testing framework

master branch
dev branch

doctest is a new C++ testing framework but is by far the fastest both in compile times (by orders of magnitude) and runtime compared to other feature-rich alternatives. It brings the ability of compiled languages such as D / Rust / Nim to have tests written directly in the production code thanks to a fast, transparent and flexible test runner with a clean interface. A complete example with a self-registering test that compiles to an executable looks like this:

There are many C++ testing frameworks - Catch, Boost.Test, UnitTest++, cpputest, googletest and others.

The key differences between it and other testing frameworks are that it is light and unintrusive:

  • Ultra light on compile times both in terms of including the header and writing thousands of asserts
  • Doesn't produce any warnings even on the most aggressive warning levels for MSVC/GCC/Clang
  • Can remove everything testing-related from the binary with the DOCTEST_CONFIG_DISABLE identifier
  • thread-safe - asserts can be used from multiple threads spawned from a single test case - example
  • asserts can be used outside of a testing context - as a general purpose assert library - example
  • No global namespace pollution (everything is in doctest::) & doesn't drag any headers with it
  • Portable C++11 (use tag 1.2.9 for C++98) with over 100 different CI builds (static analysis, sanitizers..)
  • binaries (exe/dll) can use the test runner of another binary => tests in a single registry - example

This allows the framework to be used in more ways than any other - tests can be written directly in the production code!

Tests can be a form of documentation and should be able to reside near the production code which they test.

  • This makes the barrier for writing tests much lower - you don't have to: 1) make a separate source file 2) include a bunch of stuff in it 3) add it to the build system and 4) add it to source control - You can just write the tests for a class or a piece of functionality at the bottom of its source file - or even header file!
  • Tests in the production code can be thought of as documentation/up-to-date comments - showcasing the APIs
  • Testing internals that are not exposed through the public API and headers is no longer a mind-bending exercise
  • Test-driven development in C++ has never been easier!

The framework can be used just like any other without mixing production code and tests - check out the features.

doctest is modeled after Catch and some parts of the code have been taken directly - check out the differences.

This table compares doctest / Catch / lest which are all very similar.

Checkout the CppCon 2017 talk on YouTube to get a better understanding of how the framework works and read about how to use it in the JetBrains article - highlighting the unique aspects of the framework! On a short description on how to use the framework along production code you could refer to this GitHub issue. There is also an older article in the february edition of ACCU Overload 2017. Documentation

Project:

  • Features and design goals - the complete list of features
  • Community driven roadmap - upcoming features
  • Benchmarks - compile-time and runtime supremacy
  • Contributing - how to make a proper pull request
  • Changelog - generated changelog based on closed issues/PRs

Usage:

  • Tutorial - make sure you have read it before the other parts of the documentation
  • Assertion macros
  • Test cases, subcases and test fixtures
  • Parameterized test cases
  • Command line
  • Logging macros
  • main() entry point
  • Configuration
  • String conversions
  • Reporters
  • Extensions
  • FAQ
  • Build systems
  • Examples

Bugs and feature proposals

If you find a bug, report it! If you have an idea on how to improve the project, be it anything from better documentation to adding new features, consider preparing a feature proposal. We call it proposal because the word "request" has the wrong intention, no one will auto-magically fix it for you, but the idea can be discussed and accepted or rejected before you implement it. Please make sure to read through the Contributing page before submitting any issue, the triaging procedure is documented there.

Contributing

Contributions in the form of issues and pull requests are welcome - check out the Contributing page.

Stargazers over time

Logo

The logo is licensed under a Creative Commons Attribution 4.0 International License. Copyright © 2019 area55git  

Issues· 142 open

View all issuesOpen on GitHub
  • #1208

    SUBCASE in a loop became quadratic in v2.5.x

    Updated Sep 23, 2026
  • #1108

    Per-test-case shared setup across SUBCASEs

    type/feature-proposalcategory/API-usageUpdated Sep 19, 2026
  • #205

    Memory leaks just by including doctest.h

    Updated Sep 1, 2026
  • #961

    Enhance existing matcher system

    Updated Jul 13, 2026
  • #846

    Feature request: predicate on CHECK_THROWS

    has-workaroundtype/feature-proposalcategory/API-usageUpdated Jul 12, 2026
  • #923

    Honor FORCE_COLOR and NO_COLOR environment variables

    type/feature-proposalcategory/CLIUpdated Jul 12, 2026
  • #76

    testing private members - ability to write test cases in class bodies

    verdict/stalehas-workaroundUpdated Jul 5, 2026
  • #345

    FAQ item request: Accessing current testcase name

    has-workaroundtype/feature-proposalcategory/API-usageUpdated Jun 22, 2026
  • #1168

    Tried to switch a large project from Catch2 v3 to doctest and I see no perf improvements

    Updated Jun 16, 2026
  • #1138

    VS2026: cl.exe 19.51+ miscompiles calls to CHECK()

    Updated May 29, 2026

> Tags

C++c-plus-pluscppcpp11cpp14

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 23, 2026
Category测试质量
PricingOpen source

> Related tools

J
Jest
JavaScript 测试框架
P
Playwright
现代端到端测试框架
E
eslint-plugin-test-selectors
Enforces that data-test-id attributes are added to interactive DOM elements (JSX) to help with UI testing. JSX only.