Re: testing methods




"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


.



Relevant Pages

  • Re: JUnit problem
    ... the version of the JUnit plugin ... Did you try rebooting Eclipse and/or your computer? ... Yes, rebooted and restarted Eclipse. ...
    (comp.lang.java.programmer)
  • Re: New to JUnit... Eclipse Question
    ... The tutorial says "...according to TDD... ... However JUnit4.0 for Eclipse doesn't seem to agree ... I went to create the JUnit Test Case (before ... Now I know what Calculator looks like and can implement just enough to make the test pass. ...
    (comp.lang.java.programmer)
  • Re: Frage zu JUnit
    ... throw new IllegalArgumentException; ... Funktioniert bei mir in Eclipse nicht. ... Bei mir funktioniert es mit JUnit 4.3.1 in Eclipse 3.4.1 ... Im Run> Run Configurations... ...
    (de.comp.lang.java)
  • Re: New to JUnit... Eclipse Question
    ... The tutorial says "...according to TDD... ... However JUnit4.0 for Eclipse doesn't seem to agree ... I went to create the JUnit Test Case (before ... BUT as soon as you do write foo() ...
    (comp.lang.java.programmer)