Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8606087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:00:43+00:00 2026-06-12T03:00:43+00:00

I have written a unit test that writes a file to the file-system, given

  • 0

I have written a unit test that writes a file to the file-system, given no path it writes to the working directory; so if executed from the project directory it writes in the project root, if in the projects parent directory it writes to the parents root directory.

So what is the correct way to write to the target directory? Quite possibly a directory inside the target directory?

If I quite simply specify target/ with the file it will write to the parent projects target instead of the projects target.

UPDATE: I actually want the file after the test finishes. The file is for an extraction format for third-parties that needs to be sent to the third parties. The test can be switched on/off to allow me to only run if the format of the file changes for re-approval. It’s not a huge problem where the file goes, but I would like something that’s easy to find.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T03:00:45+00:00Added an answer on June 12, 2026 at 3:00 am

    You could try to use TemporaryFolder JUnit @Rule as described here

    The TemporaryFolder creates a folder in the default temporary file directory specified by the system property java.io.tmpdir. The method newFile creates a new file in the temporary directory and newFolder creates a new folder.

    When the test method finishes, JUnit automatically deletes all files and directories in and including the TemporaryFolder. JUnit guarantees to delete the resources, whether the test passes or fails.


    After Question Updated

    You can change the working directory used by maven-surefire-plugin.

    <plugins>
        [...]
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.12.3</version>
            <configuration>
              <workingDirectory>${project.build.directory}</workingDirectory>
            </configuration>
          </plugin>
        [...]
    </plugins>
    

    You can change that working directory to anything you need for your tests like ${project.build.directory}/my_special_dir/.

    The working directory in surefire plugin only affects tests being run and ONLY for tests being conducted by maven. If you run your tests from within an IDE the working directory will be something else.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a unit test with MD 2.8.5 in a project that includes
I have different projects written in .NET 3.5 and some unit test projects to
I have some unit tests I've written to test my Django application. One test
I have a large simulation written in C++. The main working unit for the
I have written a function that sorts a big scale of data. To test
I have written an application that unit tests our hardware via a internet browser.
I have several session beans that I have written unit tests for. I have
Im writting unit test for a WCF service which i have written. The thing
I have written a unit test to comfirm the Dispose on my class does
I have a Python (Django) unit test FAIL from an exception, but the failing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.