catch2/docs/why-catch.md

58 lines
2.9 KiB
Markdown
Raw Normal View History

2017-08-24 15:21:36 +02:00
<a id="top"></a>
2013-06-07 22:31:28 +02:00
# Why do we need yet another C++ test framework?
2017-08-17 09:28:45 +02:00
Good question. For C++ there are quite a number of established frameworks,
including (but not limited to),
[Google Test](http://code.google.com/p/googletest/),
[Boost.Test](http://www.boost.org/doc/libs/1_49_0/libs/test/doc/html/index.html),
[CppUnit](http://sourceforge.net/apps/mediawiki/cppunit/index.php?title=Main_Page),
2021-08-07 21:56:17 +02:00
[Cute](http://www.cute-test.com), and
2017-08-17 09:28:45 +02:00
[many, many more](http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks#C.2B.2B).
2013-06-07 20:09:38 +02:00
2021-08-07 21:56:17 +02:00
So what does Catch2 bring to the party that differentiates it from these? Apart from the catchy name, of course.
2013-06-07 20:09:38 +02:00
## Key Features
2021-08-07 21:56:17 +02:00
* Quick and easy to get started. Just download two files, add them into your project and you're away.
* No external dependencies. As long as you can compile C++14 and have the C++ standard library available.
2017-06-27 12:39:02 +02:00
* Write test cases as, self-registering, functions (or methods, if you prefer).
* Divide test cases into sections, each of which is run in isolation (eliminates the need for fixtures).
* Use BDD-style Given-When-Then sections as well as traditional unit test cases.
2013-06-07 22:31:28 +02:00
* Only one core assertion macro for comparisons. Standard C/C++ operators are used for the comparison - yet the full expression is decomposed and lhs and rhs values are logged.
2017-06-27 12:39:02 +02:00
* Tests are named using free-form strings - no more couching names in legal identifiers.
2013-06-07 20:09:38 +02:00
2021-08-07 21:56:17 +02:00
2013-06-07 20:09:38 +02:00
## Other core features
* Tests can be tagged for easily running ad-hoc groups of tests.
2021-08-07 21:56:17 +02:00
* Failures can (optionally) break into the debugger on common platforms.
2013-06-07 20:09:38 +02:00
* Output is through modular reporter objects. Basic textual and XML reporters are included. Custom reporters can easily be added.
* JUnit xml output is supported for integration with third-party tools, such as CI servers.
2017-06-27 12:39:02 +02:00
* A default main() function is provided, but you can supply your own for complete control (e.g. integration into your own test runner GUI).
2013-06-07 20:09:38 +02:00
* A command line parser is provided and can still be used if you choose to provided your own main() function.
* Alternative assertion macro(s) report failures but don't abort the test case
2021-08-07 21:56:17 +02:00
* Good set of facilities for floating point comparisons (`Catch::Approx` and full set of matchers)
2013-06-07 20:09:38 +02:00
* Internal and friendly macros are isolated so name clashes can be managed
2021-08-07 21:56:17 +02:00
* Data generators (data driven test support)
* Hamcrest-style Matchers for testing complex properties
* Microbenchmarking support
2013-06-07 20:09:38 +02:00
2021-08-07 21:56:17 +02:00
## Who else is using Catch2?
2022-09-09 16:00:39 +02:00
A whole lot of people. According to the 2021 JetBrains C++ ecosystem survey,
2021-08-07 21:56:17 +02:00
about 11% of C++ programmers use Catch2 for unit testing, making it the
second most popular unit testing framework.
You can also take a look at the (incomplete) list of [open source projects](opensource-users.md#top)
or the (very incomplete) list of [commercial users of Catch2](commercial-users.md#top)
for some idea on who else also uses Catch2.
---
2021-08-07 21:56:17 +02:00
See the [tutorial](tutorial.md#top) to get more of a taste of using
Catch2 in practice.
2013-06-07 20:09:38 +02:00