redriver 发表于 2012-3-8 12:15:37

推荐一个开源的单元测试framework——CPPUtest

不知道大家在开发嵌入式软件时,做不做单元测试?教课书上单元测试是用来方便以后修改的,但是个人觉得还是用来发现bug的。CPPUtest可以用于嵌入式,
如果你的代码是C写的。

一些纯逻辑性的代码,是非常适合用来做单元测试的,比如文件系统(需要抛掉IO,如何隔离开IO,取决于你的设计),UI框架,嵌入式OS的内存管理模块等。

链接:
http://sourceforge.net/projects/cpputest/
介绍:
CppUTest is a unit testing framework. Its main goal is to provide a simple unit testing framework that can also work well with embedded systems. It also provides support for working with C.

exilefox 发表于 2012-3-8 12:37:37

是做什么用的丫,感觉软件工程好复杂啊~

ljt80158015 发表于 2012-3-8 12:53:45

还能举个例子啊!~

redriver 发表于 2012-3-8 16:42:10

例子回去找一个,基于VC6.0和GCC的都有。
顺便推荐一本书,Test.Driven.Development.for.Embedded.C,貌似已经有中文版了。


嵌入式系统的TDDourdev_724960KOQ5IT.zip(文件大小:7.48M) (原文件名:Pragmatic.Test.Driven.Development.for.Embedded.C.Apr.2011.zip)

redriver 发表于 2012-3-24 18:09:02

附件里是Test.Driven.Development.for.Embedded.C附书的代码。
解压或,如果是是使用VC,那么先要把测试的框架代码CPPUtest先编译一下,代码在CPPUtest子目录下,打开CppUTest.dsw,然后直接编译,
会在lib子目录下产生一个名为CPPUtest.lib的静态库,这个静态库的头文件在include\CppUTest目录下。

样例代码,打开BookCode.dsw,里面包含两个工程,一个是产品代码(被测代码),另外一个是测试代码。在编译时,会提示sdtint.h以及CPPUtest的一些头文件找不到,此时要在Tools->Options\Dirrectories设置头文件搜索目录,一个是在\CppUTest\include\Platforms\VisualCpp下,一个是在\CppUTest\include。

引入单元测试,个人感觉意义如下:

1. 相当于写两遍自己的代码,从而发现自己代码的bug;
2. 为以后的修改(比如增加功能,重构代码),提供方便;
3. 方便代码的回归测试。在一个模块改动后,判断是否会对整个项目有影响,可以跑一下单元测试,保证没有问题。


xy-mcu 发表于 2012-8-6 20:18:47

谢谢推荐,刚刚买了这本书,想到http://sourceforge.net/去,结果发现上不到。----难道又是伟大的强
还好LZ 这里有啊。谢谢。

bailang326 发表于 2013-4-9 16:36:24

hi, BookCode.dsw工程里面编译通不过呢,下面是现象。能否再上传些CPPUTEST的笔记,文档呢

--------------------Configuration: AllTests_CppUTest - Win32 Debug--------------------
Linking...
LINK : fatal error LNK1104: cannot open file "\lib\cpputest.lib"
Ö´ÐÐ link.exe ʱ³ö´í.

AllTests_CppUTest.exe - 1 error(s), 0 warning(s)
The following environment variables were not found
$(CPP_U_TEST)

mhw 发表于 2013-4-9 17:26:50

MARK………

rayman_ppx 发表于 2013-4-9 17:45:22

MARK………

mhw 发表于 2013-4-9 17:50:12

要学会看readme:
-----------------------
For visual studio users
-----------------------
        There are Visual C/C++ workspace files for working with CppUTest.
        Before opening Visual Studio, create this environment variable
                CPP_U_TEST=<BookCodeParent>/code/CppUTest

        If you are using a later version of Visual Studio, you can let your version
        convert the workspace and project files.

        Start by building CppUTest in VS. CppUTest has some Visual Studio solution files
        for later version. You can use either sln or dsw files to get CppUTest built.

        Build only for 'Debug'. 'Release' is not supported for any of the projects.

        For each of the book's workspaces, open the dsw file (let later versions of
        VS convert). Build and run without debug.You will get the command window
        to linger after the test run if you run without debug.To keep feedback fast,
        get used to using control-F5 to save all, build and run the tests.
       
        If you did not define the CPP_U_TEST environment variable correctly you will get
        compilation errors about not finding CppUTest include files
       
        These are the Visual Studio workspace files:
          <BookCodeParent>/code/BookCode.dsw
          <BookCodeParent>/code/SandBox/SandBox.dsw
                <BookCodeParent>/code/t0
                <BookCodeParent>/code/t1
                <BookCodeParent>/code/t2
                <BookCodeParent>/code/t3

To build a specific code project from the command line
    cd <BookCodeParent>/code]
    make

mhw 发表于 2013-4-9 17:51:29

在我的电脑-》属性-》高级-》环境变量,手动添加一个“CPP_U_TEST”就可以编译了。

stopfan 发表于 2013-5-13 11:58:03

ljt80158015 发表于 2012-3-8 12:53 static/image/common/back.gif
还能举个例子啊!~

兄弟能否加我一下QQ 7914703

SCoco 发表于 2014-6-23 09:28:41

牛逼,mark一下,正好有这方面的需求

redriver 发表于 2014-10-19 13:51:32

这种测试框架越来越多了,比如google test。
http://code.google.com/p/googletest/

文档:
http://code.google.com/p/googletest/wiki/GoogleTestPrimer
http://code.google.com/p/googletest/wiki/GoogleTestAdvancedGuide

zw_7627 发表于 2019-8-3 00:14:26

redriver 发表于 2014-10-19 13:51
这种测试框架越来越多了,比如google test。
http://code.google.com/p/googletest/



最下面的两个链接打开后,变成第一个链接地址了。文档看不到。。。

shian0551 发表于 2019-8-3 09:26:10

本帖最后由 shian0551 于 2019-8-3 09:27 编辑













中文版本

zzhang_hui 发表于 2019-8-3 13:48:29

谢谢,看看书先
页: [1]
查看完整版本: 推荐一个开源的单元测试framework——CPPUtest