C++ How to Set Up "Unit Test" using Boost on Visual Studio

General Project Setting

  • set entry point exist
    • at: Linker /System/ SubSystem
    • value: Console (/SUBSYSTEM:CONSOLE)

There are two ways to access the boost unittest library

  1. dynamic library

    • You need to use linker to link the lib file.
    • You need set a lot of project setting (see following).
    • Compile test file so fast
  2. header only library

    • You have nothing to link, so you have nothing to set project setting.
    • Compile test file so slow.

Project Setting using dynamic library

Using boost version 1.55 as sample

  • include:
    • at: C/C++ / General / Additional Include Directories/
    • value: YOUR_INCLUDE_PATH
  • lib path
    • at: Linker/General/Additional Library Directories
    • value: YOUR_LIB_PATH
  • lib input:
    • at: Linker/Input/Additional Dependencies
    • value: libboost_unit_test_framework-vc110-mt-gd-1_55.lib
  • dynamic debug library
    • at: C/C++ / Code Generation
    • value: Multi-threaded Debug DLL (/MDd)

Header Include and Define

using dynamic library
#define BOOST_TEST_MODULE YourModuleName
#include <boost/test/unit_test.hpp>
using header only
#define BOOST_TEST_MODULE YourModuleName // make main function
#include <boost/test/included/unit_test.hpp> // little changes is that `included\` in the middle include path


Reading Testing Result

In Visual Studio, Boost recommands that replace prompt command line window with showing messages on OUTPUT window. Following is how to do.

Project Setting for showing testing messages on OUTPUT

  • Disable Press F5 to prompt window
    • at: Debugging / Command
    • value: set it empty
  • Show message on output
    • at: Build Events/Post-Build Event
    • value: "$(TargetPath)" --result_code=no --report_level=no

ref: http://www.boost.org/doc/libs/1_36_0/libs/test/doc/html/utf/usage-recommendations/dot-net-specific.html

comments powered by Disqus