0

I am new to IntelliJ IDEA and I am trying to use specific files for my unit tests, but it seems that these cannot be found. I have built a special project/module to "reduce" the error in a totally clean setting to make sure that I don't miss something, however, it still does not work.

My file structure (as shown in the screenshot): .../test/jave/FooTest.java .../test/resources/test.txt

Folder ".../test/resources" has been marked as "Test Resources Root". However, when the test runs, file could not be found.

Screenshot of error when running test in a reduced program

I suppose that marking the folder as "Test Resources Root" should add all its files in the path. Isn't this right?

PS. I have seen this post but even adding the folder as a dependency did not work.

Pantelis Natsiavas
  • 5,293
  • 5
  • 21
  • 36

1 Answers1

0

To get a file from the resources folder, You can use any approach given here:https://www.baeldung.com/junit-src-test-resources-directory-path

File("test.txt").exists();

Will return true when your file located at ...\project_name\test.txt. Check by

File("test.txt").getAbsolutePath(); 
Darshana
  • 601
  • 2
  • 9
  • 20
  • Thank you very much for the guidance. However, I am still wondering, if marking the folder as "Test Resources Root" does not add it to my path, then what is the point of marking it? Am I missing something? – Pantelis Natsiavas Jun 01 '20 at 13:50
  • I never use IntelliJ IDEA so I don't know what it will do when we mark Test Resources Root. Does it add set up in pom file? I used eclipse. – Darshana Jun 02 '20 at 17:12