Hi, Can I test private methods directly? Or should I pass by the methods that are calling these private methods? Or can I make the method private after testing? What is the best way? Thank you
on 2008-10-10 21:40
on 2008-10-10 22:08
IMHO, one should never directly test a private method. So I prefer the second way you mentioned in your email. Better yet, think of why you want to test a private method. Is it too complicated? If this is the case, way too often this private method should not really belong to the class it's currently in. This class might be doing too much and this private method is not part of core functionality this class provides (or else it should be made public as part of the class's interface). So you may want to refactor the code to find a proper home for your private method and make it public in that class and you can unit testing this new public method. Yi
on 2008-10-10 22:13
Anita Anita <firstname.lastname@example.org> writes: > Hi, > > Can I test private methods directly? > Or should I pass by the methods that are calling these private methods? > Or can I make the method private after testing? > What is the best way? > > Thank you The party line is not to test private methods. Either test them indirectly via a public method, or extract it to a separate object and make it public there. Pat
on 2008-10-10 22:18
Well, it's a methods for buying with credit card info and everything. So I wanted to test it to make sure that all my code works but I can't make it public.
on 2008-10-11 00:01
On 10 Oct 2008, at 21:18, Anita Anita wrote: > but I can't make it public. Why not? Who are you afraid is going to call it that shouldn't?