Where should test classes be stored in the project?
I build all my web projects at work using RAD/Eclipse, and I'm interested to know where do you normally store your test's *.class files.
All my web projects have 2 source folders: "src" for source and "test" for testcases. The generated *.class files for both source folders are currently placed under WebContent/WEB-INF/classes folder.
I want to separate the test *.class files from the src *.class files for 2 reasons:-
- There's no point to store them in WebContent/WEB-INF/classes and deploy them in production.
- Sonar and some other static code analysis tools don't produce an accurate static code analysis because it takes account of my crappy yet correct testcase code.
So, right now, I have the following output folders:-
- "src" source fol开发者_开发百科der compiles to WebContent/WEB-INF/classes folder.
- "test" source folder compiles to target/test-classes folder.
Now, I'm getting this warning from RAD:-
Broken single-root rule: A project may not contain more than one output folder.
So, it seems like Eclipse-based IDEs prefer one project = one output folder, yet it provides an option for me to set up a custom output folder for my additional source folder from the "build path" dialog, and then it barks at me.
I know I can just disable this warning myself, but I want to know how you handle this.
Updates
I attached a screenshot of one of my projects' build path dialog. I'm using RAD v7.5.5. It seems like most of you build your projects with Maven. I love to use Maven, I use Maven anywhere else but work because it doesn't play nice with Websphere. If you know how to get a Mavenized project to work with Webpshere, do let me know too.
alt text http://www.imagebanana.com/img/89q9o46t/s1.jpg
I have opted for a separate TEST project to coexist with a SOURCE project.
This way you can add extra dependencies for your test project, for example some 3rd party libraries that you need for testing only, and not add this dependency on your regular project.
Say that the class being tested is com.example.MyClass
. I would put the test MyClassTest
in the same package com.example
, but in a separate folder test
:
module
/ \
src -> target <-
/ \
main test
| |
java java
| |
com com
| |
example example
| |
MyClass.java MyClassTest.java
This is Maven's Standard Directory Layout.
But you can compile the class files for tests and main classes to the same output folder target
.
I don't know for RAD but I can tell you that all my projects use a separate output folder for tests and test resources without any problem under Eclipse:
alt text http://www.imagebanana.com/img/9c8m79s/screenshot_008.png
精彩评论