Hi,

2012/11/27 Gilles Sadowski <gil...@harfang.homelinux.org>

> Hello.
>
> > > [...]
> > Actually, I would like the methods to be tested, so they cannot be
> > private. That's the reason why I made them package private.
>
> You can indirectly test them by passing appropriate arguments to the public
> methods that use them. Please do not select a visibility scope just for the
> sake of unit testing.
>
> Yes, I know that it is bad practice, and also testing public method allows
indirect testing of the private methods. However, the branching between the
public method (namely Beta.logBeta) and  all private methods is quite
intricate. In order to make sure that the testing of the private methods is
comprehensive, I would be much in favor of direct testing of these private
methods. In fact, there is a way out: reflection indeed permits access to
private methods.

Does anyone oppose the usage of reflection in unit testing to access
private methods?
I personnally think it is a good compromise between encapsulation and
comprehensive testing.

Best regards,
Sébastien

Reply via email to