Setting up boost unit testing visual studio project

less than 1 minute read

1. Header

1
2
3
#define BOOST_TEST_MODULE TestExample
#include
using namespace boost::unit_test;
2. Linked library
1
libboost_unit_test_framework-vc100-mt-sgd-1_46_1.lib

3. Global fixture

1
2
3
4
5
6
7
8
9
10
11
12
struct TestGlobalInitFixture
{
	TestGlobalInitFixture()
	{
		BOOST_TEST_MESSAGE("### Global initialization for testing ###");
	}
	~TestGlobalInitFixture()
	{
		BOOST_TEST_MESSAGE("### Global deinitialization for testing ###");
	}
};
BOOST_GLOBAL_FIXTURE(TestGlobalInitFixture);

4. Fixture

1
2
3
4
5
6
7
8
9
10
struct BuisnessLogicTestSuiteFixture
{
	BuisnessLogicTestSuiteFixture()
	{
	}
	~BuisnessLogicTestSuiteFixture()
	{
	}
};
BOOST_FIXTURE_TEST_SUITE(TestSuite_BusinessLogic, BuisnessLogicTestSuiteFixture)

5. Test case example

1
2
3
BOOST_AUTO_TEST_CASE(test_should_check_xxx)
{
}
6. run a specific test case example

1
--run_test=*/test_should_check_xxx

7. change log level

1
--result_code=no --report_level=no