Boost logo

Boost Users :

Subject: Re: [Boost-users] [Boost.Test] [1.38] Automated test suite registration with muti-file-test-modules
From: Ahmed Badran (ahmed.badran_at_[hidden])
Date: 2009-07-28 03:32:08


>> -----Original Message-----
>> From: boost-users-bounces_at_[hidden] [mailto:boost-users-
>> bounces_at_[hidden]] On Behalf Of Greg Christopher
>> Sent: Wednesday, July 08, 2009 10:02 AM
>> To: boost-users_at_[hidden]
>> Subject: Re: [Boost-users] [Boost.Test] [1.38] Automated test suite
>> registration with muti-file-test-modules
>>
>>
>>
>>> -----Original Message-----
>>> From: boost-users-bounces_at_[hidden] [mailto:boost-users-
>>> bounces_at_[hidden]] On Behalf Of Gennadiy Rozental
>>> Sent: Friday, July 03, 2009 11:48 PM
>>> To: boost-users_at_[hidden]
>>> Subject: Re: [Boost-users] [Boost.Test] [1.38] Automated test suie
>>> registration with muti-file-test-modules
>>>
>>> Greg Christopher <gchristopher <at> vmware.com> writes:
>>>
>>>>> This is covered in docs I believe. BOOST_TEST_MODULE has similar
>>> effect
>>>>> as
>>>>> BOOST_TEST_MAIN, but also define the name of the master test
>> suite
>>>> Since I don't really need to define the name of the master test
>>> suite,
>>>> I will not use BOOST_TEST_MODULE.
>>>>
>>>> As it turns out, that still does not yield a working example. I
>> then
>>>> have no init_unit_test_suite()
>>> Please post an example and how you build it.
>> The example is basically the same example that was posted earlier:
>> Test1.cpp:
>> #include "stdafx.h"
>>
>> #define BOOST_TEST_MAIN Yes // Remove this line and we stop working
>>
>> #include <boost/test/execution_monitor.hpp>
>> #include <boost/test/unit_test.hpp>
>>
>> BOOST_AUTO_TEST_SUITE(foo1)
>>
>> BOOST_AUTO_TEST_CASE(foo1case)
>> {
>> BOOST_CHECK(4 == 4);
>> }
>>
>> BOOST_AUTO_TEST_SUITE_END()
>> Test2.cpp
>> #include "stdafx.h"
>>
>> #include <boost/test/execution_monitor.hpp>
>> #include <boost/test/unit_test.hpp>
>>
>> #define BOOST_TEST_MODULE Yeah
>>
>> BOOST_AUTO_TEST_SUITE(foo2)
>>
>> BOOST_AUTO_TEST_CASE(foo2case)
>> {
>> BOOST_CHECK(4 == 4);
>> }
>>
>> BOOST_AUTO_TEST_SUITE_END()
>>
>> Now when you link to the static version of the lib you get this:
>>
>> 1>libboost_unit_test_framework-vc90-mt-gd-1_38.lib(unit_test_main.obj)
>> : error LNK2019: unresolved external symbol "class
>> boost::unit_test::test_suite * __cdecl init_unit_test_suite(int,char *
>> * const)"
>> (?init_unit_test_suite@@YAPAVtest_suite_at_unit_test_at_boost@@HQAPAD_at_Z)
>> referenced in function _main
>>
>> Project is a simple Visual Studio 2008 one using static version of
>> boost:
>>
>> http://www.easy-share.com/1906667710/basic.zip
>>
>> Thanks,
>> Greg
This is how I usually do the automated test suite registration with
multi-file test modules, I arrange my files as follows:

file1.cpp
#include <boost/test/unit_test.cpp>

....
BOOST_AUTO_TEST_SUITE(file1_test_suite)

... tests ...

BOOST_AUTO_TEST_SUITE_END()
- end of file 1 -

file2.cpp
#include <boost/test/unit_test.cpp>

....
BOOST_AUTO_TEST_SUITE(file2_test_suite)

... tests ...

BOOST_AUTO_TEST_SUITE_END()
- end of file 2 -

test_main.cpp
#define BOOST_TEST_MODULE master_test_suite
#include <boost/test/included/unit_test.hpp>

- end of test_main.cpp -

This causes a main, a test runner and the automatic generation of the
required functions in test_main.cpp.

I'm not that experienced using boost.test, but I've found this solution
to work nicely and fit my needs.

Regards,
Ahmed


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net