zoukankan      html  css  js  c++  java
  • Unit testing 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.
    ");
        }
    
        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$ 
  • 相关阅读:
    快速排序
    优先队列
    堆排序
    树、二叉树基础
    分治法
    递归算法详细分析
    算法基础
    Linux文件系统详解
    fs/ext2/inode.c相关函数注释
    块设备的读流程分析
  • 原文地址:https://www.cnblogs.com/zengjfgit/p/5455110.html
Copyright © 2011-2022 走看看