470,849 Members | 1,092 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,849 developers. It's quick & easy.

Q: How to organize unit testing

If I have a custom library formed by a package hiarachy build over the
years, what is the usual way of organizing JUnit testing?

Placing a suite in every package which wraps test case classes is messy
and pollutes the library when deployed as a jar.

I see two possebilites, either separate the tests by the use of
preprocessor build directives (but Java has none right?) or create a
mirror of the library package structure where only the tests live. Which
is the common practice and what problems should I look out for?

Thanks in advance,
Casper
Jul 18 '05 #1
3 6029
Casper B wrote:
If I have a custom library formed by a package hiarachy build over the
years, what is the usual way of organizing JUnit testing?

Placing a suite in every package which wraps test case classes is messy
and pollutes the library when deployed as a jar.

I see two possebilites, either separate the tests by the use of
preprocessor build directives (but Java has none right?) or create a
mirror of the library package structure where only the tests live. Which
is the common practice and what problems should I look out for?


Personally I prefer to keep the test classes in a separate directory one
way or another. Unless the tests depend on package visible member items
in the original classes you can keep them in a separate package.

I recommend looking into using ANT (http://ant.apache.org) for building.
ANT is capable of doing the build the way you want it (one way for the
regular classes, another for the test classes). Further, ANT has
special junit directives that make it possible to execute your JUnit
classes without having to build special suites. ANT is capable of doing
all this in a generic, parameterized fashion, meaning you can reuse the
build scripts for other projects.

HTH,
Ray

--
XML is the programmer's duct tape.
Jul 18 '05 #2

"Raymond DeCampo" <no****@twcny.rr.com> wrote in message
news:g4*****************@twister.nyroc.rr.com...
Casper B wrote:
If I have a custom library formed by a package hiarachy build over the
years, what is the usual way of organizing JUnit testing?

Placing a suite in every package which wraps test case classes is messy
and pollutes the library when deployed as a jar.

I see two possebilites, either separate the tests by the use of
preprocessor build directives (but Java has none right?) or create a
mirror of the library package structure where only the tests live. Which
is the common practice and what problems should I look out for?


Personally I prefer to keep the test classes in a separate directory one
way or another. Unless the tests depend on package visible member items
in the original classes you can keep them in a separate package.

I recommend looking into using ANT (http://ant.apache.org) for building.
ANT is capable of doing the build the way you want it (one way for the
regular classes, another for the test classes). Further, ANT has
special junit directives that make it possible to execute your JUnit
classes without having to build special suites. ANT is capable of doing
all this in a generic, parameterized fashion, meaning you can reuse the
build scripts for other projects.

HTH,
Ray

--


Also quite many of the IDE's out there support JUnit directly in the tool.
We've used both NetBeans and Eclipse, and they both support JUnit directly.
Netbeans separates the tests, like Ray recommends, in a package called test,
with sub-packages reflecting the package hiarachy of your classes to be
tested. Also, NetBeans uses ANT as a project- and build tool, and best of
all: it's free :-)

Arne
Jul 18 '05 #3
Thanks a lot for the answer!

Casper
Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Hugh Cowan | last post: by
11 posts views Thread by rhat | last post: by
14 posts views Thread by | last post: by
4 posts views Thread by Peter Rilling | last post: by
72 posts views Thread by Jacob | last post: by
4 posts views Thread by Dat AU DUONG | last post: by
176 posts views Thread by nw | last post: by
48 posts views Thread by Ark Khasin | last post: by
5 posts views Thread by Ben Finney | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.