Re: testing methods
- From: "Rhino" <no.offline.contact.please@xxxxxxxxxx>
- Date: Sun, 30 Oct 2005 09:00:57 -0500
"Michael" <mbialowas@xxxxxxx> wrote in message
news:hXU8f.339123$1i.216931@xxxxxxxxxxx
> Hello all, I was wondering something. I am putting 4 methods into a class
> called MyUtils. Can I test these methods to make sure they work; if I
create
> new new class files calling these methods. My question is , should it work
> if I place all files in same directory.
>
I agree with what Roedy has already said. I have done exactly what you're
talking about and tested these utility methods via both of the techniques
Roedy mentions and they worked very well for me.
In fact, I have quite a few different groups of utility methods so I put
each group into its own class. As a result, I have a GraphicUtils class for
utility methods that involve Graphics, a DateTimeUtils class for utility
methods involving the calculation of dates and times, FontUtils for utility
methods involving fonts, and so forth. I also have a MiscellaneousUtilities
class for everything that doesn't properly fit into any of the other Utility
classes. All of them belong to a package called
'mydomain.com.common.utilities'. When I bundle up my applications, the
applications are only distributed with the specific Utils classes that they
need, e.g. FontUtils and LogUtils. If I had put all of my utilities into a
single large class called Utils, I'd have to ship a large number of utility
methods most of which never got used. Instead, I ship a few smaller classes
of utilities, most of which DO get used.
One other thing: I think you'll find that you want to make your Utility
methods static. There is little value, as far as I can see, in having to
instantiate potentially dozens or hundreds of instances of your Utility
classes at runtime when a class containing static methods will do the job
just fine. If you look at classes like Math, you'll see that its methods are
static; I assume that is for the same reason as I just cited.
By the way, if you decide to check out JUnit, just so a Google search on
"JUnit tutorial" and you'll find plenty of hits describing how to use it. I
didn't find JUnit particularly intuitive to use at first but it actually
works quite well and isn't too hard to learn. It's also integrated into some
IDEs, like Eclipse, so you don't even have to download it or install it if
you use Eclipse since it's already there.
Rhino
.
- References:
- testing methods
- From: Michael
- testing methods
- Prev by Date: Re: Desing Question re Multiple Constructors
- Next by Date: Eclipse and cvs
- Previous by thread: Re: testing methods
- Next by thread: NIO for J2ME?
- Index(es):
Relevant Pages
|