File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JB: Leave tests in app for deployment?

 
Michael Sullivan
Ranch Hand
Posts: 235
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Placing tests in the app, and I see that to test protected methods, I need to place tests in the same package as the classes under test. So am I adding my tests to the actual app and deploying them? If so, doesn't this bulk up it a bit? Do you suggest leaving the tests in for each release? Should we be versioning our tests along with the app?

Thanks,
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33673
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael,
Placing tests in the app, and I see that to test protected methods, I need to place tests in the same package as the classes under test. So am I adding my tests to the actual app and deploying them? If so, doesn't this bulk up it a bit? Do you suggest leaving the tests in for each release?

You can create a parallel package (preferably in a different project.) As long as the package name is the same the tests will run. The different project does not need to be deployed. (Projects apply to IDEs. If you aren't using an IDE, just use a different directory.)

Should we be versioning our tests along with the app?

Yes! If you ever have to go back and create a branch of the production application, you will want to have that version of what the tests looked like at the time.

In summary: version, but don't deploy.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another option would be to keep the tests inside the same project in your IDE but under different "source directory", like

You can also use Ant and naming standards to filter out the test code when building your production archive.
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my work...

I create TestCase Class in same package of source code ..


/src/com/spns/AddData.java
/src/com/spns/AddDataTestCase.java


Why I do this ???

Because I use CVS to control version of Source code in my application, so i don't create other package for testing class.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33673
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Somkiat,
I'm sure everyone who posted in response uses CVS or some other version control system. It's more of a question of building jars/ears without the test code. Either of the below two approaches allow you to version the code and keep it separate.


We used to use:
myproject/src/org/.../MyClass.java
myproject/test/src/org/.../MyClassTest.java


Recently we switched to:
myproject/src/org/.../MyClass.java
myproject.junit/src/org/.../MyClassTest.java


We had two reasons for switching to this:
1) It's easier to build an ear by hand (using WSAD) if the junit tests are both in a separate project.
2) JTest generates its tests in a separate project so we wanted to be consistent.
[ August 13, 2004: Message edited by: Jeanne Boyarsky ]
 
J. B. Rainsberger
author
Ranch Hand
Posts: 87
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are strong advantages and disadvantages to placing tests in the same source tree as production code, and in the same packages as production code. Fortunately, we discuss the options in detail in Chapter 3.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33673
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
J. B.,
I didn't realize that was in your book. Cool!
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We've also discussed the topic before in this very forum if someone feels like searching...
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic