doctest - 最轻的特性丰富的C++单个header的测试框架
doctest - 最轻的特性丰富的C++单个header的测试框架
C/C++ 测试工具
共2794Star
详细介绍
The lightest feature-rich C++98/C++11 single-header testing framework for unit tests and TDD
master branch | Linux/OSX |
Windows |
||
---|---|---|---|---|
dev branch | Linux/OSX |
Windows |
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.
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:
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 library 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
- Tests can be shipped to the customer with the software to diagnose a bug faster
- 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
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.
Contributions in the form of issues and pull requests are welcome as well - check out the Contributing page.
Documentation
Project:
- Features and design goals - the complete list of features
- Roadmap - upcoming features
- Benchmarks - compile-time 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
- Command line
main()
entry point- Configuration
- String conversions
- FAQ
- Examples
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
?
- Zahari Karadzhov
- Mario Kostadinov