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 dependency declarations like this:
dependencies { compile group: 'com.squareup.dagger', name: 'dagger', version: '1.0.0' testCompile group: 'junit', name: 'junit', version: '4.11' testCompile group: 'com.squareup', name: 'fest-android', version: '1.0.1' }
This, however, fails with this error message:
> Could not find method testCompile() for arguments [{group=junit, name=junit, version=4.11}] on project ':simstatus'.
Am I missing something here?
(Full gradle build file for reference)
To add a dependency to your project, specify a dependency configuration such as implementation in the dependencies block of your module's build. gradle file. This declares a dependency on an Android library module named "mylibrary" (this name must match the library name defined with an include: in your settings.
Gradle build script defines a process to build projects; each project contains some dependencies and some publications. Dependencies refer to the things that supports in building your project, such as required JAR file from other projects and external JARs like JDBC JAR or Eh-cache JAR in the class path.
In your Gradle project, in the editor, create or select a test to run. From the context menu, select Run <test name>. icon in the left gutter. If you selected the Choose per test option, IntelliJ IDEA displays both Gradle and JUnit test runners for each test in the editor.
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' }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With