-
转载自:
http://xiekeli.blogbus.com/logs/149554147.html
(引自:http://blog.csdn.net/casualgame/article/details/332153)
VC6.0下面如果想做TDD,并没有Java、.Net这么方便,不过还是可以做到的,用CppUnit即可;Gtest好像不支持VC6;
下面对google到的CppUnit在VC6下的配置及使用做简单的记录:
1、编译和安装CppUnit
从http://voxel.dl.sourceforge.net/sourceforge/cppunit/cppunit-1.10.2.tar.gz 下载一个安装包,然后解压到指定目录,文章后面用c指代解压目录。
打开$CPPUNIT/src/CppUnitLibraries.dsw文件。
在VC IDE中打开Build菜单,选择‘Batch Build…’
在Batch Build菜单中,选择所有的编译项目。
然后在/lib目录你会找到所有编译生成的文件。
在Tools/Options菜单中分别设置include files,libraries files,source file。
2、项目配置
准备开始新项目,创建一个new console application,选择‘a simple application’模板。在project setting中:
- Tab ‘C++’,多选框‘Code Generation’,针对debug和release分别设置为‘Multithreaded DLL’和‘Debug Multithreaded DLL’。
- Tab ‘C++’,多选框‘C++ langage’,选择All Configurations,选上‘'enable Run-Time Type Information (RTTI)’。
- Tab ‘Link’,在‘Object/library modules’中,针对debug和release分别加入cppunitd.lib和cppunit.lib。
- Tab ‘post-build step’,选择All Configurations,在‘post-build command(s)’中增加一个命令‘$(TargetPath)’。这样CppUnit在项目编译完后会进行自动的测试。
3、应用
把main函数所在的文件的代码改为如下:
#include "stdafx.h" #include #include #include int main(int argc, char* argv[]) { // Get the top level suite from the registry CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest(); // Adds the test to the list of test to run CppUnit::TextUi::TestRunner runner; runner.addTest( suite ); // Change the default outputter to a compiler error format outputter runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(), std::cerr ) ); // Run the tests. bool wasSucessful = runner.run(); // Return error code 1 if the one of test failed. return wasSucessful ? 0 : 1; }
按Ctrl + F5,出现以下类似语句:
Compiling...
UnitReTest.cpp
Linking...
Unit testing...
OK (0)
UnitReTest.exe - 0 error(s), 0 warning
vc6.0下CppUnit安装
最新推荐文章于 2019-05-29 16:55:50 发布