|
Boost Users : |
From: Gennadiy Rozental (gennadiy.rozental_at_[hidden])
Date: 2006-03-22 16:29:18
> Is there a way to test the private functions of a class without moving
> them into public scope during test?
>
> What are some strategies for this?
>
> I was hoping to add "friend class boost::unit_test::test_suite;" to my
> class but that didn't work.
Putting aside "why would you need that" question, simple answer is: define
test case as a friend to your class. For example if you want to implement
test case as free function:
class Foo {
friend void foo_test();
void private_method();
};
void foo_test()
{
Foo f;
f.private_method();
}
If you need multiple test cases having access to the internals you could
define test class and make it friend of your class. Next all your test cases
will instantiate test class and run test methods.
Gennadiy
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net