doctest - 最轻的特性丰富的C++单个header的测试框架

网友投稿 930 2022-10-31

doctest - 最轻的特性丰富的C++单个header的测试框架

doctest - 最轻的特性丰富的C++单个header的测试框架

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

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 fileThe 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 identifierDoesn't pollute the global namespace (everything is in the doctest namespace) and doesn't drag any headers with itDoesn't produce any warnings even on the most aggressive warning levels for MSVC/GCC/ClangVery 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 usedTests can be shipped to the customer with the software to diagnose a bug fasterTest-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 featuresRoadmap - upcoming featuresBenchmarks - compile-time supremacyContributing - how to make a proper pull requestChangelog - generated changelog based on closed issues/PRs

Usage:

Tutorial - make sure you have read it before the other parts of the documentationAssertion macrosTest cases, subcases and test fixturesCommand linemain() entry pointConfigurationString conversionsFAQExamples

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 KaradzhovMario Kostadinov

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Litho: 一个声明式框架用于在Android上构建高效UI
下一篇:PlotOptiX:基于NVIDIA OptiX光线跟踪框架的Python数据可视化
相关文章

 发表评论

暂时没有评论,来抢沙发吧~