aspose file tools*
The moose likes Testing and the fly likes JB: Leave tests in app for deployment? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "JB: Leave tests in app for deployment?" Watch "JB: Leave tests in app for deployment?" New topic
Author

JB: Leave tests in app for deployment?

Michael Sullivan
Ranch Hand

Joined: Dec 26, 2003
Posts: 235
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

Joined: May 26, 2003
Posts: 30771
    
156

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
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.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
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.


SCJA,SCJP,SCWCD,SCBCD,SCEA I
Java Developer, Thailand
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30771
    
156

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

Joined: Aug 05, 2004
Posts: 87
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.


Author of <a href="http://www.amazon.com/exec/obidos/ASIN/1932394230/ref=jranch-20" target="_blank" rel="nofollow">JUnit Recipes: Practical Methods for Programmer Testing</a>
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30771
    
156

J. B.,
I didn't realize that was in your book. Cool!
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
We've also discussed the topic before in this very forum if someone feels like searching...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: JB: Leave tests in app for deployment?