codevour codevour - 1 year ago 72
Java Question

Howto add another test source folder to Maven and compile it to a separate folder?

I have the default

folder for our unit tests. A separate folder
is available for the integration tests.

I configured the
to execute the unit/integration tests in their respective phases. This works great when the compiled classes are in the correct directory. Unfortunately Maven only supports one test source folder and one test output folder.

With mavens build-helper plugin I could add another test-source folder but the compiled classes will be generated into
but I want to compile the classes from
. Is this possible?

src/test/java > target/test-classes
src/integration/java > target/integration-test-classes

PS: I don't like this exclude/include on package base solution (exclude all
files from the default test phase, and exclude all
from the integration phase.

Answer Source

Sorry, there's no way of doing that, IMHO even with some hacking in mind. The concept is that there's only one target directory for compiled classes and one for compiled test classes (even <build> tag schema exposes this). To be honest, I don't really think it should be possible with Maven. Maven promotes straight, clean and legible design of your application, by using well-crafted modules.

If think what you really want to do is to actually create integration tests module. That's the common practice, in fact. So far I always had separate integration testing module and never had problems with that. You should of course depend on all needed modules to run these tests. You can even depend on other module's test classes by using <type>test-jar</type> with your dependency declaration as mentioned here:

I don't like this method, however, and usually prefer to have separate module with testing support stuff, like base classes for JUnit test cases etc.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download