您的位置:首页 > 编程语言 > C语言/C++

c语言实现一个单元测试框架(Unit Test Framework)

2012-03-22 18:59 525 查看
csdn lidp  转载注明出处

此单元测试框架为我在google code上的开源项目spider-tool的一部分,

关于spider-tool,欢迎访问google code. 
https://spider-tool.googlecode.com
单元测试框架接口应尽量简单并提供必要的功能,使用步骤:

1. 注册单元测试函数到测试框架

2. 运行测试框架

3.生成单元测试统计信息(通过测试条数,失败测试条数,每条测试的执行时间,总时间,测试失败的代码位置)

4  从测试框架注销单元测试函数

对应接口函数:

/* 声明单元测试函数,name 为函数名,隐藏框架细节 */

SPD_TEST_INIT(name);

/* 注册单元测试函数到测试框架 name为函数名 */

SPD_TEST_REGISTER(name);

 /* 

  * run test framework  in three mode :

  * name : run given name test case, may be NULL 

  * category : run a class of test of given category , may be NULL

  * if both name and category is NULL , will run all registered test case.

  */

SPD_TEST_RUN(name,category);

/* 产生测试报告,可以输出单个/一组/全部用力到文件filepath*/

SPD_TEST_REPORT(name, category, filepath);

/* 从框架中注销测试函数 */

SPD_TEST_UNREGISTER(name);

四个对外接口例子:

test_db为要编写的测试函数,统计测试结果到spddb_test文件

SPD_TEST_REGISTER(test_db);

SPD_TEST_RUN("test_db",NULL);

SPD_TEST_REPORT("test_db", NULL, "/tmp/spddb_test");

SPD_TEST_UNREGISTER(test_db);

后续附上代码。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐