简体   繁体   English

找不到Gradle DSL方法:testCompile()

[英]Gradle DSL Method not found: testCompile()

Hi I am working on a project and have reached a stage where it would be unwise to continue without unit testing. 嗨,我正在研究一个项目,并且已经达到了一个阶段,如果没有单元测试,继续进行下去是不明智的。 I thought unit testing in Android Studio would be straight forward but I can't run my tests. 我以为Android Studio中的单元测试会很简单,但是我无法运行测试。

Here are my dependencies. 这是我的依赖项。 Everything works fine until I add the last line of code. 一切正常,直到我添加了最后一行代码。 I then receive the error message that is in the title. 然后,我收到标题中的错误消息。

在此处输入图片说明

How do I fix this and run my tests? 如何解决此问题并运行测试?

Here was the tutorial I was following: http://tools.android.com/tech-docs/unit-testing-support 这是我正在关注的教程: http : //tools.android.com/tech-docs/unit-testing-support

Official Unit testing support was introduced in Android plugin starting from version 1.1. 从版本1.1开始,Android插件中引入了官方的单元测试支持。 This means that testCompile configuration is not available on previous versions. 这意味着testCompile配置在以前的版本中不可用。 Based on your comment, you are using Android Gradle plugin version 1.0.0. 根据您的评论,您正在使用Android Gradle插件版本1.0.0。 That's why your build complains about missing testCompile configuration. 这就是为什么您的构建抱怨缺少testCompile配置。

As of today, the latest released Android Gradle plugin version is 1.3.0 , so I would suggest moving to this version ASAP. 截至今天,最新发布的Android Gradle插件版本为1.3.0 ,因此,我建议尽快迁移到该版本。

What you need to do - is in root level build.gradle file update com.android.tools.build:gradle version to 1.3.0 : 您需要做的-在根目录级别build.gradle文件build.gradle com.android.tools.build:gradle版本更新为1.3.0

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0'
    }
}

对我来说,该问题已通过在顶级build.gradle注释掉以下行来解决:

testCompile() "org.robolectric:robolectric:3.3.2"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM