官方教程有三种方式


方式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单元测试框架

<<< 未完待续

相关文章:

  • 2022-12-23
  • 2021-08-18
  • 2022-03-10
  • 2021-11-25
  • 2021-05-11
  • 2021-08-02
  • 2021-09-22
  • 2021-06-17
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-06
  • 2021-12-22
  • 2022-01-02
相关资源
相似解决方案