参见:http://cpputest.github.io/
1. CppUTest是一个C/C++单元测试框架,可以在C/C++项目中使命。
2. 第一个测试
新建一个cpp 文件,包含一个TEST_GROUP 和一个 TEST。下面的例子表明测试结果是失败。
1 #include "CppUTest/TestHarness.h" 2 int main(int ac, char** av) 3 { 4 //运行所有的单元测试 5 return CommandLineTestRunner::RunAllTests(ac, av); 6 } 7 8 TEST_GROUP(FirstTestGroup) 9 { 10 }; 11 12 TEST(FirstTestGroup, FirstTest) 13 { 14 FAIL("Fail me!"); 15 } 16 17 TEST(FirstTestGroup, SecondTest) 18 {//向FirstTestGroup中再增加一个测试 19 STRCMP_EQUAL("hello", "world"); 20 LONGS_EQUAL(1, 2); 21 CHECK(false); 22 }