linux 下单元测试框架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 );
}
第四步:编译

这里我的代码文件结构如下:
example010
编译命令:

g++ -std=c++11 -o 010-TestCase 010-TestCase.cpp
第五步:执行

结果如下
在这里插入图片描述

参考:
Catch2单元测试框架
C++ 的单元测试工具 —— Catch

<<< 未完待续

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值