Skip to content
Permalink
devel
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
5 contributors

Users who have contributed to this file

@philsquared @martinmoene @tocic @horenmar @antonioborondo

Why do we need yet another C++ test framework?

Good question. For C++ there are quite a number of established frameworks, including (but not limited to), Google Test, Boost.Test, CppUnit, Cute, and many, many more.

So what does Catch2 bring to the party that differentiates it from these? Apart from the catchy name, of course.

Key Features

  • 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.
  • 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.
  • 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.
  • Tests are named using free-form strings - no more couching names in legal identifiers.

Other core features

  • Tests can be tagged for easily running ad-hoc groups of tests.
  • Failures can (optionally) break into the debugger on common platforms.
  • 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.
  • A default main() function is provided, but you can supply your own for complete control (e.g. integration into your own test runner GUI).
  • 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
  • Good set of facilities for floating point comparisons (Catch::Approx and full set of matchers)
  • Internal and friendly macros are isolated so name clashes can be managed
  • Data generators (data driven test support)
  • Hamcrest-style Matchers for testing complex properties
  • Microbenchmarking support

Who else is using Catch2?

A whole lot of people. According to the 2021 JetBrains C++ ecosystem survey, 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 or the (very incomplete) list of commercial users of Catch2 for some idea on who else also uses Catch2.


See the tutorial to get more of a taste of using Catch2 in practice.


Home