Search code examples
c++unit-testingtestcaseboost.test

BOOST.TEST Trouble having BOOST test cases in a dll and runner in exe


I am using Boost.Test for my unit testing. I would like to have all test code in a separate dll so that the test code is not shipped and my production code doesn't bloat.

For this I considered having manual test cases in the dll and have the dll export a method

// Test cases DLL code
// exported method
__declspec(dllexport) test_suite *GetTestSuite()
{
    test_suite* ts1 = BOOST_TEST_SUITE( "manual_test_suite1" );
    ts1->add( BOOST_TEST_CASE( &manual_test_case1 ) );
    ts1->add( BOOST_TEST_CASE( &manual_test_case2 ) );
    return ts1;
}

From my test runner, I am able to call this method inside my init_unit_test_suite as

bool init_unit_test_suite()
{
    test_suite * ts = GetTestSuite();
    framework::master_test_suite().add( ts );
    return true;
}

But the test cases are not picked up. However the test cases I have inside the test runner locally are getting picked up.

I am linking with the BOOST static lib and having my own main by defining

// Test runner app code
#define BOOST_TEST_NO_LIB
#define BOOST_TEST_NO_MAIN

in my test runner.

What is wrong with this combination? How could I achieve segregation of test cases in separate dlls and also have an external test runner?

EDIT: The command line I use to invoke the test cases is:

char *myargv[] = {"", "--log_level=test_suite", "report_level=detailed", "output_format=xml", "--run_test=manual_test_suite1"};
argc = _countof(myargv);
unit_test_main((init_unit_test_func) &init_unit_test_suite, argc, myargv );

The error I am getting with the above command line is:

Test setup error: no test cases matching filter

Solution

  • I found the issue. My testrunner was dynamically linking to Boost.Test. But my test dll was linking statically to Boost. I changed it to dynamic linking and now everything is working fine.