Issue
I have the default src/test/java
folder for our unit tests. A separate folder src/integration/java
is available for the integration tests.
I configured the maven-surefire-plugin
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 test-classes
but I want to compile the classes from src/integration/java
into target/integration-test-classes
. 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 **/it/**
files from the default test phase, and exclude all **/unit/**
from the integration phase.
Solution
Sorry, there's no way of doing that, even when considering some hacking. The concept here is there's only one target directory for compiled classes and one for compiled test classes (even the single <build>
tag 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.
I think that what you really want to do is actually to create the integration tests module. That's the common practice, by the way. So far I've always had separate integration testing module and never have had any problems with it. You should depend on all modules needed to run these tests. You can even depend on other module's test classes by using <type>test-jar</type>
within your dependency declaration, as mentioned here:
http://maven.apache.org/guides/mini/guide-attached-tests.html
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.
Answered By - MichaĆ Kalinowski