tags:

views:

62

answers:

1
+2  Q: 

Testing with boost

Can someone write step by step what to do to start using testing facilities from boost? For example I have a class:

class A
{
public:
int multiplyByTwo(const int input)
{
return input * 2;
}
};

and I would like to set test cases for multiplyByTwo fnc. How? In which files? What steps do I need to perform in order to run it?

+3  A: 

Someone already has written this down for you - there is a 'hello world' introduction in the Boost docs.

For your case, I think it should look something like this:

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

BOOST_AUTO_TEST_CASE( my_test )
{
    my_class A( /* whatever you need to construct it right */ );

    BOOST_CHECK( A.multiply_by_two(2) == 4 );
}

EDIT: There is a slightly more extensive tutorial here that should help when you start to taxonomize your tests.

Steve Townsend
@Steve The missing info: BOOST_AUTO_TEST_CASE( my_test ) - thats the second 'screen' in which file am I suppose to place it? What is my_test?
There is nothing we can do
@There is nothing we can do - see edit. Let me know if more problems arise.
Steve Townsend
Shouldn't custom headers be in " "
Chubsdad
@Steve thanks for your edit. I'm going to test it right now.
There is nothing we can do
@Steve Great thanks it seems to work now. So basically every new test I'm just placing in BOOST_AUTO_TEST_CASE?
There is nothing we can do
@There is nothing we can do - see 2nd edit. That would work, yes.
Steve Townsend
@Steve once again thanks, I was driven demented by lack of good tutorials (step by step and I mean step by step) on the web.
There is nothing we can do