I have been struggling with unit-test-android problem for quite a long time. I have seen this, this and that, finally I found the gradle-android-test-plugin and even got it working. I can now run the tests with gradlew test
command.
But, writing those tests in IDE (Android Studio or IntelliJ 13) is far from comfortable, because it does not see the junit & Robolectric dependencies added with testCompile
dependency.
Is there any way to add these dependencies to the IDE classpath but still avoid to package them in the production app (thus, AFAIU compile
dependency cannot be used)?
I had the same problem with IntelliJ 14.1.3 today. The solution was to run the steps outlined here. Basically:
testCompile 'junit:junit:4.+'
, etzsrc/test/java/...
testXxx
, whereXxx
is the build-type (debug/release/etz).The important step here is the one in the "Build Variants" view. After you change it to "Unit Test", it will index and your libraries and full auto-completion are available.