Boost logo

Boost Users :

Subject: Re: [Boost-users] Testing private methods in Boost
From: Mauricio Gomes (mgpensar_at_[hidden])
Date: 2010-06-08 21:19:47


Hi,

If it is too hard to test your private methods via the public
interface then it maybe a sign that your class could use a little
refactoring and you may want to move code to separate utility/helper
classes.

Best regards,
Mau.

2010/6/8 Rob Riggs <rob_at_[hidden]>:
> On 06/08/2010 01:54 PM, hmiller_at_[hidden] wrote:
>>
>> Is their a good strategy for testing private methods in a class using
>> Boost?  I am looking for something that is non-intrusive to the developed
>> code, but I can't think of any good ways without modifying the code under
>> test.
>
> #define private public
> #define protected public
> #include "MyClass.hpp"
> #undef protected
> #undef private
>
> That's the horribly wrong answer.  The right answer is "don't test privates
> except through the public interface".  Testing private methods explicitly
> will result in classes that are hard to refactor because the unit tests,
> upon which one relies heavily during any refactoring exercise, constrain the
> implementation.
>
> Regards,
>
> Rob
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>

-- 
Mauricio Gomes
Pensar Digital
55-11-9698-1683 (Brazil - mobile)

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