在Android Studio项目中找不到参数为test()的方法

28

在我的Android应用程序中,我想要排除某个包中的一些测试用例,因此我在build.gradle文件中使用了test任务,例如:

apply plugin: 'com.android.library'

test{
     exclude '**/calltest/Summary.class'
}

如果同步项目时出现以下异常:

* What went wrong:
A problem occurred evaluating project ':SdkModule'.
> Could not find method test() for arguments [build_4g3vf7b615x3x1p7i9ty0pt1l$_run_closure1@73d026ca] on project ':SdkModule' of type org.gradle.api.Project.

如果我添加apply plugin : 'java'

CONFIGURE FAILED in 1s
The 'java' plugin has been applied, but it is not compatible with the Android plugins.

请帮我处理这个问题。

2个回答

6

当我尝试为我的Jenkins构建生成XML测试报告时,遇到了类似的问题。 与测试相关的设置应该在testOptions中。我的文件:

android {
  testOptions {
    unitTests.includeAndroidResources = true
    unitTests.all {
        reports {
            junitXml.enabled = true
            html.enabled = false
        }
    }
}

5

相比于

test {
    exclude '**/calltest/Summary.class'
}

尝试使用Groovy语言

tasks.withType(Test) {
    exclude '**/calltest/Summary.class'
}

或使用 Kotlin DSL(build.gradle.kts)进行编写。

tasks.withType<Test> {
    exclude("**/calltest/Summary.class")
}

2
必须位于模块的build.gradle中,而非根目录。 - Akbolat SSS

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接