Boost logo

Boost Users :

From: Ed Johnson (ed_at_[hidden])
Date: 2006-05-02 22:07:03


Gennadiy Rozental wrote:
>> 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

In my tests, it does not appear possible to use the auto_unit_test.hpp
macros in a test class that is attempting to be a friend of a testee
class. The compiler complains that the test class is trying to access
private data. Does anyone know how to make them work together?
(Should this be a separate thread, or is it alright to add it to this one?)

Thanks,

Ed


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