Jump to content
  • Advertisement
Sign in to follow this  
maximAL

Boost.test - howto?

This topic is 3589 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i wanted to use unit tests for a library i'm just writing and i decided for boost.test mostly because it has a good reputation and will most likely still be supported in a few years (as my project is supposed to be very long-lived). but unfortunately i already run into problems just implementing the most basic examples. eg.:
#include <my_class.hpp>
#define BOOST_TEST_MODULE MyTest
#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_CASE( my_test )
{
    my_class test_object( "qwerty" );

    BOOST_CHECK( test_object.is_valid() );
}

this won't link, because main is undefined (i dynamically linked the lib). now, of course i know there must be a main somewhere. but on several occasions the doc mentions it's automatically produced by boost.test. when i include <boost/test/included/unit_test.hpp> instead, it works. the doc also mentions function like unit_test_main and what not, you may have to define yourself but all in all it's still completely unclear to me, how the whole system works and what i really need to get anything up and running. disappointingly, the doc seems mostly incomplete, with many not-working examples, dead links/images...and many typos. now, since this is a boost lib where talking about here, it's probably my fault. i hope. otherwise i might resort to CxxTest. that seems to work ootb like a charm. but the last version is already a few years old and who knows if there will be an update someday (eg. to adept to the new C++ standard).

Share this post


Link to post
Share on other sites
Advertisement
I had a similar problem IIRC, but never got round to fixing it. I'm fairly sure the problem started with boost 1.35 and that it used to work with 1.34, so it may be worth trying an older version of the lib.

Share this post


Link to post
Share on other sites
I poked around with boost.test a few days ago too. Unfortunately, I don't have the code here, so I can't say exactly how I got it working. I think you're using the wrong macro though.

BOOST_TEST_MODULE only defines *a* module, iirc. There's another macro for defining the *main* module (which generates a main function)

Also, the docs actually exist, and are pretty much up to date. They just seem to have *also* kept a ton of old, outdated docs online as well. I spent a few hours trying to figure out these old docs, before I stumbled across the "proper" version. But once you find the proper docs, it works very well.

If I remember, I'll post my code when I get home. And a link to the proper documentation. :)

In any case, once you get past these problems, I think it's a really nice framework.

Share this post


Link to post
Share on other sites
Quote:
Original post by donny dont
Are you using bjam to build or visual studio?

for an example as basic as that one, a command line call to g++ should be enough ;)

Quote:
Original post by donny Spoonbender
BOOST_TEST_MODULE only defines *a* module, iirc. There's another macro for defining the *main* module (which generates a main function)

there also is the BOOST_TEST_MAIN variable, but that doesn't change anything.

Share this post


Link to post
Share on other sites
This minimal example compiles fine for me:


#define BOOST_TEST_MODULE MyTest
#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_CASE( my_test )
{
BOOST_CHECK( 1 == 1 );
}



and I *think* that if you use the docs located here, they should be up to date, and the links to source code examples should actually work. (If you google for the docs, you most likely end up with the wrong version, one with lots of dead links)

Share this post


Link to post
Share on other sites
unfortunately, this also doesn't work for me. but i figured out that i have version 1.34 instead of the lastest 1.36 installed (i just took what my package manager spit out). maybe i try to build 1.36 on my own...

Share this post


Link to post
Share on other sites
It isn't too painful, just can take quite a bit of waiting, to compile boost on linux. Though Boost.Test is somewhat of a header only library so you can get away with not doing the actual compile.

http://www.boost.org/doc/libs/1_36_0/more/getting_started/unix-variants.html

That should get you started up.

Share this post


Link to post
Share on other sites
so, even with the latest version it still won't work, but the error messages differ this time.
now i get compiler errors because "init_unit_test_func" is undefined. i had a look at the source and found this in framework.hpp:
#ifdef BOOST_TEST_ALTERNATIVE_INIT_API
typedef bool (*init_unit_test_func)();
#else
typedef test_suite* (*init_unit_test_func)( int, char* [] );
#endif


defining BOOST_TEST_ALTERNATIVE_INIT_API doesn't help. but copying the first typedef in my test program does - in contrast to the second typedef.
really, wtf?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!