Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven: change the directory in which tests are executed

Tags:

maven

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

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?

Thanks

like image 930
yelo3 Avatar asked Jul 18 '11 13:07

yelo3


People also ask

Where does Maven store test results?

By default, these files are generated at ${basedir}/target/surefire-reports . As such, after the tests are executed, you just need to open those reports in Eclipse by double-clicking them.

How do I disable surefire report in Maven?

skipSurefireReport: If set to true the surefire report generation will be skipped. https://maven.apache.org/surefire/maven-surefire-report-plugin/report-mojo.html#skipSurefireReport. this code will skip the surefire tests.

How do I exclude test cases in Maven?

To skip running the tests for a particular project, set the skipTests property to true. You can also skip the tests via the command line by executing the following command: mvn install -DskipTests.


1 Answers

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> 

Reference: 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> 
like image 198
kaliatech Avatar answered Sep 28 '22 08:09

kaliatech