The Android gradle build forces my AndroidTests to be in src/androidTests. How do I change this to be another directory of my choosing?
Here is some background: I am migrating a project from eclipse.
According to the build documentation, when I add this to my gradle build file:
androidTest.setRoot('tests')
The android gradle build does this: "Note: setRoot() moves the whole sourceSet (and its sub folders) to a new folder. This moves src/androidTest/* to tests/*"
That is great for the build and makes it run just fine.
However, it forces my project structure to put my androidTests within: src/AndroidTest. This makes Eclipse unable to compile because it thinks all the test code should be in a package called androidTests.com.etc.etc.etc...
I'd like to set some property like this:
androidTest { java.srcDirs = ['tests'] }
A typical project in Android Studio contains two directories in which you place tests. The androidTest directory should contain the tests that run on real or virtual devices. Such tests include integration tests, end-to-end tests, and other tests where the JVM alone cannot validate your app's functionality.
By default, the source files for local unit tests are placed in module-name/src/test/ . This directory already exists when you create a new project using Android Studio.
By default, Android Studio provides a source code directory at src/androidTest/java/ to place your instrumented and UI tests.
androidTest.setRoot('tests')
will reset the root of the sourceSets so that
tests/java
tests/res
You can configure those separately though with
android {
sourceSets {
androidTest {
java.srcDirs = ['tests']
}
}
}
Note: this uses android.sourceSets
because the Android plugin uses custom sourceSets.
There are slight variations on how to do this. Putting the following in my build.gradle file worked for me:
android {
sourceSets {
androidTest{
java.srcDir file('src/tests/java')
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With