Separating in-VM Unit Tests and Remote Tests with Maven

by Robert Cooper

After jumping through some hoops with my neighbor on a "How do I make Maven do this issue", I believe we have officially found a better way to package in-VM unit tests and remote unit/integrations tests into a single Maven project. The trick is one property on the test plug in and one property that isn't even documented on the properties page! Sometimes actually looking at the jelly file pans out.

The trick is:

/src/java
/src/test <-junit tests
/src/remote-test <- SOAP/JWebUnit/HTTPUnit etc.

Set: <unitTestSourceDirectory>src/test</unitTestSourceDirectory> and <includes><include>**/*Test.java</include></includes> or your preferred pattern.

Next, add maven.test.compile.src.set=src/test/remote-test to the project.properties.

Finally, you can define a goal, or set as a post-goal to tomcat:deploy, for example, in your maven.xml file:
<goal name="remote-test">
<ant:property name="maven.test.search.classdir" value="true" /><attainGoal name="test:test" /></goal>
or run maven from the command line as
maven -Dmaven.test.search.classdir=true test:test
to pick up the remote tests.