C语言单元测试框架

    xiaoxiao2025-02-25  50

     

    一、Google Test

    gtest是一个跨平台的(Liunx、Mac OS X、Windows、Cygwin、Windows CE and Symbian)C++单元测试框架,由google公司发布。gtest是为在不同平台上为编写C++测试而生成的。它提供了丰富的断言、致命和非致命判断、参数化、”死亡测试”等等。

    //编译升级到设备中去。

    可以参考的网址:

    1、使用说明翻译

    https://www.cnblogs.com/jycboy/p/6057677.html

    2、在嵌入式设备上的使用

    https://www.cnblogs.com/StitchSun/p/4430362.html

    二、CUnit

    1、继Junit CppUnit的成功后, c语言环境下也出现了开放源码的白盒测试用例CUnit。CUnit以静态库的形式提供给用户使用,用户编写程序的时候直接链接此静态库就可以了。它提供了一个简单的单元测试框架,并且为常用的数据类型提供了丰富的断言语句支持。

    2、静态测试,方便操作。

    3、CUnit可以结合gcov lcov等使用

    4、可以看出Cunit也是有组织的,呵呵,主要分几个角色,Registry,Suite及Test方法。可以通过下面例子,体会到这种组织关系。 按官方文档说明,使用Cunit的主要步骤有: 1) Write functions for tests (and suite init/cleanup if necessary).  2) Initialize the test registry - CU_initialize_registry()  3) Add suites to the test registry - CU_add_suite()  4) Add tests to the suites - CU_add_test()  5) Run tests using an appropriate interface, e.g. CU_console_run_tests  6) Cleanup the test registry - CU_cleanup_registry

    5、可以参考的网址:

    https://www.jianshu.com/p/b0bffd44d2c9

    https://blog.csdn.net/qq_31385393/article/details/79468857

    网址主页:http://cunit.sourceforge.net/

    三、读书《测试驱动的嵌入式C语言开发》

    第二章

    1、在C语言要把测试做到面面俱到很难。

    2、CUnit和CppUTest

    3、测试的四阶段,这种模式的目的是为了创建一个明确、可读并且结构良好的测试,分别是建立:对测试的前置条件,运行:对系统进行操作,验证:检查预期的输出,拆卸:把测试系统恢复到测试前的初始状态。

    最新回复(0)