[PJUG Javamail] unit testing private methods

Richard Johnson richard at ytivarg.com
Fri Feb 10 14:44:06 UTC 2012


I agree with Zack.  We want to encapsulate logic.  That ultimately means 
private methods (for the ultimate in encapsulation.)  Think about it.  At some 
point you want/need to be able to prove that (for instance) your regular 
expression is working right, or that you're not fetching a null, or that 
you're realling returning a sin(x) and not a cos(x) or that things are in the 
right order.

I like to (try to) do TDD and (mostly) adhere to a strict single-
responsibility principle.  That means lots of small, easy to read private 
methods *that have tests.*   Your coding may vary.

I need to dig some more into Doug's JMockit suggestion and see how it works.  
It seems better than the alternatives I've tried (main(), inner class, and 
make protected and extend the class.)  On the surface (a sample size of one 
web page) it looks a little cryptic.

On a somewhat grander level, I don't see "testing patterns" in the same style 
as GoF "design patterns."  We should have a well-known structure and method of 
testing proxies, commands, etc.
-- 
Richard J.



More information about the Javamail mailing list