C++ 迷你单元测试和性能测试库:cc-mini-test

jopen 10年前

cc-mini-test 是 C++ 迷你单元测试和性能测试库。

基本用法:

#include "test.h"    int Sum(int a, int b) {   return a+b;  }    TEST(Sum, Simple) {   ASSERT_TRUE(Sum(1,2) == 3);  }    TEST(Sum, For) {   for(int i = 0; i < 10; ++i) {    ASSERT_TRUE_MSG(Sum(i,i) == i*2, "i = %d", i);   }  }

性能测试:

BENCH(Sum, For500) {      for(int i = 0; i < BenchN(); ++i) {          for(int j = 0; j < 500; ++j) {              Sum(i, i);          }      }  }    BENCH(Sum, For1000) {      for(int i = 0; i < BenchN(); ++i) {          for(int j = 0; j < 1000; ++j) {              Sum(i, i);          }      }  }

运行性能测试: a.exe -test.bench

其他命令行参数:

./a.out -help  usage: a.out    [-list=*.]    [-test=*.]    [-test.bench=]    [-test.benchtime=1second]    [-help]    [-h]

项目主页:http://www.open-open.com/lib/view/home/1396357209622