Mirror of Catch2
Find a file
Martin Hořeňovský 74fcff6e5b
Some checks failed
Linux Builds (Bazel) / Linux Ubuntu 22.04 Bazel build <GCC 11.2.0> (push) Has been cancelled
Linux Builds (Meson) / meson clang++-11, C++14, debug (push) Has been cancelled
Linux Builds (Meson) / meson clang++-11, C++17, debug (push) Has been cancelled
Linux Builds (Meson) / meson g++-11, C++14, debug (push) Has been cancelled
Linux Builds (Meson) / meson g++-11, C++17, debug (push) Has been cancelled
Linux Builds (Meson) / meson clang++-11, C++14, release (push) Has been cancelled
Linux Builds (Meson) / meson clang++-11, C++17, release (push) Has been cancelled
Linux Builds (Meson) / meson g++-11, C++14, release (push) Has been cancelled
Linux Builds (Meson) / meson g++-11, C++17, release (push) Has been cancelled
Linux Builds (Complex) / CMake configuration tests, clang++-14, C++14 Debug (push) Has been cancelled
Linux Builds (Complex) / Extras + Examples, clang++-14, C++17 Debug (push) Has been cancelled
Linux Builds (Complex) / Extras + Examples, g++-11, C++14 Debug (push) Has been cancelled
Linux Builds (Complex) / Extras + Examples, clang++-14, C++17 Release (push) Has been cancelled
Linux Builds (Complex) / Extras + Examples, g++-11, C++14 Release (push) Has been cancelled
Linux Builds (Complex) / Surrogates build, clang++-14, C++14 Debug (push) Has been cancelled
Linux Builds (Complex) / clang-tidy (push) Has been cancelled
Linux Builds (Basic) / clang++-10, C++14, Debug (push) Has been cancelled
Linux Builds (Basic) / clang++-11, C++14, Debug (push) Has been cancelled
Linux Builds (Basic) / clang++-12, C++14, Debug (push) Has been cancelled
Linux Builds (Basic) / clang++-13, C++14, Debug (push) Has been cancelled
Linux Builds (Basic) / clang++-14, C++14, Debug (push) Has been cancelled
Linux Builds (Basic) / clang++-14, C++17, Debug (push) Has been cancelled
Linux Builds (Basic) / clang++-14, C++20, Debug (push) Has been cancelled
Linux Builds (Basic) / clang++-6.0, C++14, Debug (push) Has been cancelled
Linux Builds (Basic) / clang++-7, C++14, Debug (push) Has been cancelled
Linux Builds (Basic) / clang++-8, C++14, Debug (push) Has been cancelled
Linux Builds (Basic) / clang++-9, C++14, Debug (push) Has been cancelled
Linux Builds (Basic) / g++-10, C++14, Debug (push) Has been cancelled
Linux Builds (Basic) / g++-11, C++14, Debug (push) Has been cancelled
Linux Builds (Basic) / g++-11, C++20, Debug (push) Has been cancelled
Linux Builds (Basic) / g++-12, C++14, Debug (push) Has been cancelled
Linux Builds (Basic) / g++-7, C++14, Debug (push) Has been cancelled
Linux Builds (Basic) / g++-8, C++14, Debug (push) Has been cancelled
Linux Builds (Basic) / g++-9, C++14, Debug (push) Has been cancelled
Linux Builds (Basic) / clang++-10, C++14, Release (push) Has been cancelled
Linux Builds (Basic) / clang++-11, C++14, Release (push) Has been cancelled
Linux Builds (Basic) / clang++-12, C++14, Release (push) Has been cancelled
Linux Builds (Basic) / clang++-13, C++14, Release (push) Has been cancelled
Linux Builds (Basic) / clang++-14, C++14, Release (push) Has been cancelled
Linux Builds (Basic) / clang++-14, C++17, Release (push) Has been cancelled
Linux Builds (Basic) / clang++-14, C++20, Release (push) Has been cancelled
Linux Builds (Basic) / clang++-6.0, C++14, Release (push) Has been cancelled
Linux Builds (Basic) / clang++-7, C++14, Release (push) Has been cancelled
Linux Builds (Basic) / clang++-8, C++14, Release (push) Has been cancelled
Linux Builds (Basic) / clang++-9, C++14, Release (push) Has been cancelled
Linux Builds (Basic) / g++-10, C++14, Release (push) Has been cancelled
Linux Builds (Basic) / g++-11, C++14, Release (push) Has been cancelled
Linux Builds (Basic) / g++-11, C++20, Release (push) Has been cancelled
Linux Builds (Basic) / g++-12, C++14, Release (push) Has been cancelled
Linux Builds (Basic) / g++-7, C++14, Release (push) Has been cancelled
Linux Builds (Basic) / g++-8, C++14, Release (push) Has been cancelled
Linux Builds (Basic) / g++-9, C++14, Release (push) Has been cancelled
Mac Builds / build (Debug, macos-13, 14) (push) Has been cancelled
Mac Builds / build (Debug, macos-13, 17) (push) Has been cancelled
Mac Builds / build (Debug, macos-14, 14) (push) Has been cancelled
Mac Builds / build (Debug, macos-14, 17) (push) Has been cancelled
Mac Builds / build (Debug, macos-15, 14) (push) Has been cancelled
Mac Builds / build (Debug, macos-15, 17) (push) Has been cancelled
Mac Builds / build (Release, macos-13, 14) (push) Has been cancelled
Mac Builds / build (Release, macos-13, 17) (push) Has been cancelled
Mac Builds / build (Release, macos-14, 14) (push) Has been cancelled
Mac Builds / build (Release, macos-14, 17) (push) Has been cancelled
Mac Builds / build (Release, macos-15, 14) (push) Has been cancelled
Mac Builds / build (Release, macos-15, 17) (push) Has been cancelled
Package Manager Builds / Conan 1.63 (push) Has been cancelled
Package Manager Builds / Conan 2.1 (push) Has been cancelled
Check header guards / build (push) Has been cancelled
Windows Builds (Basic) / windows-2019, 14, Debug, Win32 (push) Has been cancelled
Windows Builds (Basic) / windows-2019, 17, Debug, Win32 (push) Has been cancelled
Windows Builds (Basic) / windows-2019, 14, Debug, x64 (push) Has been cancelled
Windows Builds (Basic) / windows-2019, 17, Debug, x64 (push) Has been cancelled
Windows Builds (Basic) / windows-2022, 14, Debug, Win32 (push) Has been cancelled
Windows Builds (Basic) / windows-2022, 17, Debug, Win32 (push) Has been cancelled
Windows Builds (Basic) / windows-2022, 14, Debug, x64 (push) Has been cancelled
Windows Builds (Basic) / windows-2022, 17, Debug, x64 (push) Has been cancelled
Windows Builds (Basic) / windows-2025, 14, Debug, Win32 (push) Has been cancelled
Windows Builds (Basic) / windows-2025, 17, Debug, Win32 (push) Has been cancelled
Windows Builds (Basic) / windows-2025, 14, Debug, x64 (push) Has been cancelled
Windows Builds (Basic) / windows-2025, 17, Debug, x64 (push) Has been cancelled
Windows Builds (Basic) / windows-2019, 14, Release, Win32 (push) Has been cancelled
Windows Builds (Basic) / windows-2019, 17, Release, Win32 (push) Has been cancelled
Windows Builds (Basic) / windows-2019, 14, Release, x64 (push) Has been cancelled
Windows Builds (Basic) / windows-2019, 17, Release, x64 (push) Has been cancelled
Windows Builds (Basic) / windows-2022, 14, Release, Win32 (push) Has been cancelled
Windows Builds (Basic) / windows-2022, 17, Release, Win32 (push) Has been cancelled
Windows Builds (Basic) / windows-2022, 14, Release, x64 (push) Has been cancelled
Windows Builds (Basic) / windows-2022, 17, Release, x64 (push) Has been cancelled
Windows Builds (Basic) / windows-2025, 14, Release, Win32 (push) Has been cancelled
Windows Builds (Basic) / windows-2025, 17, Release, Win32 (push) Has been cancelled
Windows Builds (Basic) / windows-2025, 14, Release, x64 (push) Has been cancelled
Windows Builds (Basic) / windows-2025, 17, Release, x64 (push) Has been cancelled
Use Start-BitsTransfer for downloading OpenCppCoverage instead
The old `Start-FileDownload` was no longer recognized by the pswh
version on my local machine, this updates the OpenCppCoverage install
script to use a still usable cmdlet.
2025-05-02 22:58:36 +02:00
.conan Prevent unnecessarily finding C compiler 2025-04-26 12:05:22 -06:00
.github Add VS 2025 CI jobs 2025-04-27 11:08:50 -06:00
CMake Fix formatting of CMake files 2025-04-26 10:38:36 -06:00
data/artwork Use logo with bit of white background in README 2022-11-22 16:13:37 +01:00
docs Add return code constants to API 2025-04-29 09:26:28 -06:00
examples Fix formatting of CMake files 2025-04-26 10:38:36 -06:00
extras Fix formatting of CMake files 2025-04-26 10:38:36 -06:00
fuzzing Fix formatting of CMake files 2025-04-26 10:38:36 -06:00
src Add return code constants to API 2025-04-29 09:26:28 -06:00
tests Fix typos 2025-04-26 22:46:42 -06:00
third_party fixing UB 2020-07-22 17:17:33 +02:00
tools Use Start-BitsTransfer for downloading OpenCppCoverage instead 2025-05-02 22:58:36 +02:00
.bazelrc Migrate Bazel build to use Bzlmod 2025-01-05 16:03:22 +01:00
.clang-format Slightly better clang-format 2023-01-05 23:02:51 +01:00
.clang-tidy Cleanup clang-tidy warning about enum sizes 2024-10-29 21:06:54 +01:00
.gitattributes Update gitattributes 2018-07-23 10:15:52 +02:00
.gitignore Adding unapproved.txt files to gitignore 2024-07-19 22:21:09 +02:00
appveyor.yml Update AppVeyor exclusion branch pattern for Github Actions 2024-02-23 20:52:04 +01:00
BUILD.bazel Fix typos 2025-04-26 22:46:42 -06:00
CMakeLists.txt Fix formatting of CMake files 2025-04-26 10:38:36 -06:00
CMakePresets.json Add more useful preset settings 2025-04-26 22:46:21 -06:00
CODE_OF_CONDUCT.md Create CODE_OF_CONDUCT.md 2017-08-17 07:45:12 +01:00
codecov.yml Sweep out two leftover references to master 2020-10-23 23:02:44 +02:00
conanfile.py conanfile: fix cmake_target_name of Catch2::Catch2. 2024-04-20 14:31:04 +02:00
Doxyfile Update Doxyfile for newer doxygen 2023-12-23 11:27:46 +01:00
LICENSE.txt Renamed licence file, license should now be detected by github 2017-03-20 08:59:25 +01:00
MAINTAINERS.md Add MAINTAINERS.md 2025-04-18 16:29:44 +02:00
mdsnippets.json Add infrastructure for embedding code samples in docs. 2020-10-28 11:38:06 +01:00
meson.build v3.8.1 2025-04-08 12:40:18 -06:00
meson_options.txt add meson option to not install library 2025-01-05 20:10:45 +01:00
MODULE.bazel Migrate Bazel build to use Bzlmod 2025-01-05 16:03:22 +01:00
README.md Mention that the benchmarks are not run by default next to example 2022-12-18 21:42:40 +01:00
SECURITY.md Add SECURITY.md 2021-11-26 00:10:01 +01:00

Catch2 logo

Github Releases Linux build status Linux build status MacOS build status Build Status Code Coverage Try online Join the chat in Discord: https://discord.gg/4CWS9zD

What is Catch2?

Catch2 is mainly a unit testing framework for C++, but it also provides basic micro-benchmarking features, and simple BDD macros.

Catch2's main advantage is that using it is both simple and natural. Test names do not have to be valid identifiers, assertions look like normal C++ boolean expressions, and sections provide a nice and local way to share set-up and tear-down code in tests.

Example unit test

#include <catch2/catch_test_macros.hpp>

#include <cstdint>

uint32_t factorial( uint32_t number ) {
    return number <= 1 ? number : factorial(number-1) * number;
}

TEST_CASE( "Factorials are computed", "[factorial]" ) {
    REQUIRE( factorial( 1) == 1 );
    REQUIRE( factorial( 2) == 2 );
    REQUIRE( factorial( 3) == 6 );
    REQUIRE( factorial(10) == 3'628'800 );
}

Example microbenchmark

#include <catch2/catch_test_macros.hpp>
#include <catch2/benchmark/catch_benchmark.hpp>

#include <cstdint>

uint64_t fibonacci(uint64_t number) {
    return number < 2 ? number : fibonacci(number - 1) + fibonacci(number - 2);
}

TEST_CASE("Benchmark Fibonacci", "[!benchmark]") {
    REQUIRE(fibonacci(5) == 5);

    REQUIRE(fibonacci(20) == 6'765);
    BENCHMARK("fibonacci 20") {
        return fibonacci(20);
    };

    REQUIRE(fibonacci(25) == 75'025);
    BENCHMARK("fibonacci 25") {
        return fibonacci(25);
    };
}

Note that benchmarks are not run by default, so you need to run it explicitly with the [!benchmark] tag.

Catch2 v3 has been released!

You are on the devel branch, where the v3 version is being developed. v3 brings a bunch of significant changes, the big one being that Catch2 is no longer a single-header library. Catch2 now behaves as a normal library, with multiple headers and separately compiled implementation.

The documentation is slowly being updated to take these changes into account, but this work is currently still ongoing.

For migrating from the v2 releases to v3, you should look at our documentation. It provides a simple guidelines on getting started, and collects most common migration problems.

For the previous major version of Catch2 look into the v2.x branch here on GitHub.

How to use it

This documentation comprises these three parts:

More