The lightest feature-rich C++98/C++11 single-header testing framework for unit tests and TDD
C++ CMake Python
Latest commit 7e61291 Nov 15, 2016 @onqtam version 1.1.3

README.md

The lightest feature-rich C++98/C++11 single-header testing framework for unit tests and TDD

master branch Linux/OSX Linux/OSX Status Windows Windows status Coverage Status Static Analysis
dev branch Linux/OSX Linux/OSX Status Windows Windows status Coverage Status

This library is free, and will stay free but needs your support to sustain its development. There are lots of new features and maintenance to do. If you work for a company using doctest or have the means to do so, please consider financial support.

Pledgie Patreon PayPal


The doctest library is inspired by the unittest {} functionality of the D programming language and Python's docstrings - tests can be considered a form of documentation and should be able to reside near the production code which they test.

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

cover-example

Note how a standard C++ operator for equality comparison is used - doctest has one core assertion macro (it also has for less than, equals, greater than...) - yet the full expression is decomposed and the left and right values are logged.

It is modeled after Catch which is currently the most popular alternative for testing in C++ - check out the differences.


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

What makes doctest different is that it is ultra light on compile times (by orders of magnitude) and is unintrusive.

The key differences between it and other testing libraries are:

  • Ultra light - below 10ms of compile time overhead for including the header in a source file
  • The fastest possible assertion macros - 50k asserts can compile for under 30 seconds (even under 10 sec)
  • Subcases - an intuitive way to share common setup and teardown code for test cases (alternative to fixtures)
  • Offers a way to remove everything testing-related from the binary with the DOCTEST_CONFIG_DISABLE identifier
  • Doesn't pollute the global namespace (everything is in the doctest namespace) and doesn't drag any headers with it
  • Doesn't produce any warnings even on the most aggressive warning levels for MSVC/GCC/Clang
  • Very portable and well tested C++98 - per commit tested on CI with over 220 different builds (valgrind, sanitizers...)
  • Just one header and no external dependencies apart from the C/C++ standard library

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

  • 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 or up-to-date comments - showing how an API is used
  • Testing internals that are not exposed through the public API and headers becomes easier!
  • Test-driven development in C++ has never been easier!

The library can be used like any other if you don't like the idea of mixing production code and tests - check out the features

Language Standard License Version download documentation Join the chat at https://gitter.im/onqtam/doctest Try it online

Contributing

Support the development of the project with donations! There is a list of planned features which are all important and big - see the roadmap. I took a break from working in the industry to make open source software so every cent is a big deal.

If you work for a company using doctest or have the means to do so, please consider financial support.

Pledgie Patreon PayPal

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

Documentation

Project:

Usage:

Sponsors

Want to see your name or the name of your company here? Consider donating!

⚡️ Rockstar sponsors ⚡️

💎 Gold sponsors 💎

  • Pascal Thomet

🍰 Silver sponsors 🍰

🍔 Bronze sponsors 🍔

  • Sebastien Feldis
  • Zahari Karadzhov
  • Mario Kostadinov