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$ 
  • 相关阅读:
    统计MySQL数据库硬盘占用量大小
    zookeeper 集群安装与配置
    On Java 8中文版 英雄召集令
    下划线参数转成驼峰
    在Ubuntu 18.04中安装JDK 8
    GIT和GitHub的使用总结
    Python目录
    selenium代码实例
    Fiddler请求图标含义
    Tensorflow之神经网络
  • 原文地址:https://www.cnblogs.com/zengjfgit/p/5455110.html
Copyright © 2011-2022 走看看