Boost logo

Boost Users :

Subject: [Boost-users] [Boost.Test] Unable to perform init at startup
From: Adam Nielsen (a.nielsen_at_[hidden])
Date: 2013-12-21 06:09:02


(Apologies for the last message, I am using an unfamiliar keyboard and
accidentally pressed the 'send' keyboard combination.)

Hi all,

I'm having a bit of a problem trying to figure out how to perform some
class init while manually registering my tests.

I want to run a set of tests which all share the same class instance
(this is a factory class that creates the objects to be tested.)

I am creating a number of global class instances and using boost::bind
in the constructor to register the tests with Boost.Test.

This works fine, except that I need to create the factory class before
the tests can be run. In case the factory class fails, I want to use
some of the Boost.Test checks in the initialisation function.

However when I do this, I get this runtime error:

  terminate called after throwing an instance of 'std::runtime_error'
    what(): can't use testing tools before framework is initialized

I am assuming this means I need to wait with the construction of my
factory class until Boost.Test is ready, but I am unsure how to do this.

I am #defining BOOST_TEST_MODULE, and when I try to declare a function
called init_unit_test() as suggested in the docs it tells me the
function already exists. If I remove the BOOST_TEST_MODULE #define,
then it complains that main() is not implemented.

I am a bit confused because I do not understand the reason for having
init_unit_test() if you cannot implement it. If you choose not to use
the Boost auto function then it seems you must implement your own
main(), so I would expect your init code would go there, so there is no
need for the init_unit_test() function?

Is there some other way not mentioned in the docs to manually register
tests (which are class member functions) but where the class can call
Boost.Test functions in its constructor?

Many thanks,
Adam.
        


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