CheckOps home

Tools directory

C

CheckOps

Catch2

Catch2 is a BSL-1.0 C++ unit testing framework with natural assertions, free-form test names, sections for shared setup, BDD-style macros and built-in micro-benchmarking.

Visit website

Latest public signals

Not refreshed yet. Refresh reads the public site and, when the entry has a GitHub repository, the latest release.

Visit Website

Introduction

Catch2 is mainly a unit testing framework for C++, but its README notes that it also provides basic micro-benchmarking features and simple BDD macros. Its main advantage, according to the project, is that it is simple and natural to use: test names do not have to be valid identifiers, assertions look like normal C++ boolean expressions, and sections provide a local way to share setup and teardown code.

The project is licensed under the Boost Software License 1.0 and has about 21,600 GitHub stars. Catch2 v3 changed the distribution model from the original single header to a conventional library with multiple headers, which greatly improves compile times; projects include only the headers they need, such as catch2/catch_test_macros.hpp. Version 3.16.1 was released on 8 October 2026.

Assertions use REQUIRE (stop the test on failure) and CHECK (continue), and Catch2 decomposes expressions so a failure such as REQUIRE(factorial(10) == 3628800) prints both sides. Sections let several related paths share the same setup: each SECTION runs from the top of the test case independently, which avoids fixture classes for many cases.

Beyond basics, Catch2 offers generators for data-driven tests (GENERATE), matchers for strings, floating point, ranges and exceptions, tags for organising and filtering tests, templated test cases, and reporters including console, JUnit, XML, TeamCity and SonarQube formats. The BENCHMARK macro provides statistically analysed micro-benchmarks inside the same test binary.

How it compares: GoogleTest offers more structure and the GoogleMock mocking library, while Catch2 focuses on low-ceremony, readable tests and has no built-in mocking (teams pair it with libraries such as trompeloeil or FakeIt). doctest borrows Catch’s style with an emphasis on extremely fast compile times. Catch2 integrates with CMake and CTest through catch_discover_tests.

In the quality loop, Catch2 serves unit tests and simple benchmarks for C++ libraries, games, tools and embedded-adjacent code.

The source code is at catchorg/Catch2 on GitHub under the BSL-1.0 licence, with about 21,600 stars; the most recent commit was on 30 October 2026.

Catch2 ships several reporters, including JUnit and XML formats, so results can feed CI dashboards. Its micro-benchmarking support is deliberately opt-in: per the README, benchmarks are not run by default and must be selected explicitly with the [!benchmark] tag, which keeps ordinary test runs fast. The project maintains a migration guide for moving from v2 to v3, because v3 is no longer a single-header library and instead behaves as a normal library with separately compiled parts, which improves compile times for large suites.

Catch2 is distributed under the Boost Software License 1.0, a permissive licence that allows use in commercial and closed-source projects without attribution requirements in binaries.

Features

  1. Natural assertions: REQUIRE(a == b) and CHECK(...) print expanded values on failure.
  2. Free-form test names: Describe tests in plain sentences with tags such as [parser][slow].
  3. Sections: Share setup between related paths without fixture classes.
  4. BDD macros: SCENARIO, GIVEN, WHEN and THEN for behaviour-style tests.
  5. Generators: GENERATE produces data-driven test cases inline.
  6. Matchers: String, floating-point, range, vector and exception matchers, plus custom matchers.
  7. Micro-benchmarks: BENCHMARK blocks with statistical analysis.
  8. Reporters: Console, JUnit, XML, TeamCity, SonarQube and more for CI.

Pros

  1. Very readable tests: Low ceremony makes tests easy to write and review.
  2. Faster builds in v3: The multi-header library avoids recompiling the framework for every test file.
  3. Free to use: Open source under the BSL-1.0 licence, so the core tool costs nothing to use.
  4. Actively maintained: The repository had commits as recent as 30 October 2026.
  5. Community: About 21,600 GitHub stars.

Cons

  1. No built-in mocking: Requires a separate mocking library.
  2. v2 to v3 migration: Header and build changes are needed when upgrading from the single-header v2.
  3. Sections can confuse newcomers: The re-execution model of sections takes a moment to understand.
  4. Benchmarks are basic: Serious performance work may need a dedicated benchmarking library.

Add Catch2 with CMake:

include(FetchContent)
FetchContent_Declare(Catch2 GIT_REPOSITORY https://github.com/catchorg/Catch2.git GIT_TAG v3.16.1)
FetchContent_MakeAvailable(Catch2)
add_executable(tests test_stack.cpp)
target_link_libraries(tests PRIVATE Catch2::Catch2WithMain)
include(Catch)
catch_discover_tests(tests)

Tests with sections and a generator:

#include <catch2/catch_test_macros.hpp>
#include <catch2/generators/catch_generators.hpp>
#include <vector>

TEST_CASE("vectors can grow and shrink", "[vector]") {
    std::vector<int> v(5);
    REQUIRE(v.size() == 5);

    SECTION("pushing increases size") {
        v.push_back(1);
        CHECK(v.size() == 6);
    }
    SECTION("clearing empties it") {
        v.clear();
        CHECK(v.empty());
    }
}

TEST_CASE("absolute value is never negative") {
    int x = GENERATE(-3, 0, 7);
    CHECK(std::abs(x) >= 0);
}

Run a subset by tag and produce JUnit XML:

./tests "[vector]" --reporter junit --out results.xml

Practical tips: tag slow tests and exclude them by default with ~[slow], and use CHECK for independent assertions so one run reports every failure.

Resources:

Pricing

Catch2 is free and open source under the BSL-1.0 licence.

  1. C++ developers who want readable, low-ceremony unit tests.
  2. Library authors needing simple CMake integration and CI reporters.
  3. Teams wanting quick micro-benchmarks next to their tests.
  4. Not a fit if you need integrated mocking out of the box; GoogleTest with GoogleMock covers that.

Conclusion

Catch2 makes C++ tests pleasant to write: natural assertions, descriptive names and sections keep tests short and readable.

With v3’s faster multi-header design, generators, matchers and benchmarks, it is a strong alternative to GoogleTest for most C++ projects.

Compare

CheckOps pages that put Catch2 next to related tools. There is no paid placement on these lists.

Alternatives

Other tools on CheckOps that cover similar ground. Open a page, or compare one with Catch2 side by side.