----- Original Message -----
From: "Thomas Calivera" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, May 18, 2001 2:29 PM
Subject: Re: Mock Objects


> Vincent et al
>
> A general question regarding mock objects: When unit testing with mock
> objects, there is a general desire to break algorithms up into distinct
> parts and pass mock objects in and out of these algorithms. These
> fine-grained algorithms become separate methods that are usually
candidates
> for private protection (in Java). However, since most unit tests are a
> separate class ([ClassToTest]Test.java), these algorithms become friendly
at
> best (test class in package), public at worst. When this happens, the
> contract of the class is significantly extended (at least, within the
> package). Is this an unavoidable externality of fine-grained,
comprehensive
> unit testing? Or is there a way, perhaps with inner classes, to retain
> private protections on methods not useful for other package or general
> classes, but enable granular unit testing?
>

Interesting remark !
I can give you 2 answers :

1- make your methods protected instead of private. They will be accessible
by your test class as long as this test class is in the same package ! I
think it is not that bad since the method is still not public.
2- now, if you really want to keep the method private, you always have the
possibility to unit test private class (I'm not sure how, but this is done
by several test famework - You can check JUnitX which does it - I think they
change the security manager but I'm not sure

> Tom
> http://calivera.manilasites.com

Cheers,
Vincent


Reply via email to