Reputation: 21258
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)?
Upvotes: 5
Views: 2297
Reputation: 26709
In IntelliJ IDEA you need to configure couple things in your build.gradle
// add idea plugin
apply plugin: 'idea'
// make sure `configurations.testCompile` is added to idea.module
idea {
module {
scopes.TEST.plus += [ configurations.testCompile ]
}
}
For more info see: http://www.gradle.org/docs/current/dsl/org.gradle.plugins.ide.idea.model.IdeaModule.html
Any dependency included with testCompile
will be automatically imported into IDEA.
Upvotes: 0
Reputation: 25755
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
, where Xxx
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.
Upvotes: 1
Reputation: 15029
You can use the built-in idea
plugin. That should set up test dependencies for you. You'll need to import the plugin:
apply plugin: 'idea'
Then run gradle idea
, to generate module file (*.iml
) and re-load your project. Note you'll have to be using non-directory based idea configuration for this to work.
Upvotes: 0
Reputation: 2581
For my Android test dependencies, I use instrumentTestCompile instead of testCompile. This works for me when running my tests in Android Studio. Hope this helps.
Upvotes: 0