Mic*_*rth 38
您还可以添加新的测试资源文件夹.
<build>
<testResources>
<testResource>
<directory>${project.basedir}/src/test/resources</directory>
</testResource>
<testResource>
<directory>${project.basedir}/src/test/something_else</directory>
</testResource>
</testResources>
</build>
Run Code Online (Sandbox Code Playgroud)
第一个路径src/test/resources是默认路径.假设您仍然希望使用默认路径,请确保包含它.(testResources标记会覆盖您的默认值,因此如果您没有明确包含默认路径,它将停止使用.)
Ric*_*ler 35
您可以使用build-helper-maven-plugin指定其他测试资源目录,如下所示.使用下面的配置,test-resources目录的内容将在generate-test-sources阶段复制到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>
Run Code Online (Sandbox Code Playgroud)
sal*_*sal 25
如果您只想将属性文件放在磁盘上的某个位置,并且不希望在构建期间将这些属性文件复制到目标/测试类,则可以这样做
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<additionalClasspathElements>
<additionalClasspathElement>/add/this/to/path</additionalClasspathElement>
</additionalClasspathElements>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
小智 5
如果您有多个资源环境,您可以使用maven配置文件并根据您正在测试的配置文件放置各种资源。
test/resources/uat
test/resources/prod
test/resources/dev
Run Code Online (Sandbox Code Playgroud)
但通常如果您需要进行集成测试,那么您不需要 build-helper-maven-plugin。