Asserting with Catch2
Unlike other testing frameworks, Catch2 does not provide a large set of assertion macros. It has two main macros: REQUIRE
, which produces a fatal error, stopping the execution of the test case upon failure, and CHECK
, which produces a non-fatal error upon failure, continuing the execution of the test case. Several additional macros are defined; in this recipe, we will see how to put them to work.
Getting ready
You should now be familiar with writing test cases and test functions using Catch2, a topic we covered in the previous recipe, Writing and invoking tests with Catch2.
How to do it...
The following list contains the available options for asserting with the Catch2 framework:
- Use
CHECK(expr)
to check whetherexpr
evaluates totrue
, continuing the execution in case of failure, andREQUIRE(expr)
to make sure thatexpr
evaluates totrue
, stopping the execution of the test in case of failure:int a = 42; CHECK(a == 42); REQUIRE...