Testing with Catch2

C++ Automated Test Cases in a Header - Catch2 - is a C++ test framework with support for C and Objective-C distributed as a single header file.

Catch2 is extremely portable with no external dependencies.

mytest.cc010-TestCase.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
#define CATCH_CONFIG_MAIN  // This tells Catch to provide a main() - only do this in one cpp file
#include "catch.hpp"

unsigned int Factorial( unsigned int 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) == 3628800 );
}
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×