I am now using BOOST::UNIT_TEST framework to perform unit test, and it is a great tool to perform unit test. However, I found something inconvenient: when I add functions to test, it seems that the functions must be static or a free function as the following codes illustrate:
test_suite* ts = BOOST_TEST_SUITE( "unit_test" );
ts->add(BOOST_TEST_CASE(&static_fun));
When it is not a static function, for example,
class Abc
{
public:
void myfun();
};
Abc obj;
ts->add(BOOST_TEST_CASE(&(obj.myfun)));
then, I will have C2064: term does not evaluate to a function taking 0 arguments
error. Any idea that I can add the non-static class member function to the test framework? Thanks
You should look here
You can use boost::bind
for this case.
ts->add(BOOST_TEST_CASE(boost::bind(&Abc::myfun, obj)));