把这个catch.hpp文件,引入到自己的工程即可。catch测试框架,仅仅这一个catch.hpp文件即可。
例子:
https://blog.csdn.net/qq_24889575/article/details/82873379
把catch.hpp文件加到头文件里面
在新建的cpp文件中不用在写main函数头
#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 );
}
如果使用自己写main函数时
**//#define CATCH_CONFIG_MAIN //定义后直接使用catch自带的main()函数
#ifdef CATCH_CONFIG_MAIN
#include "catch.hpp"
#else
#define CATCH_CONFIG_RUNNER //使用自己写的mian()函数
https://www.cnblogs.com/sxy-798013203/p/7634728.html