Boost logo

Boost :

Subject: [boost] [test] Using the Boost Unit Test Framework with shared libs
From: Peter (vmail_at_[hidden])
Date: 2009-03-24 07:43:19


Hi
I am using Boost.Test from the current boost 1.38 , on cygwin ( gcc )
and I want to use it with multiple test files and with shared libs ( in
order to speed up the compilation time which is too long for me when
using the header include variant ).

What is the recommended way ? ( I read the doc, several times and I read
the _long_ threads on the mailing list concerning the static/shared
library issue, but I am not sure that I understood all the details).

I did the following:

*in mainTest.cpp:*

#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MAIN

#include "../inc/globalFixture.hpp"
#include "../inc/testfile1.hpp"
#include "../inc/testfile2.hpp"

*testfile1.hpp:*

#include "globalFixture.hpp"

BOOST_FIXTURE_TEST_SUITE(ATlib1, Fixture)

BOOST_AUTO_TEST_CASE(Resource_Manager) {
...
....BOOST_CHECK ....
}

BOOST_AUTO_TEST_SUITE_END()

*testfile2.hpp:*

#include "globalFixture.hpp"

BOOST_FIXTURE_TEST_SUITE(ATlib2, Fixture)

BOOST_AUTO_TEST_CASE(FileManager {
  ... BOOST_CHECK ....
}

BOOST_AUTO_TEST_SUITE_END()

*globalfixture.hpp:

*#ifndef _GLOBALFIXTURE_HPP
#define _GLOBALFIXTURE_HPP

#define BOOST_TEST_MODULE ATlib
#include <iostream>
#include <boost/test/unit_test.hpp>
#include <boost/test/detail/unit_test_parameters.hpp>
#include <boost/bind.hpp>
#include <boost/test/output_test_stream.hpp>

using namespace boost::unit_test;

struct GlobalConfig {

    GlobalConfig() {
        std::cout << "GlobalConfig setup\n";
        using namespace boost::unit_test;
       if (runtime_config::log_level() < log_warnings)
            unit_test_log.set_threshold_level(log_successful_tests);
    };

    ~GlobalConfig() {
        std::cout << "GlobalConfig teardown\n";
    }
};

BOOST_GLOBAL_FIXTURE(GlobalConfig);

struct Fixture {

    Fixture() {
        BOOST_TEST_MESSAGE("setup Fixture");
       using namespace boost::unit_test;
       unit_test_log.set_threshold_level(log_successful_tests);
    }

    ~Fixture() {
        BOOST_TEST_MESSAGE("teardown Fixture");
    }
};

#endif /* _GLOBALFIXTURE_HPP */*

*I then link to boost_unit_test_framework-gcc34-mt-1_38.so
The link passes , but I get a warning from gcc++ 3.4.4 that auto-linking
has been enabled ( I will provide the exact details if useful ).
I can execute the resulting mainTest.exe without problems, but the
compiler warnings tells that something is not quite right.

Is the above example the right way to use multiple test files ?
Are the flags for shared libs correctly set ?

Thanks for your help.

PS: I think that Boost.Test is not easy to grasp ( at least for me ). I
think this is partially due to a lack of complete examples ( involving
for examples a test suite with more than one test file ).
Also the static/shared library topic and the related macros (
BOOST_TEST_DYN_LINK etc ) could do with a concrete example. Maybe the
mentioned case above could serve as an example after
clarification.

Peter


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk