Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / May 2004

Tip: Looking for answers? Try searching our database.

unit testing locations

Thread view: 
Eric - 04 May 2004 18:12 GMT
Hello,

On the one hand I've seen (most) people advocate putting all (junit) tests
in a separate test package (or packages that mirror their source packages).
This makes production deployment easier, but may force you into exposing
methods with some sort with public access, solely to validate the test. It
seems to make more sense to me to leave tests in the packages together with
their source, and use Ant's ability to exclude files that start or end with
"Test".

Any thoughts on this? FAQs I should know about? Is this the right forum for
this question? (I posted this to the software.testing forum and got one
reply from a person who basically said he wondered about that too).

Thanks in advance,
- Eric
Chris Smith - 04 May 2004 21:13 GMT
> On the one hand I've seen (most) people advocate putting all (junit) tests
> in a separate test package (or packages that mirror their source packages).
[quoted text clipped - 5 lines]
>
> Any thoughts on this?

Yep, here's a thought.  It's entirely possible in Java to store source
in identical packages, but in separate directories.  That's a very
common and effective way to solve this problem.  So your project would
have a separate "src" and "tests" subdirectory, but the same packages in
each.

Signature

www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

Eric - 04 May 2004 23:28 GMT
> Yep, here's a thought.  It's entirely possible in Java to store source
> in identical packages, but in separate directories.  That's a very
> common and effective way to solve this problem.  So your project would
> have a separate "src" and "tests" subdirectory, but the same packages in
> each.

Thanks for the reply Chris. I tried it with a protected method though. I
took "src.utilities.display.TestStatusImpl" and moved it to
"test.utilities.display.TestStatusImpl", and the method is not visible in
it's new home.

So I'd need to make this method public solely for testing.  Am I missing
something?

- Eric
Daniel Sjöblom - 05 May 2004 07:49 GMT
>>Yep, here's a thought.  It's entirely possible in Java to store source
>>in identical packages, but in separate directories.  That's a very
[quoted text clipped - 9 lines]
> So I'd need to make this method public solely for testing.  Am I missing
> something?

Yes. Remove test and src from the package names.
Signature

Daniel Sjöblom
Remove _NOSPAM to reply by mail

Chris Smith - 05 May 2004 19:36 GMT
> Thanks for the reply Chris. I tried it with a protected method though. I
> took "src.utilities.display.TestStatusImpl" and moved it to
[quoted text clipped - 3 lines]
> So I'd need to make this method public solely for testing.  Am I missing
> something?

Perhaps.  You're talking about moving methods between packages, or at
least you seem to be... "test.utilities.display.TestStatusImpl" looks
like a fully qualified class name; and the wrong one.  If you mean that
you moved the class files to test/utilities/display, then you are
confusing matters by writing the package as if it contains the name of
the root directory (test or src).

For example, you might put code in the following two places:

   /home/cdsmith/mycode/src/com/mypackage/*.java
   /home/cdsmith/mycode/tests/com/mypackage/*.java

The package declarations, of course, would both look like:

   package com.mypackage;

(After all, the whole point is to keep both classes in the same
package.)

When you compile the main code, your command might look like this:

   cd /home/cdsmith/src
   javac -d ../bin com/mypackage/*.java

and for unit tests:

   cd /home/cdsmith/tests
   javac -d ../bin com/mypackage/*.java

and then ensure that /home/cdsmith/bin is in your classpath (perhaps as
the current working directory, ".") when running the application.

Signature

www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

Eric - 05 May 2004 23:00 GMT
> > Thanks for the reply Chris. I tried it with a protected method though. I
> > took "src.utilities.display.TestStatusImpl" and moved it to
[quoted text clipped - 35 lines]
> and then ensure that /home/cdsmith/bin is in your classpath (perhaps as
> the current working directory, ".") when running the application.

I get the idea and too many people recommend it for me too believe it
doesn't work! My IDE however (Eclipse), is not at all happy if I try to
'unqualify' the package names. If you've any patience left for me I sure
would appreciate it.

Regards,
- Eric
Chris Smith - 06 May 2004 01:50 GMT
> I get the idea and too many people recommend it for me too believe it
> doesn't work! My IDE however (Eclipse), is not at all happy if I try to
> 'unqualify' the package names. If you've any patience left for me I sure
> would appreciate it.

Sure.  Follow these steps from Eclipse.

1. Right-click on your project name, and choose Properties.
2. Select "Java Build Path" in the left column.
3. Choose the "Source" tab along the top.
4. Select each of your source folders and choose "Remove".
5. Choose "Add Folder"
6. Navigate to the "src" folder, and choose OK.
7. Agree to Eclipse's request to change the output folder.
8. Choose "Add Folder" again.
9. Navigate to the "tests" folder", and choose OK.
10. Choose "OK" on the properties dialog.

Signature

www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

Eric - 06 May 2004 03:41 GMT
> > I get the idea and too many people recommend it for me too believe it
> > doesn't work! My IDE however (Eclipse), is not at all happy if I try to
[quoted text clipped - 13 lines]
> 9. Navigate to the "tests" folder", and choose OK.
> 10. Choose "OK" on the properties dialog.

Verrry cool. I owe you a beer at least!

- Eric
Shane Mingins - 05 May 2004 21:54 GMT
> > Yep, here's a thought.  It's entirely possible in Java to store source
> > in identical packages, but in separate directories.  That's a very
[quoted text clipped - 11 lines]
>
> - Eric

Hi Eric

Two comments:

1.  The "where do I put my test case" question is a little bit like "which
editor shall I use" .. opinions will vary.  Choose which best suits you.  I
use the most intelligent Java IDE around --
http://www.intellij.com/idea/ --- and I can right click any package and run
the tests in it.  And (from memory) it does not matter if they are called
TestXxxx or XxxxTest ... although I use TestXxxx so that I cabn exclude them
from my build with ANT.

2.  The other question "do I make a method public solely for testing" has
been extensively discussed in groups like
http://groups.yahoo.com/group/testdrivendevelopment/   And again, opinions
(if I recall correctly) varied.  One question (that I liked) was the one
where you ask yourself "what is the code telling me if I need to make this
public to test it?".  There may be an article on making methods public (or
not) for testing at www.junit.org have a look, or seach the TDD newsgroup,
or maybe the JUnit newsgroup also on Yahoo.

HTH

Shane

Signature

Today I want to do something better than when I did it yesterday

Eric - 05 May 2004 22:51 GMT
> > > Yep, here's a thought.  It's entirely possible in Java to store source
> > > in identical packages, but in separate directories.  That's a very
[quoted text clipped - 36 lines]
>
> Shane

Much thanks for the reply Shane. Thanks for the Yahoo groups info too. I
also use Intellij, and it does make developing a 'pleasure'! One of the
features I like about it for junits is the ability to right click on a
single test method and run it.

I like the TestXxxx version personally as well, since it makes Tests in a
package stand out. The folks at Ant prefer the xxxTest way. No difference as
long as you can exclude them in the build.

Oh well...I'm currently learning and using Eclipse on a project. I thought I
would try the mirror image directory method for this project, since so many
people seem to recommend it.

Regards,
- Eric
Karthik - 05 May 2004 04:25 GMT
> Hello,
>
[quoted text clipped - 12 lines]
> Thanks in advance,
> - Eric

Generally some people prefer to put the unit tests in the same directory
, but name the class as ending with 'Test'. This is done so that the
package level access methods and variables can be tested too, which
might not be possible in case you put it in a different package tree
altogether.

HTH

Signature

 Karthik.
 Humans please 'removeme_' for my real email.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.