C ++ unit testing framework: a boost test tutorial -- Part2: Using boost Test

Source: Internet
Author: User

Original address: http://www.beroux.com/english/articles/boost_unit_testing? Part = 2

Following the crash-course introduction, let's see how to install and use boost, plus some references.

Installing boost

Now that you have an idea about the benefit we'll briefly see how to install boost.

On WindowsVisual c ++The simplest way (and also the way promoted by boost) is to use boost from boostpro computing.

Here are the full installation step. If the installation setup fails, restart it.

  1. Download the latest boost installer from boostpro computing: http://www.boostpro.com/products/free
  2. Install the setup:
    1. Select whatever mirror you like.
    2. It is advised to checked those checked with a cross below:
      [] Visual c ++ 8.0 (Visual Studio 2005)



      [X] visual c ++ 9.0 (Visual Studio 2008)







      [X] mulithread debug, DLL -- DLL debug, required when boost_dyn_link defined.



      [X] mulithread, DLL -- DLL release, required when boost_dyn_link defined.



      [X] mulithread -- lib (for crt dll) release, default in release.



      [X] mulithread debug -- lib (for crt dll) debug, default in debug.



      [X] mulithread, static runtime -- lib (for CRT Lib) release.



      [] Mulithread debug, static runtime -- lib (for CRT Lib) debug.



      [] Single thread, static Runtime



      [] Single thread debug, static Runtime
    3. Keep the default options on the next screen.
    4. Wait for the download and installation to complete. In case of error, restart.
    5. Say yes to add boost to the path at the end.
  3. Add boost to the include and library folders of Visual Studio:
    1. OpenVisual Studio
    2. Go to the menuTools> options...
    3. GoProject and solutions> VC ++ Directories
    4. Add to yourInclude files:C: "Program Files" Boost "Boost _X_xx_x
    5. Add to yourInclude files:C: "Program Files" Boost "Boost _X_xx_x"Boost" tr1
    6. Add to yourLibrary files:C: "Program Files" Boost "Boost _X_xx_x"Lib
  4. (Optional)Path Extension sion: If you use boost DLLs (rare) You may addC: "Program Files" Boost "Boost _X_xx_x"LibTo your system path.
  5. (Optional)Documentation shortcut: Create a shortcutC: "Program Files" Boost "Boost _X_xx_x"More" index.htm
  6. Done.
Creating a unit test project in Visual C ++

You know how to write c ++ code using boost test and you have boost installed. Let's see how to create a nice project for unit testing in Visual Studio.

    1. Open your existing project to test.
    2. Go to menuFile> Add> new project...
    3. Create a visual C ++ empty project.
    4. Either Add the classes to test so they get compiled, or make a library and add a reference to your other project (better). You probably also want to have the sameStdafx. h.
    5. In the Project SettingsBuild Events> post-build eventDefine:
      Command line:"$ (Targetpath)" -- result_code = No -- report_level = No -- catch_system_error = Yes
    6. Include your runner and other test cases.

If you generated a library from your code, you probably have at least third project that will use this library to make the application. you can mark the unit test to be built first, this way you'll always have unit tests checks done each build.

Official documentation

You can find the official documentation here. The documentation may be hard to read, so here are some tips to find your things in it:

    • The boost_check and other commands:Boost Test Library> the unit test framework> testing tools
    • Runner command-line options:Boost Test Library> the unit test framework> runtime configuration> parameters reference
Conclusion

Boost test is now simple to use (once you found your way through their documentation or after reading this article) and provides from minimal tests to complex scenarios. you can find some more advanced features like function base test cases. I hope boost has now been demystified for you; it's now my favorite C ++ testing framework.

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.