2

I have some files in src/main/resources. During the main program run, I can load them fine using Source.fromResource(pathWithoutSlash). But in tests, if I try to use the same method to load them, it returns null unless I copy over the files to src/test/resources. This is an issue for some large sized files.

Any ideas how to fix this?

Ali
  • 261,656
  • 265
  • 575
  • 769
  • seems to be a duplicate of this: [How to read from test resources](https://stackoverflow.com/questions/46921715/how-to-read-files-from-test-resources-with-scalatest) – proximator Aug 13 '18 at 13:34
  • That question never got any answers – Ali Aug 13 '18 at 13:37
  • I tried it in my intellij, it is working fine. Are you using mvn or sbt? – proximator Aug 13 '18 at 13:58
  • @proximator sbt , this is my build.sbt: https://gist.github.com/aliakhtar/97bd7967499ab48f4860b81ffdc981e4 – Ali Aug 13 '18 at 14:04
  • During tests, by default, `Source.fromResource("hello/world.txt")` will try and use `src/test/resources/hello/world.txt` and if it doesn't exist, then this will default in using `src/main/resources/hello/world.txt`. Tried again with scala 2.12.2, seems to work fine. – Xavier Guihot Aug 13 '18 at 17:53

0 Answers0