Catch2 is a testing framework built specifically for C++, aimed at developers who want unit tests, TDD workflows, or BDD-style specs without pulling in a heavy dependency chain. Test names don't need to be valid identifiers, assertions read like normal boolean expressions, and sections let you share setup and teardown code locally inside a test case. It's a good fit for teams writing C++14 or later who want a test runner that feels natural to write in, rather than one bolted on from another language's testing conventions.
REQUIRE and CHECK macros wrap ordinary C++ boolean expressions, so you don't learn a separate assertion DSL.GIVEN, WHEN, THEN style macros for teams that prefer behavior-driven test structure.BENCHMARK macro for simple performance measurement inside test cases, opt-in via a [!benchmark] tag.Catch2 fits projects already written in C++14 or newer that need a straightforward unit testing setup, whether that's a small library, an application, or a larger codebase migrating off an older or custom test harness. It works well for teams that want readable test output and don't want to write custom fixture classes for every shared setup step. The BDD macros make it a reasonable choice for teams that already think in given/when/then terms, and the benchmarking macros are useful for quick, in-tree performance checks without adding a separate benchmarking tool.
It's not the right choice if you're stuck on C++11, since that support only exists in the older v2 branch. If you need a dedicated, statistically rigorous benchmarking tool, Catch2's built-in benchmarks are convenient but not a replacement for something purpose-built like Google Benchmark. Projects that specifically want a single-header drop-in (no build step) should stay on v2, since v3 is a compiled library.
Catch2 v3 is distributed as a library rather than a single header, so it needs to be built and linked rather than just included. The common approach is to pull it in with CMake's FetchContent:
Include(FetchContent)
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.x)
FetchContent_MakeAvailable(Catch2)
target_link_libraries(tests PRIVATE Catch2::Catch2WithMain)
Alternatively, if Catch2 is already installed on the system (via a package manager or manual build/install), use find_package:
find_package(Catch2 3 REQUIRED)
target_link_libraries(tests PRIVATE Catch2::Catch2WithMain)
A basic test file looks like this:
#include <catch2/catch_test_macros.hpp>
TEST_CASE("Factorials are computed", "[factorial]") {
REQUIRE(factorial(1) == 1);
}
If you're migrating an existing project from Catch2 v2, check the migration guide in the docs folder first, since the switch from single-header to library changes include paths and build setup. For teams that need C++11 support, use the v2.x branch instead of devel.