Environment: maven 2.0.8, surefire 2.4.1,2.4.2
We are running tests using Surefire 2.4.1 and Maven 2.0.8. The Junit test classes are expecting to load a properties file from
src/test/resources with the same name as a properties file in src/main/resources to load test data etc. However the src/main/resources properties file is being loaded.
Looking at the debug output shows:
[DEBUG] Test Classpath :
[DEBUG] C:\Documents and
Settings\benl\.m2\repository\junit\junit\4.2\junit-4.2.jar
[more jars]
[DEBUG] c:\Development\Projects\MyProject\target\classes
[DEBUG] c:\Development\Projects\MyProject\target\test-classes
Which would explain it. Setting childDelegation to true doesn't get the test-classes before classes in the classpath order.
I generated the effective-pom and used it in a copy of the Surefire integration test for the classpath order (http://svn.apache.org/repos/asf/maven/surefire/trunk/surefire-integration-tests/src/test/resources/classpath-order
). The tests failed. I then trawled through the project POM and then its parent POM commenting out plugins, reporting, dependencies, and other bits until the test passed.
The thing that was causing the test to fail was that in the parent POM:
<defaultGoal>package</defaultGoal>
<directory>target</directory>
<finalName>${pom.artifactId}-${pom.version}</finalName>
<sourceDirectory>${basedir}/src/main/java</sourceDirectory>
<testSourceDirectory>${basedir}/src/test/java</testSourceDirectory>
<testOutputDirectory>${basedir}/target/test-classes</testOutputDirectory>
<outputDirectory>${basedir}/target/classes</outputDirectory>
Changing just testOutputDirectory to
<testOutputDirectory>target/test-classes</testOutputDirectory>
Made the tests pass. I've no idea why.