Maven:更改执行测试的目录 [英] Maven: change the directory in which tests are executed
问题描述
在我的代码中,我设置为在./
目录中创建一些文件,因为当将软件部署到安装机器中时,如果是第一次运行,则所有配置文件都将在./
中创建
In my code I have set to create some files in ./
directory, because when the software will be deployed in the installation machine, all the configuration files will be created in ./
if it's the first run
不幸的是,当我构建项目并由Maven执行测试时,所有文件都在项目目录中创建.
我希望在target/test-run/
中创建这些文件
我该怎么办?
Unfortunately when I build the project, and Maven executes tests, all the files are created in the project directory.
I want those files to be created in target/test-run/
How can I do it?
谢谢
推荐答案
如果您使用的是surefire插件来执行测试(这是默认设置),则可以这样设置工作目录:
If you are using the surefire plugin to execute tests (which is the default), then you can set working directory like this:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.7.2</version>
<configuration>
<workingDirectory>${java.io.tmpdir}</workingDirectory>
</configuration>
</plugin>
</plugins>
</build>
参考: http://maven.apache.org/plugins/maven-surefire-plugin/test-mojo.html
要设置为问题中的特定目录:
To set to the specific directory in the question:
<workingDirectory>${project.build.directory}/test-run</workingDirectory>
这篇关于Maven:更改执行测试的目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!