推荐一个单元测试库

  1. 云栖社区>
  2. 博客>
  3. 正文

推荐一个单元测试库

idealities 2019-08-14 16:56:24 浏览25397
展开阅读全文

https://github.com/catchorg/Catch2

写起来也很简单:


#define CATCH_CONFIG_MAIN
#include "catch.hpp"

unsigned int factorial( unsigned int n ) {
    return n <= 1 ? n : Factorial(n-1) * n;
}

TEST_CASE("Factorials are computed", "[factorial]" ) {
    REQUIRE( factorial(1) == 1 );
    REQUIRE( factorial(2) == 2 );
    REQUIRE( factorial(3) == 6 );
    REQUIRE( factorial(10) ==

网友评论

登录后评论
0/500
评论
idealities
+ 关注