Classification:
1. Download and install boost
2. Set in VS2010
Tools, Options->vc++ Directory
Set Include Files directory: Find the extracted boost folder Eg:c:\boost_1_43_0
3. Writing test procedures
In the simplest, create a new Win32 console program, select "Empty Project", then add the code->c++ file (. cpp) with the new item, and then write the code:
First, add the following two lines to the file header:
#define Boost_test_module test_xxxx//define BOOST Test module, the test_xxxx on the back of the macro is not repeated.
#include <boost/test/unit_test.hpp>//reference Boost unit test header file
Then add the test case:
Boost_auto_test_case (test_somefunction)//parentheses can be seen as the name of the test case
{
}
================================= assume that you want to test the following code
// ! Sensor Receiving message
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; Receive time
String M_strecv; Content of the message received
};
================================================
/*! @file
********************************************************************************
<PRE>
Module Name: Unit test
File name: Sensor.h
Related documents: Sensor.cpp
File implementation function: Test all of the sensor files
Author: Mao Yong
Version: 1.0
--------------------------------------------------------------------------------
Multithreading Security: Yes
Exception-time Security: Yes
--------------------------------------------------------------------------------
Notes
--------------------------------------------------------------------------------
To modify a record:
Date version modified by the person to modify the content
2010/07/07 1.0.0 Mao Yong created
</PRE>
*******************************************************************************/
#include <iostream>
#include <string.h>
#include <string>
#include ". /transmissiongateway/sensor.h "
using namespace Std;
#define BOOST_TEST_MODULE Sensor
#include <boost/test/included/unit_test.hpp>
//====================================================================
============================ Unit Test-Sensor.h ===================
//====================================================================
Boost_auto_test_suite (sensor)//name of the TEST SUITE is sensor
// ! CLASTRECV class Test
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;
}
Software Test--boost Unit Test C + +