Search code examples
c++testingboostboost-test

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?


Solution

  • 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.