Here’s a minimal example of a C++ unit test program using boost.test. You can copy the sample code by choosing the Help -> Using Boost Test… menu entry.



A boost.test based unit test needs #include <boost/test/unit_test_gui.hpp> in place of the regular unit_test.hpp header file to support BoostTestUi. The unit_test_gui.hpp file can be created from the File -> Create Header -> Boost Test… menu. Save the header file somewhere in a boost/test subfolder in your include path, typically inside the boost folder itself.

Create boost/test/unit_test_gui.hpp

BoostTestUi will detect a boost.test executable without the special #include file and show you a reminder.


BoostTestUi adds the BOOST_AUTO_TEST_CASE_ENABLE(name, enable) macro as an alternative to BOOST_AUTO_TEST_CASE_ENABLE(name). The additional enable parameter accepts a boolean expression that defines the initial enabled state of the test case.


You wil get linker errors if you #include <boost/test/unit_test_gui.hpp> in more than one source file in your test project. A single source file with unit_test_gui.hpp is enough to support BoostTestUi but you can #define BOOST_TEST_NO_GUI before #include <boost/test/unit_test_gui.hpp> if you want to use BOOST_AUTO_TEST_CASE_ENABLE in other unit test source files too.

If you define your own init_unit_test_suite function instead of using BOOST_TEST_MODULE, it


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s