[PJUG Javamail] unit testing private methods
James Perkins
jrperkinsjr at gmail.com
Fri Feb 10 19:23:57 UTC 2012
Purely my opinion, you're doing it wrong :-) Okay, maybe not wrong, but
there's probably a better way.
If the methods are private it seems maybe they shouldn't be and there is
probably a better way than adding a isXxx for each new rule that comes
it. IMO this is the perfect spot for minimally a protected method that
returns a enum to describe the address type. It reduces it to one method
and allows for other types to be inserted without having to create a new
isXxx() each time a new rule comes about.
--
James R. Perkins
On Fri, Feb 10, 2012 at 11:08, Kevin Scaldeferri <kevin at scaldeferri.com>wrote:
> We have an AddressClassifier class. It's public interface exposes methods
> like allowsWhiteGloveDelivery, allowsUPS, allowsUSPS,
> allowsOvernightShipping. The implementation involves private methods like
> isPOBox, isOutsideContinentalUS, isMilitary which are combined according to
> various boolean conditions. Some of these private methods involve some
> pretty hairy regular expressions derived from a large corpus of addresses.
> It's much nicer to test those private methods directly; and in fact to run
> a large sample of the corpus through them to ensure we don't regress.
>
> -kevin
>
>
> On Fri, Feb 10, 2012 at 9:02 AM, Nick DeYoung <ndeyoung at thetus.com> wrote:
>
>> Please, give me some times when you 'want' to unit test private methods.
>>
>> specific or generic, I don't care.
>>
>> -ndy
>>
>>
>> On Fri, Feb 10, 2012 at 8:40 AM, Hall, Steve J <
>> steve.j.hall at tektronix.com> wrote:
>>
>>> Interesting question...
>>>
>>> Yes, there are times when we want to unit test private methods. In my
>>> view this often very important to help verify the behavior of key private
>>> methods. Groovy has proven to be a useful, as I do not have to alter my
>>> code to test it.
>>>
>>> Regards,
>>> Steve
>>>
>>> -----Original Message-----
>>> From: javamail-bounces at pjug.org [mailto:javamail-bounces at pjug.org] On
>>> Behalf Of Richard Johnson
>>> Sent: Thursday, February 09, 2012 6:08 PM
>>> To: javamail at pjug.org
>>> Subject: [PJUG Javamail] unit testing private methods
>>>
>>> Hi all,
>>>
>>> How do you unit test private methods? Do you? Why or why not?
>>> --
>>> Richard J.
>>> Let the discussion begin
>>> _______________________________________________
>>> Web Site - http://www.pjug.org/
>>> Javamail mailing list
>>> Javamail at pjug.org
>>> http://www.pjug.org/mailman/listinfo/javamail
>>>
>>>
>>> _______________________________________________
>>> Web Site - http://www.pjug.org/
>>> Javamail mailing list
>>> Javamail at pjug.org
>>> http://www.pjug.org/mailman/listinfo/javamail
>>>
>>
>>
>> _______________________________________________
>> Web Site - http://www.pjug.org/
>> Javamail mailing list
>> Javamail at pjug.org
>> http://www.pjug.org/mailman/listinfo/javamail
>>
>>
>
> _______________________________________________
> Web Site - http://www.pjug.org/
> Javamail mailing list
> Javamail at pjug.org
> http://www.pjug.org/mailman/listinfo/javamail
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://javac.com/pipermail/javamail/attachments/20120210/c03b7335/attachment-0002.html>
More information about the Javamail
mailing list