没有找到摇篮DSL方法:测试() [英] Gradle DSL method not found: test()

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

问题描述

试过在Android的工作室我的build.gradle 文件的最后添加如下code 1.2(人员建议在<一个href=\"http://stackoverflow.com/questions/3963708/gradle-how-to-display-test-results-in-the-console-in-real-time\">this帖子):

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:<一href=\"https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html\">https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html

The gradle documentation: https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html

表示测试任务从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测试你应该得到这些事件记录为测试进行处理。

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

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

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