In my unit tests I want to create a tmp directory inside the ${project.build.directory}. How can I access the value of ${project.build.directory} inside my unit test?
One way, which I could think of, is to provide a filtered properties file in the test resources, which holdes that value. (I haven't tried yet, but I think that should work.)
Is there a direct way to access/ pass this property value?
sourceDirectory , scriptSourceDirectory , and testSourceDirectory provide access to the source directories for the project. outputDirectory and testOutputDirectory provide access to the directories where Maven is going to put bytecode or other build output.
The target directory is used to house all output of the build. The src directory contains all of the source material for building the project, its site and so on. It contains a subdirectory for each type: main for the main build artifact, test for the unit test code and resources, site and so on.
${project. basedir} is the root directory of your project.
JUnit is the testing framework that is extensively used for java projects built in the maven project format for unit testing purposes. Here we will see how we can mention the JUnit dependency in pom. xml file in a maven project and see various annotations and assert methods that can be used in java projects.
I've used something like this with some success before. The unit test will still run even if not using Maven, the target directory will still get created two dirs up relative to the cwd of wherever the tests are run.
public File targetDir(){ String relPath = getClass().getProtectionDomain().getCodeSource().getLocation().getFile(); File targetDir = new File(relPath+"../../target"); if(!targetDir.exists()) { targetDir.mkdir(); } return targetDir; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With