I wrote several JUnit tests for the Android project (Cordova), and so far I have managed to run them both from the gradle command line and in Android Studio (1.2.2).
When I added the code loading the properties file (using this.getClass().getClassLoader().getResourceAsStream() ), the code worked on the Android device and the tests were still running from the gradle command line, getResourceAsStream () returns null when I I run tests in Android Studio.
Has anyone successfully been able to load property files this way and then test them in Android Studio?
The gradle configuration for the cordova project contains this for installing a set of test sources:
subprojects { if (project.hasProperty("android")) { android.sourceSets { main { manifest.srcFile 'AndroidManifest.xml' java.srcDirs = ['src'] resources.srcDirs = ['src'] aidl.srcDirs = ['src'] renderscript.srcDirs = ['src'] res.srcDirs = ['res'] assets.srcDirs = ['assets'] jniLibs.srcDirs = ['libs'] } test { java.srcDir file('test') resources.srcDir file('test') } } }
I understand that loading a properties file into a unit test is not the best practice, but because of the nature of this project, I wanted to use a properties file rather than mock the values.
source share