There's a known bug in Android Studio where the app's ressources aren't available from within test classes.
The solution according to aforementioned thread is to put the following lines into the build.gradle:
task copyTestResources(type: Copy) {
from "${projectDir}/src/test/resources"
into "${buildDir}/classes/test"
}
processTestResources.dependsOn copyTestResources
but gradle says:
Error:(132, 0) Could not find property 'processTestResources' on project ':app'.
Where exactly do I have to put the line
processTestResources.dependsOn copyTestResources
within my build.gradle?
EDIT:
I didn't have apply plugin: 'java'
in my build files yet. The problem is that in my app module's build gradle, I already have apply plugin: 'android'
and trying to add the java plugin leads to
Error:The 'java' plugin has been applied, but it is not compatible with the Android plugins.
I tried puttin apply plugin: 'java'
in the top level build file and then
task copyTestResources(type: Copy) {
from "${projectDir}/app/src/test/resources"
into "${buildDir}/classes/test"
}
Note that I added the modules directory to the from-line. This builds fine, but unit tests that need to access ressources still don't work.