Software Test--boost Unit Test C + +

Source: Internet
Author: User

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 + +

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.