我的项目中的Junit需要从类路径加载属性文件。如何指定这些属性文件的目录,以便Maven在运行测试之前在类路径中进行设置?
发布于 2009-08-24 21:26:26
您可以使用build-helper-maven-plugin指定其他测试资源目录,如下所示。使用以下配置,在generate-test-sources阶段,test-resources目录的内容将被复制到target/test-classes目录:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.12</version>
<executions>
<execution>
<id>add-test-resource</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-resource</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>path/to/additional/test/resources</directory>
<excludes>
<exclude>**/folder-to-exclude/**</exclude>
</excludes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>发布于 2013-07-03 23:59:57
您还可以添加新的测试资源文件夹。
<build>
<testResources>
<testResource>
<directory>${project.basedir}/src/test/resources</directory>
</testResource>
<testResource>
<directory>${project.basedir}/src/test/something_else</directory>
</testResource>
</testResources>
</build>第一个路径src/test/resources是默认路径。假设您仍然希望使用默认路径,请确保将其包含在内。( testResources标记会覆盖您的默认值,所以如果您没有显式包含默认路径,它将停止使用。)
发布于 2009-08-25 13:40:06
如果您只想将属性文件放在磁盘上的某个位置,并且不想在构建过程中将这些属性文件复制到target/test-classes,那么可以这样做
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<additionalClasspathElements>
<additionalClasspathElement>/add/this/to/path</additionalClasspathElement>
</additionalClasspathElements>
</configuration>
</plugin>https://stackoverflow.com/questions/1324767
复制相似问题