4

When running standard junit tests (not AndroidTestCase) in Android, how can I get resources in src/test/resources?

I have tried all the usual...

getClass().getResourceAsStream("/testData.dat");

and...

Thread.currentThread().getContextClassLoader() .getResourceAsStream("/testData.dat");

and also with gradle copy resources..

task copyTestResources(type: Copy) { from "${projectDir}/src/test/resources" into "${buildDir}/classes/test" }

What confuses me is when I ask in the unit test what the classloaders path is for getting resources using

ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); URL resource = classLoader.getResource(".");

It returns: /home/rob/Android/Sdk/platforms/android-17/data/res

Can anyone please explain this to me and tell me how I can get a relative path anywhere in the project so I can use test resources?

Rob McFeely
  • 2,823
  • 8
  • 33
  • 50

0 Answers0