0

Application runs in production environment and there is no change in code since long time.

After setting up application in eclipse in local machine, I am trying to run JUnits and they are failing due to resources file not found located in src/test/resources folder in Java maven project directory.

java.io.FileNotFoundException: File 'C:\[redacted]\target\test-classes\sample.txt' does not exist

In code, files are read through below code.

String content = IOUtils.toString(openInputStream(this.getClass().getClassLoader().getResource(filename).getPath()), "UTF-8")

NOTE: application has been set up before also without any issue of JUnits. application is passed through Jenkin build JUnit check also. I am able to run my application in eclipse.

So there should be something missing at eclipse setting or build path. Please guide me.

Jim Garrison
  • 85,615
  • 20
  • 155
  • 190
KJ21
  • 63
  • 7
  • Q: do you have a "" entry in your Maven pom.xml? Look here: https://stackoverflow.com/a/18082816/421195 – paulsm4 Jan 06 '22 at 22:31
  • `C:*\target\test-classes\sample-*.txt` I don't think the leading asterisk in the path will work here unless you're using a path matcher. – Jim Garrison Jan 06 '22 at 22:36
  • asterisk was placed only to hide real folder structure. I updated it in my question – KJ21 Jan 06 '22 at 22:49
  • 1
    Does this answer your question? [How to read a text-file resource into Java unit test?](https://stackoverflow.com/questions/3891375/how-to-read-a-text-file-resource-into-java-unit-test) – Anass ABEA Jan 06 '22 at 22:52
  • I've tried all other options. I was able to run JUnits some months before without any issues. No code changes since then. Now there is some issue with eclipse or build path. – KJ21 Jan 06 '22 at 22:57

0 Answers0