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 6217311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:24:15+00:00 2026-05-24T07:24:15+00:00

One of my unit tests is driven by test data, stored in src/test/resources/testData.txt .

  • 0

One of my unit tests is driven by test data, stored in src/test/resources/testData.txt. Since Maven will copy the contents of src/test/resources to target/test-classes/ which is on the classpath, I can read that file conveniently from the classpath without caring about its absolute file name. So far, so good.

Now I’m in the process of witing some code that will update that file with data fetched from a remote system. That code will be run rarely, and not as part of the build. The updated file will be committed to the source repository. In order to append to the file, I need to know the path to the original file in src/test/resources (appending to the one in target/test-classes/ will obviously not work).

How do I determine that path in a portable way? I’d rather not hard code src/test/resources/, because those directory names may actually change. Also, this would break if executed with a current working directory other than my project base directory.

Any ideas?

  • 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-05-24T07:24:16+00:00Added an answer on May 24, 2026 at 7:24 am

    The best way would probably be with ${project.basedir}/src/test/resources. The test resource directory is unlikely to change, and it will safely resolve to the correct path regardless of your working directory. Trying to reference a test resource directory via a property is problematic because there can be, and often are, multiple test resources defined. How would you know which one to pick?

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

Sidebar

Related Questions

Using Visual Studio 2008 for a unit test, one of the unit tests has
Should one create unit tests involving IO? Ie, testing a class method for serializing/deserializing
One of our unit tests is to populate properties within our business objects with
I'm getting NoPrimaryKeyException when I try to run one of my unit tests which
I want to create unit tests for one of my project's classes but I'm
How does one unit test that a new thread was spawned for a Runnable
How does one write a unit test that fails only if a function doesn't
What Makes a Good Unit Test? says that a test should test only one
I am trying to write a unit test for my one controller to verify
I have 2 projects each one with its own unit test project, and one

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.