[Pdx-pm] The art of volunteering

Kevin Scaldeferri kevin at scaldeferri.com
Tue Feb 20 08:59:57 PST 2007


On Feb 20, 2007, at 2:36 AM, Josh Heumann wrote:

>
>
> While we're talking about testing, what's the general feeling on  
> testing
> protected and private methods?
>

If you really have private methods; and if you can provably cover all  
code paths with tests of the public API, then I would say you are  
okay to only do that.  If you can't cover everything using just calls  
to the public API, then your choices are to a) add tests to the  
private methods, or b) remove the logically unreachable code.

Protected methods can be called by your subclasses, so you should  
test them directly.

If, like most perl code, you don't really have private methods, you  
have to test everything, because someone, someday is going to use it.


Speaking of coverage... it seemed like a few people at the last  
meeting were unfamiliar with using Devel::Cover together with unit  
tests.  If there's interest, I could probably put together a talk  
about it.  (But not for March.)


-kevin


More information about the Pdx-pm-list mailing list