c++ 单元测试框架Catch2

官方教程有三种方式


方式1 如下


第一步:获取 Catch2,下载 catch.hpp

第二步:引入头文件

#include "catch.hpp"

第三步:写测试代码

#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 );
}

第四步:编译

这里我的代码文件结构如下:
c++ 单元测试框架Catch2
编译命令:

g++ -std=c++11 -o 010-TestCase 010-TestCase.cpp

第五步:执行

结果如下
c++ 单元测试框架Catch2

参考:
Catch2单元测试框架

<<< 未完待续