CppUnit安装手册

王朝other·作者佚名  2006-01-31
窄屏简体版  字體: |||超大  

编译和安装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。

准备开始新项目,创建一个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在项目编译完后会进行自动的测试。

把main函数所在的文件的代码改为如下:

#include "stdafx.h"

#include <cppunit/CompilerOutputter.h>

#include <cppunit/extensions/TestFactoryRegistry.h>

#include <cppunit/ui/text/TestRunner.h>

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

到此为止,大功告成。

Ps:若出现stlportxxxx.dll文件找不到的情况,是因为CppUnit用到了stlport,请下载最新的版本:http://www.stlport.org/archive/STLport-4.6.2.tar.gz ,再根据stlport的安装和配置手册设置后就可以了。

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航