Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
659 views
in Technique[技术] by (71.8m points)

unit testing - Gradle DSL method not found: test()

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

But got:

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.

What did I miss?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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

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

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

Solution

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...