Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1041345
  • 博文数量: 264
  • 博客积分: 6005
  • 博客等级: 大校
  • 技术积分: 2798
  • 用 户 组: 普通用户
  • 注册时间: 2007-08-08 20:15
文章分类

全部博文(264)

文章存档

2011年(42)

2010年(213)

2009年(4)

2008年(2)

2007年(3)

分类:

2010-07-07 20:21:45

1. 下载安装Boost
2. 在vs2010 中设置
   工具->选项->vc++目录
   设置包含文件目录:找到解压的boost文件夹eg:C:\boost_1_43_0
3. 编写测试程序
最简单的,新建一个win32控制台程序,选择“空项目”;然后添加新建项->代码->C++文件(.cpp),然后编写代码:
首先,在文件头添加以下两行:
#define BOOST_TEST_MODULE test_xxxx  //定义boost测试模块,宏后面的 test_xxxx不重复就行
#include   //引用boost单元测试头文件

然后添加测试用例:
BOOST_AUTO_TEST_CASE( test_someFunction )  //括号中的可以看做该测试用例的名字
{
}


=================================假设要测试如下代码

// ! 传感器接收报文
class CLastRecv
{
public:
    CLastRecv(IN const string &strRecv);
    ~CLastRecv();

public:
    bool GetRecvTime(OUT time_t &recvTine);
    bool GetRecvMessage(OUT string &strRecv);

private:
    time_t      m_recvTime;    //接收时间
    string      m_stRecv;      //接收的报文内容
};
================================================




/*! @file
********************************************************************************

模 块名      : 单元测试
文件名       : Sensor.h
相关文件     : Sensor.cpp
文件实现功能 : 测试Sensor 文件中的所有
作者         : 毛勇
版本         : 1.0
--------------------------------------------------------------------------------
多线程安全性 : 是
异常时安全性 : 是
--------------------------------------------------------------------------------
备 注        :
--------------------------------------------------------------------------------
修 改记录 :
日 期        版本     修改人              修改内容
2010/07/07   1.0.0    毛勇                创建

*******************************************************************************/


#include
#include
#include

#include "../TransmissionGateway/Sensor.h"

using namespace  std;


#define BOOST_TEST_MODULE sensor
#include

//====================================================================
//============================ 单元测试 - Sensor.h ===================
//====================================================================
BOOST_AUTO_TEST_SUITE (sensor) // name of the test suite is sensor

// ! CLastRecv 类测试
BOOST_AUTO_TEST_CASE (clastrecv)
{
    //cout <<"------------------- begin CLastRecv test---------"<< endl;
    string  str("hello");
    CLastRecv  lastRecv(str);
    time_t recvTime;
    string strRecv;

    BOOST_CHECK(lastRecv.GetRecvTime(recvTime) == TRUE);//TRUE

    lastRecv.GetRecvMessage(strRecv);

    BOOST_CHECK(0 == strRecv.compare("hello"));

    BOOST_CHECK(-1 == strRecv.compare("world"));

    //cout << ctime(&recvTime) << endl;

    //cout <<"------------------- end CLastRecv test---------"<< endl;
}

阅读(2036) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~