|
Re: JUnit FAQ suggests private methods bad design?
"Shaun Zinck" <avalanche@texoma.net> wrote in message
> Private methods are not meant to be called from anything other than
> the owning class/object. The point of JUnit testing is to make sure
> that the inputs and outputs of an object work as expected. If each
> tested input (method call, parameters) yields the expected output
> (return value, object state), then the class can be considered
> functional. Even if public methods call private methods, if the
> outputs and inputs are correct then the private methods can be
> considered correct as well.
Right. That is the generally best way to handle private methods. If
they are private for 1+ reasons, those reasons must be addressed to
legitimate yanking them out into their own class. Plus calling
overhead, and readability should be evaluated when taking that kind of
step.
> Private methods are tested indirectly by
> testing the public methods that use them. This is known as "black box
> testing".
>
> Since the correctness of private methods lies in the fact of the
> inputs and outputs working correctly, testing private methods directly
> is unnecessary. It may even be a bad idea since that would make it
> harder to change code internal to your class and not exposed to the
> public.
Elliott
--
Once a fortnight, Audrey and her close companion were driven to
re-experience bathing in the pure sound of shattering panes of glass.
|