
Signature
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
> 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