Reputation: 543
The androidTest appeared on my Android Studio when the Test Artifact was switched to Android Instrumentation Test. However, when the Test Artifact was switched back to Unit Test. The entire androidTest folder disappear. This project was a migration from Eclipse. I have multiple flavor for my project.
Gradle.build
sourceSets {
main {
// manifest, java, renderscript, aidl, assets, res detail etc etc
}
flavour1 {
// manifest, java, renderscript, aidl, assets, res detail etc etc
}
flavour2 {
// manifest, java, renderscript, aidl, assets, res detail etc etc
}
flavour3 {
// manifest, java, renderscript, aidl, assets, res detail etc etc
}
flavour4 {
// manifest, java, renderscript, aidl, assets, res detail etc etc
}
androidTest.setRoot('tdd/test')
androidTest {
java.srcDirs = ['tdd/test/java']
}
}
I don't understand why it disappear for Unit Test but appear for Android Instrumentation Test.
Upvotes: 1
Views: 1832
Reputation: 543
I believe this is the answer. I managed to create the test folder even in Unit Test Artifact. When there are multiple variants of the application, Gradle doesn't know the project structure causing it to lose the ability to detect Unit Test and Instrumentation Test. So in order to implement Unit Test, add test method within the android method in build.gradle; as for Android Instrumentation Test, add androidTest method within the android method in build.gradle;
Example:
build.gradle
sourceSets {
test.setRoot('anydir') // for Unit Test
androidTest.setRoot('anydir') // for Android Instrumentation Test
}
The above code is only needed if Android Studio is unable to recognised your test folder since you have multiple variants and you changed the directory of your java code.
Upvotes: 1