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.

Standard
License
download
CII Best Practices
Try it online

A complete example with a self-registering test that compiles to an executable looks like this:

cover-example

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

cost-of-including-the-framework-header

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.

CppCon 2017 talk about doctest on youtube

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
