I have an Android app using the new standard gradle layout:
src / main / java
src / main / resources
src / instrumentTest / java
src / instrumentTest / resources
I have a unit test in src/instrumentTest/java/com/example/MyUnitTest.javathat reads a file located in src/instrumentTest/resources/testfile.json
- First question: the right place to place test files?
- Second question: how can I read this file in String?
I tried these two ways to read the file in unit test without success (it cannot find the file):
String myJson = new Scanner (new File ("testfile.json"), "UTF-8"). UseDelimiter ("\\ A"). Next ();
String myJson = new Scanner (new File ("resources / testfile.json"), "UTF-8"). UseDelimiter ("\\ A"). Next ();
Hooray!