之前早有听说过Cmockery,但一直没有使用起来,主要是也不知道用来做什么,当然现在其实也不知道用来做什么,不过还是想编译一下,看下效果,然后搞了一个最简单的测试程序看一下效果。
/**********************************************************************
* Unit testing Cmockery 简单使用
* 说明:
* 之前早有听说过Cmockery,但一直没有使用起来,主要是也不知道用来做
* 什么,当然现在其实也不知道用来做什么,不过还是想编译一下,看下效果,
* 然后搞了一个最简单的测试程序看一下效果。
*
* 2016-5-3 深圳 南山平山村 曾剑锋
*********************************************************************/
一、参考文章:
C单元测试框架之Cmockery
http://c4fun.cn/blog/2014/12/06/cmockery/
二、编译:
1. ./configure
2. make
3. sudo make install
4. sudo ldconfig
三、Demo Test:
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include "cmockery.h" // 注意头文件所在的位置
void testFunction(void **state) {
printf("zengjf.\n");
}
int main(int argc, char *argv[])
{
const UnitTest tests[] = {
unit_test(testFunction),
};
return run_tests(tests);
}
四、测试结果:
myzr@myzr:~/c_program$ ./a.out
testFunction: Starting test
zengjf.
testFunction: Test completed successfully.
All 1 tests passed
myzr@myzr:~/c_program$