You should look here
You can use boost::bind
for this case.
ts->add(BOOST_TEST_CASE(boost::bind(&Abc::myfun, obj)));
Question
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
Solution 2
You should look here
You can use boost::bind
for this case.
ts->add(BOOST_TEST_CASE(boost::bind(&Abc::myfun, obj)));
OTHER TIPS
I think you try to define a test fixture class? The way I use boost test in most cases looks like this:
struct MyTestFixture
{
int test_data;
void func()
{
// some common test code
}
};
BOOST_FIXTURE_TEST_SUITE(MyTest, MyTestFixture)
BOOST_AUTO_TEST_CASE(Test1)
{
test_data = 3;
func();
// ...
}
BOOST_AUTO_TEST_CASE(Test2)
{
// ...
}
BOOST_AUTO_TEST_SUITE_END()