Boost: Test

Source: Internet
Author: User
There are many libraries for test-driven development. selection is a problem.

Boost. test is a testing framework for C ++ development, similar to cppunit. I personally think cppunit has copied the JUnit framework too much and has a strong Java style, it seems a little bound to use, not so native.

I have used the Symbian version of cxxtest. It seems that Perl is required, but the Symbian itself requires Perl for installation. Therefore, it does not matter for Symbian, and Perl can be used to avoid some routines. Code (In other words, all Symbian is required. If you install a Symbian C ++ SDK and jdk1.3.2, do you not know if you need to install a GCC for the development of J2EE? ).

Boost. Test can write a test-case at the cost of # include a line of code. The simpler the test, the more developers are willing to use it,
Compared with inheriting a base class and overwriting a virtual function, boost. test is very convenient in some cases.

The following is a hello, world test example: test whether your system is equal to 1 or 2 (joke)

# Include <boost/test/Included/test_engine_monitor.hpp> #1

Int test_main (INT, char * []) #2
{
Boost_check_equal (1, 2); #3
Return 1; #4
Throw "Ooops..."; #5
}


#1 is the cost of a line of code I mentioned earlier
#2 of course, the main has been taken over by boost. Test. We will use test_main and wait for it to be called.
#3 test macro, requirement 1 = 2. Of course, an error will be reported
#4 according to the tradition of C, if our test_main function returns a non-0 value, it is also an error.
#5 It is also an error to escape from test_main due to an exception. Of course, this sentence will not be executed. For example, it is.


Then compile and run the program. For example, if VC is used

Cl.exe/GX/ID:/Boost hello. cpp

D:/Boost is my boost installation path. If hello.exe is run later, two errors are returned, indicating the file name, row number, and so on. For example

Hello. cpp (7): Error in "test_main_caller (argc, argv)": Check 1 = 2 failed [1! = 2]

D

:/Boost/test/impl/test_main.ipp (39): Error in "test_main_caller (argc, argv)": Check test_main_result = 0 | test_main_result = boost :: exit_success failed


One is the #3 error, and the other is the #4 error.

This is the simplest case. It is suitable for scenarios where there are not many tests. If there are many tests, you should compile boost. Test into a lib and link it to this Lib,
Instead of compiling boost. test every time, you can save the Compilation Time (mainly at #1 ).

It is also a good idea to work with bjam in boost. build.

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.