vc6.0下CppUnit安装

  • 转载自:

    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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值