Boost unit test framework is a c++ unit test framework of boost libraries for c++ development.
Requirements:
Anchor List:
First, a boost unit test c++ code
hello.cpp
#define BOOST_TEST_MODULE "hello.cpp" #include <boost/test/unit_test.hpp> #include <iostream> BOOST_AUTO_TEST_CASE(test_case_01) { std::cout << "Hello, c++!" << std::endl; BOOST_CHECK(2 == 2); BOOST_CHECK_EQUAL(2, 2); }
Then, compile the c++ unit test code
g++ hello.cpp -std=c++26 -DBOOST_TEST_DYN_LINK -lboost_unit_test_framework -o hello
BOOST_CHECK :
You can provide a false condition to it, compile and run again, see what happens.
c++ code:
Use the same c++ code above: hello.cpp
B2 Build:
File: jamroot
import testing ; lib boost-test : : <name>boost_unit_test_framework : : <define>BOOST_TEST_DYN_LINK ; project : default-build <cxxstd>26 ; unit-test hello : hello.cpp : <library>boost-test ;
Build test
b2
Because unit-test is used instead of exe, the unit test program will be auto-compiled and auto-run, you does not have to run program by hand.
https://www.boost.org/doc/libs/latest/libs/test/doc/html/index.html
Thu Jun 19 12:44:59 AM UTC 2025