can i move the dir src/test to the dir tests
xianyo opened this issue · 8 comments
when i set this:
androidTest {
setRoot('tests')
}
it do not work!
setRoot()
is not a method on the androidTest extension: https://github.com/robolectric/gradle-android-test-plugin/blob/master/src/main/groovy/org/robolectric/gradle/RobolectricTestExtension.groovy
Looking at the source for the plugin itself, it does not support custom path for the tests source and requires that your test source be in src/test/java/
or src/testVariantName/java
.
This breaks if you have overridden the project structure to work like previous build tools (e.g., sourceSets.main.java.srcDirs = ['src']
)
Actually the test source is pulled from here:
Sourceset: androidTest java source: /Users/clifton/dev/Multi/MultiAndroid/app/src/androidTest/java
The folder in question is "androidTest" not "test". Adding this to my build reveals where the test source is pulled from:
android.sourceSets.each {
println "Sourceset: ${it.name} java source: ${(it.java ? it.java.srcDirs.join(':'):'Null')}"
}
I haven't tried overriding or changing it yet. I'm posting a blog post about my findings later tonight here: http://codeforfun.wordpress.com
Search for the post "Learning Android Gradle Unit Testing"
The folder in question is "androidTest" not "test".
Not entirely true...
Again, I point to the source for where it generates the source set. It is iterating over TEST_DIRS
, and adding everything that it tries to look for that is valid/exists (presumably). TEST_DIRS
is defined as:
private static final String[] TEST_DIRS = ['test', 'androidTest']
So yes, src/androidTest/java
is one of the possible directories, but it actually looks for src/test/java
first. And more importantly: if both src/test/java
and src/androidTest/java
exist, it will actually use both source directories (which could lead to problems if you do have both).
Also of note: the source set for this plugin does not come from android.sourceSets -- it comes from javaConvention.sourceSets. And it does not try to intelligently set a default for that source set if it wasn't already defined -- it just blindly attempts to create it.
This is seriously frustrating. I cannot find any way to modify the test sourceSets path! :(
As an experiment, I renamed my working "src/test" folder to "src/testfoo".
gradlew clean test shows no tests run.
I try every possible valid combination [I can think of] to set the android test sourceSet srcRoot or srcDir or srcDirs to point to that "src/testfoo" folder, and it never picks it up.
wait... what ? AndroidTestPlugin:16
First of all, what's the point to run integration tests when you want just unit tests ? This result in errors like java.lang.RuntimeException: Stub! at android.test.ActivityTestCase.<init>(ActivityTestCase.java:5)
. Plus you have mixed dependencies now because androidTestCompile
stands for native Android tests and for Robolectric...
Secondly, why does it hardcoded ?
#59 addresses this issue