使用 Gradle Android 构建系统指定测试依赖项 [英] Specifying test dependencies with the Gradle Android build system

查看:40
本文介绍了使用 Gradle Android 构建系统指定测试依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在阅读Gradle Dependency Management Basics 之后,我想为我的测试指定依赖项 我虽然可以像这样将 testCompile 调用添加到我的依赖声明中:

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?

(完整的gradle构建文件供参考)

推荐答案

android 构建系统不使用标准的 Gradle Java 插件.

The android build system doesn't use the standard Gradle Java plugin.

其文档 说:

如前所述,主sourceSet旁边是androidTest sourceSet,默认位于src/androidTest/

As mentioned previously, next to the main sourceSet is the androidTest sourceSet, located by default in src/androidTest/

此外,可以将 sourceSet 配置为具有自己的依赖项.默认情况下,应用程序及其自身的依赖项被添加到测试应用程序的类路径中,但这可以通过

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'
}

更新

截至 2017 年 5 月文档testCompile已弃用,您应该使用 testImplementation

As of May 2017 Doc, testCompile is deprecated and you should use testImplementation

dependencies {
        androidTestImplementation 'com.google.guava:guava:11.0.2'
}

这篇关于使用 Gradle Android 构建系统指定测试依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆