Skip to content

Catch2

Snippet fetch_catch2 not found in snippets/tests/CMakeLists.txt


1
2
add_executable(unit_tests_catch unit_tests_catch.cpp)
target_link_libraries(unit_tests_catch PRIVATE Catch2::Catch2)

1
2
#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>

1
2
3
TEST_CASE("Factorial of 0 is 1 (fail)", "[single-file]") {
    REQUIRE(Factorial(0) == 1);
}

1
2
3
4
5
6
TEST_CASE("Factorials of 1 and higher are computed (pass)", "[single-file]") {
    REQUIRE(Factorial(1) == 1);
    REQUIRE(Factorial(2) == 2);
    REQUIRE(Factorial(3) == 6);
    REQUIRE(Factorial(10) == 3628800);
}

Share Snippets