I have an Android project (generated by Cordova) that I want to add (instrumentation) tests to. It has only one MainActivity.java
that should be tested.
Normally this means adding some dependencies to build.gradle
and creating a file /src/androidTest/java/org/example/package/MainActivityTest.java
with an MainActivityTest
class and some test methods. (In Android Studio I can even generate those by using Run -> "Record Espresso Test" - so really simple and works).
Unfortunately, I now have the requirement that those test files do actually live outside the project directory. There should be only minimal changes on the existing Cordova project (as it is regenerated and handled as a build artifact). The MainActivity.java
would best be in the same root folder where the Android project is in /android
.
How can I achieve that?
The build.gradle
changes can be added to a build-extras.gradle
file that the real build.gradle
already includes, so this is taken care of.
But I have no idea how to place the MainActivityTest.java
outside of the project folder structure and still be able run it inside the project.
For iOS you can link external files into the project with absolute paths. Something like that would be perfect here as well.
I looked at sourceSets
but I am not sure how to integrate this in the Cordova Android project which already has this non default (I think?) sourceSets
:
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']
}
}
...
}