I want to specify dependencies for my tests and after reading the Gradle Dependency Management Basics I though I could just add testCompile
calls to my dependen
Just to make this question answered in full this is what is needed to resolve the issue. Since Junit is wanted for local testing and guava might be wanted for androidTest the android DSL should contain this:
android {
:
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src/main/java']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
:
}
test {
java.srcDirs = ['src/test/java']
resources.srcDirs = ['src/test/resources']
:
}
androidTest.setRoot('tests')
}
:
}
The : means other statements that you need. Please also note that the folders can be others than the ones above.
The android build system doesn't use the standard Gradle Java plugin.
Its documentation says:
As mentioned previously, next to the main sourceSet is the androidTest sourceSet, located by default in src/androidTest/
Additionally, the sourceSet can be configured to have its own dependencies. By default, the application and its own dependencies are added to the test app classpath, but this can be extended with
dependencies {
androidTestCompile 'com.google.guava:guava:11.0.2'
}
Update
As of May 2017 Doc,
testCompile
is deprecated and you should usetestImplementation
dependencies {
androidTestImplementation 'com.google.guava:guava:11.0.2'
}