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

  • SEARCH
  • Home
  • 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 6360709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:41:01+00:00 2026-05-24T23:41:01+00:00

I have a testng class which tests a class which in turns load property

  • 0

I have a testng class which tests a class which in turns load property from classpath.When i run maven install i am getting an error mentioning file not found.It is not able to find the property file though i have it in src/test/resources. How to resolve this issue?

the java code is having a constructor which tries to load the property file Properties props = JobUtils .loadProperties("x.properties"); my maven configuration:


<plugin>
  <groupId>org.apache.maven.plugins
  <artifactId>maven-surefire-plugin
  <version>2.5
  <configuration>
    <skipTests>false</skipTests>
  </configuration>
</plugin>

with:


<build>
  <testResources>
    <testResource>
      <directory>src/test/resources</directory>
      <filtering>false</filtering>
    </testResource>
  </testResources>
</build>

Also I have this x.properties in src/test/resource

Stack trace Running TestSuite is:


java.io.FileNotFoundException: x.properties (The system cannot find the file specified)
   at java.io.FileInputStream.open(Native Method)
   at java.io.FileInputStream.(FileInputStream.java:106)
   at java.io.FileInputStream.(FileInputStream.java:66)

Also note the test class i have tries to instantiate this java code and test it.

  • 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-24T23:41:02+00:00Added an answer on May 24, 2026 at 11:41 pm

    Your x.properties file from the src/test/resources directory is actually being copied to the target/test-classes directory after the Maven process-test-resources phase is executed. So if you want your application to be able to find it, you should use the following file-path:

    
    Properties props = JobUtils .loadProperties("target/test-classes/x.properties");
    

    However I do not think this is exactly what you are looking for. I recommend to read the property file directly from the CLASSPATH (without using the file-system directly) using a code like this:

    
    InputStream is = getClass().getResourceAsStream("/x.properties");
    Properties p = new Properties();
    try {
      p.load(is);
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      if (is != null) {
        try {
          is.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }
    

    Using this approach you will be able to load the property file even from within a JAR file distributed to the customer or also from a configuration file that is added to the CLASSPATH in some kind of a launch-script.

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

Sidebar

Related Questions

I'm using TestNG to run Selenium based tests in Java. I have a bunch
I have a test fixture class which is currently used by many tests. #include
I have a class which has some unit tests, but when I am running
Presume you have a class which passes all its current unit tests. If you
I have a base class that represents a database test in TestNG, and I
I have this CacheManager class which keeps a static dictionary with all sorts of
I want to write a unit test which tests the function of a class
I am unit testing mercurial integration and have a test class which currently creates
I have ExcelStepDefinition class in which are my steps for excel testing. I have
I have several integration tests for various services that extend the following baseclass: @ContextConfiguration(locations=classpath:applicationContext-test.xml)

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.