CppUnit安装手册

来源:互联网 发布:淘宝双11会场 编辑:程序博客网 时间:2024/04/29 18:25

编译和安装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 fileslibraries filessource file

 

准备开始新项目,创建一个new console application,选择‘a simple application’模板。在project setting中:

       Tab C++’,多选框‘Code Generation’,针对debugrelease分别设置为‘Multithreaded DLL’和‘Debug Multithreaded DLL’。

       Tab C++’,多选框‘C++ langage’,选择All Configurations,选上‘'enable Run-Time Type Information (RTTI)’。

       Tab Link’,在‘Object/library modules’中,针对debugrelease分别加入cppunitd.libcppunit.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的安装和配置手册设置后就可以了。
原创粉丝点击