views:

172

answers:

3

I build all my web projects at work using RAD/Eclipse, and I'm interested to know where do you guys 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 folder 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 guys handle this.

Thanks.

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 guys know how to get a Mavenized project to work with Webpshere, do let me know too.

alt text

+1  A: 

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

Pascal Thivent
This is rather embarrassing, but I have problem attaching my screenshot on my above post. Anyhow, I think this is probably RAD's problem. I tried the same thing in Eclipse Galileo, and yes, I'm not getting any warning. I'm using RAD v7.5.5, by the way.
limc
@limc: It sounds like a RAD "issue" indeed. The strange part is that I know that you can use RAD with Maven projects (which is what I'm doing with Eclipse). But maybe people get this warning when they do so, I can't confirm this.
Pascal Thivent
@pascal: okay, I finally got the screenshot up in my post. RAD works fine with Maven, provided it is not a web project. I can't get hot deploy to work against Websphere from a Maven project, plus I currently creates the IBM xmi files by hand to get my JNDIs to work in Websphere. Of course, the whole "hacking" thing is so brittle, so know who this whole thing will work when I move to WAS 7 in the future. My goal is to set up my project using Maven, and do my development against Jetty, then I'll ear it up and deploy it in Websphere... and pray.
limc
@limc I was not aware of this "restriction" with RAD (and I guess it's a soft restriction or it would totally disallow it but I have no idea of the consequences). By the way, the sample project on my screenshot is a webapp project. Regarding the other part (doing development on Tomcat/Jetty/GlassFish), this is pretty common, especially when using a slow container. If you are not using specific stuff (i.e. if you are using standard Java EE stuff), it should be ok. Just do deploy regularly on the target container to avoid any bad surprise.
Pascal Thivent
+2  A: 

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.

Alexander Pogrebnyak
Maven (or Ivy) can handle this for you. You can scope the dependencies as Test.
Jeff Storey
I wish I can use Maven for my work projects, but the fact is it doesn't work well with Websphere to begin with, or at least, I can't get Maven to play nice with it. My current project structure is like a bastardized version of Maven project, it looks like a Maven project but it is not. I have an ANT script that invokes a "mvn war:exploded" then programatically copy all the jars into the WebContent/WEB-INF/lib in my dynamic web project. Right now, I'm just bummed that RAD sees several output folders as a potential problem.
limc
+1  A: 

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.

Bruno Rothgiesser