<a id="top"></a>

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.
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.
This documentation comprises these three parts:


多风格AI绘画神器
堆友平台由阿里巴巴设计团队创建,作为一款AI驱动的设计工具,专为设计师提供一站式增长服务。功能覆盖海量3D素材、AI绘画、实时渲染以及专业抠图,显著提升设计品质和效率。平台不仅提供工具,还是一个促进创意交流和个人发展的空间,界面友好,适合所有级别的设计师和创意工作者。


零代码AI应用开发平台
零代码AI应用开发平台,用户只需一句话简单描述需求,AI能自动生成小程序、APP或H5网页应用,无需编写代码。


免费创建高清无水印Sora视频
Vora是一个免费创建高清无水印Sora视频的AI工具


最适合小白的AI自动化工作流平台
无需编码,轻松生成可复用、可变现的AI自动化工作流
