I have maven project X which depends on project Y. when I run the tests on project X, it is not able to 开发者_Go百科find the test files in project Y although it is in the class path.
The usual convention in Maven is to have the unit tests localy to your project which means you can't use classes from outside the current project. This is coming also from the point that the test class will not be packaged into a jar in contradiction to the production code (src/main/java). But you can solve the problem by defining the class you would like to reuse like the following (project Y):
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
You have to do mvn install (or may be mvn deploy) and in project Y you have to use the above by defining it like the following:
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>test</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
精彩评论