CppUnit的使用步骤

来源:互联网 发布:战争雷霆激活码淘宝 编辑:程序博客网 时间:2024/03/28 18:25

使用cppunit简直是恶梦啊

参考了这两文:

配置和使用CPPUnit笔记http://dev.csdn.net/article/68/68259.shtm

便利的开发工具 CppUnit 快速使用指南http://www.devworkclub.com/bbs/FileView.php?id=200408051345330000

 

研究出来的使用步骤:

1.       编译cppunit目录/src/cppunit/CppUnitLibraries.dsw中的cppunit_dll项目,release版生成cppunit_dll.libcppunit_dll.dlldebug版生成cppunitd_dll.libcppunitd_dll.dll。这是CPPUnit基本类库。

2.       编译cppunit目录/src/cppunit/CppUnitLibraries.dsw中的TestRunner项目。release版生成TestRunner.libTestRunner.dlldebug版生成TestRunnerd.libTestRunnerd.dll。这是使用MFC的图形化界面的类库。

3.       把所有lib文件放置到CommonFiles/Lib目录下面。

或者

   在VC中工具-》选择-》目录-》Library Files中将cppunit中的lib目录放进来

  

4.       dll文件放到相应的debugrelease可执行目录下面。

5.

6.vc中工程-》设置-》link

放入cppunitd_dll.lib

在“Projects/Settings.../C++/C++ Language”页选中“Enable RTTI ”。
在“Projects/Settings.../C++/Code Generation”页选择“Use run-time library”中的内容:
Release版, 选择"Mulithreaded DLL".
Debug版, 选择 "Debug Multihreaded DLL".

7.可以引入宏AddingUnitTestMethod.dsm,可以方便生成测试框架

8.写完待测试和测试类后,还要写个main函数

提供的断言:

CPPUNIT_ASSERT(condition) // 确信condition为真
CPPUNIT_ASSERT_MESSAGE(message, condition) // 当condition为假时失败, 并打印message
CPPUNIT_FAIL(message) // 当前测试失败, 并打印message
CPPUNIT_ASSERT_EQUAL(expected, actual) // 确信两者相等
CPPUNIT_ASSERT_EQUAL_MESSAGE(message, expected, actual) // 失败的同时打印message
CPPUNIT_ASSERT_DOUBLES_EQUAL(expected, actual, delta) // 当expected和actual之间差大于delta时失败

运行方式:
CppUnit::TextUi::TestRunner // 文本方式的TestRunner
CppUnit::QtUi::TestRunner // QT方式的TestRunner
CppUnit::MfcUi::TestRunner // MFC方式的TestRunner

 

   在VC中工具-》选择-》目录-》Include Files中将cppunit中的include目录放进来



Google <script type="text/javascript"><!-- google_ad_client = "pub-7330597899926046"; google_ad_format = "350x30_sdo"; google_link_target = 2; google_color_bg = "ffffff"; google_color_link = "000000"; google_encoding = "GB2312";//--></script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-7330597899926046";google_ad_slot = "8791774696";google_ad_width = 468;google_ad_height = 60;//--></script> <script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
原创粉丝点击