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.
-
- Download the latest boost installer from boostpro computing: http://www.boostpro.com/products/free
- Install the setup:
-
- Select whatever mirror you like.
- 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
-
- Keep the default options on the next screen.
- Wait for the download and installation to complete. In case of error, restart.
-
- Say yes to add boost to the path at the end.
-
- Add boost to the include and library folders of Visual Studio:
- OpenVisual Studio
- Go to the menuTools> options...
- GoProject and solutions> VC ++ Directories
- Add to yourInclude files:C: "Program Files" Boost "Boost _X_xx_x
- Add to yourInclude files:C: "Program Files" Boost "Boost _X_xx_x"Boost" tr1
- Add to yourLibrary files:C: "Program Files" Boost "Boost _X_xx_x"Lib
-
- (Optional)Path Extension sion: If you use boost DLLs (rare) You may addC: "Program Files" Boost "Boost _X_xx_x"LibTo your system path.
- (Optional)Documentation shortcut: Create a shortcutC: "Program Files" Boost "Boost _X_xx_x"More" index.htm
-
- 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.
- Open your existing project to test.
- Go to menuFile> Add> new project...
- Create a visual C ++ empty project.
- 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.
- In the Project SettingsBuild Events> post-build eventDefine:
Command line:"$ (Targetpath)" -- result_code = No -- report_level = No -- catch_system_error = Yes
- 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.