#define CATCH_CONFIG_MAIN
#include "catch.hpp"
int add_(int a, int b) {
return a+b;
}
TEST_CASE("add 3 and 4 is 7(success)", "anything"){
REQUIRE(add_(3, 4)==7);
}
g++ first.cpp catch.hpp -std=c++14
运行
$ ./a.out
[1/1] (100%): add 3 and 4 is 7(success)
===============================================================================
All tests passed (1 assertion in 1 test case)
#include <catch2/benchmark/catch_benchmark.hpp>
#include <catch2/catch_test_macros.hpp>
#include <catch2/generators/catch_generators.hpp>
TEST_CASE("Fibonacci") {
BENCHMARK("Fibonacci 35") {
return Fibonacci(35);
};
}
cd Catch2 && mkdir build && cd build
cmake -DCMAKE_INSTALL_PREFIX=/your/install/path ..
make -j 8
make install
include_directories(/Users/yaojun/MyInstall/catch_install/include)
FIND_LIBRARY(CATCH2_LIBS Catch2 /Users/yaojun/MyInstall/catch_install/lib NO_DEFAULT_PATH)
FIND_LIBRARY(CATCH2MAIN_LIBS Catch2Main /Users/yaojun/MyInstall/catch_install/lib NO_DEFAULT_PATH)
add_executable(catch_v3 hello.cpp)
target_link_libraries(catch_v3 ${CATCH2_LIBS} ${CATCH2MAIN_LIBS})
#include <catch2/catch_test_macros.hpp>
static int Factorial( int number ) {
return number <= 1 ? 1 : Factorial( number - 1 ) * number; // pass
}
TEST_CASE( "Factorial of 0 is 1 (fail)", "[single-file]" ) {
REQUIRE( Factorial(0) == 1 );
}