Boost logo

Boost Users :

Subject: [Boost-users] Suggestions/advice using boost::test
From: Ahmed Badran (ahmed.badran_at_[hidden])
Date: 2009-07-21 02:58:43


Hi,

I want to use boost test in a particular way, I'm not sure if it's
even possible, suggestions/advice are greatly appreciated. I have a
shared library consisting of many classes. I would like to write my
BOOST_AUTO_TEST_CASE at the end of the implementation of each class so
as to encourage always writing tests. So this is what I've done,
included <boost/test/unit_test.hpp> in the implementation file of each
class, and wrote the test cases for each class at the end of the .cpp
file for that class. In one of the .cpp files, I've stuck the
following at the top to produce a canned 'main':

#ifdef TEST
#define BOOST_TEST_MAIN
#include <boost/test/included/unit_test.hpp>
#endif

and compiled this particular file twice, so now I have a library
without a main, and an executable with a main.

The self-contained executable runs the tests perfectly as intended.
The problem is that now the library is dependent on boost::test, any
program that links against this library now needs to also link against
the boost::test library (otherwise I get linker errors) which is
_highly_ undesirable.
It is perfectly fine however, if the tests get included/instantiated
in the library but never get called, that's a perfectly valid
solution. I also don't want to wrap the inclusion/code for the tests
in ifdefs, since this will mean that the code (which is a lot) will
have to be compiled twice and this process gets messy and tedious.

Is there a way to accomplish this?

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