Unit testing Cmockery 简单使用

简介: /********************************************************************** * Unit testing Cmockery 简单使用 * 说明: * 之前早有听说过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$ 

 

目录
打赏
0
0
0
0
12
分享
相关文章
pytest学习和使用22-allure特性 丨总览中的Environment、Categories设置以及Flaky test使用
pytest学习和使用22-allure特性 丨总览中的Environment、Categories设置以及Flaky test使用
169 0
Robot Framework(14)- Variables 表的详细使用和具体例子
Robot Framework(14)- Variables 表的详细使用和具体例子
278 0
Robot Framework(14)- Variables 表的详细使用和具体例子