搜索
bottom↓
回复: 16

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

[复制链接]

出0入0汤圆

发表于 2012-3-8 12:15:37 | 显示全部楼层 |阅读模式
不知道大家在开发嵌入式软件时,做不做单元测试?教课书上单元测试是用来方便以后修改的,但是个人觉得还是用来发现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.

出0入0汤圆

发表于 2012-3-8 12:37:37 | 显示全部楼层
是做什么用的丫,感觉软件工程好复杂啊~

出0入0汤圆

发表于 2012-3-8 12:53:45 | 显示全部楼层
还能举个例子啊!~

出0入0汤圆

 楼主| 发表于 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)

出0入0汤圆

 楼主| 发表于 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. 方便代码的回归测试。在一个模块改动后,判断是否会对整个项目有影响,可以跑一下单元测试,保证没有问题。


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

出50入255汤圆

发表于 2012-8-6 20:18:47 | 显示全部楼层
谢谢推荐,刚刚买了这本书,想到http://sourceforge.net/去,结果发现上不到。----难道又是伟大的强
还好LZ 这里有啊。谢谢。

出0入0汤圆

发表于 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)

出0入0汤圆

发表于 2013-4-9 17:26:50 | 显示全部楼层
MARK………

出0入0汤圆

发表于 2013-4-9 17:45:22 | 显示全部楼层
MARK………

出0入0汤圆

发表于 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[/t[0123]]
    make

出0入0汤圆

发表于 2013-4-9 17:51:29 | 显示全部楼层
在我的电脑-》属性-》高级-》环境变量,手动添加一个“CPP_U_TEST”就可以编译了。

出0入0汤圆

发表于 2013-5-13 11:58:03 | 显示全部楼层
ljt80158015 发表于 2012-3-8 12:53
还能举个例子啊!~

兄弟能否加我一下QQ 7914703

出0入0汤圆

发表于 2014-6-23 09:28:41 | 显示全部楼层
牛逼,mark一下,正好有这方面的需求

出0入0汤圆

 楼主| 发表于 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

出0入0汤圆

发表于 2019-8-3 00:14:26 | 显示全部楼层
redriver 发表于 2014-10-19 13:51
这种测试框架越来越多了,比如google test。
http://code.google.com/p/googletest/

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

出0入0汤圆

发表于 2019-8-3 09:26:10 | 显示全部楼层
本帖最后由 shian0551 于 2019-8-3 09:27 编辑













中文版本

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

出10入0汤圆

发表于 2019-8-3 13:48:29 | 显示全部楼层
谢谢,看看书先
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-4-18 12:49

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表