找不到 Gradle DSL 方法:test() [英] Gradle DSL method not found: test()

查看:24
本文介绍了找不到 Gradle DSL 方法:test()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在 Android-Studio 1.2 中的 build.gradle 文件末尾添加以下代码(如 这篇文章):

Tried to add the following code at the end of my build.gradle file in Android-Studio 1.2 (as advised in this post):

test {
    testLogging {
        events "passed", "skipped", "failed", "standardOut", "standardError"
    }
}

但是得到了:

Error:(40, 0) Gradle DSL method not found: 'test()'
Possible causes:
- The project 'xxxxx' may be using a version of Gradle that does not contain the method.
- The build file may be missing a Gradle plugin.

我错过了什么?

推荐答案

gradle 文档:https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html

表示'test'任务来自java插件:

indicates that the 'test' task is sourced from the java plugin:

apply plugin: 'java' // adds 'test' task

正如您所说,这与 com.android.application 插件冲突.

This as you say conflicts with the com.android.application plugin.

解决方案

我终于想出了如何做到这一点.您可以将日志更改应用到所有测试"类型的任务,而不是将日志更改应用于测试任务(仅可从 java 插件获得),如下所示:

I have finally worked out how to do this. Rather than apply the logging changes to the test tasks (which is only available from java plugin) you can apply it to all tasks of type 'Test' as follows:

//Test Logging
tasks.withType(Test) {
    testLogging {
        events "started", "passed", "skipped", "failed"
    }
}

现在,当您运行 ./gradlew test 时,您应该在处理测试时记录这些事件.

Now when you run ./gradlew test you should get these events logged as the tests are processed.

这篇关于找不到 Gradle DSL 方法:test()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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