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

M.A*_*ali 14 android build.gradle android-junit android-studio-3.0

在我的Android应用程序中,我想排除软件包中的一些测试用例,以便使用文件中的test任务build.gradle。例如:

apply plugin: 'com.android.library'

test{
     exclude '**/calltest/Summary.class'
}
Run Code Online (Sandbox Code Playgroud)

如果同步项目,则会出现以下异常:

* 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.
Run Code Online (Sandbox Code Playgroud)

如果我加 apply plugin : 'java'

CONFIGURE FAILED in 1s
The 'java' plugin has been applied, but it is not compatible with the Android plugins.
Run Code Online (Sandbox Code Playgroud)

请帮我。

ant*_*ity 5

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

android {
  testOptions {
    unitTests.includeAndroidResources = true
    unitTests.all {
        reports {
            junitXml.enabled = true
            html.enabled = false
        }
    }
}
Run Code Online (Sandbox Code Playgroud)


小智 5

代替

test {
    exclude '**/calltest/Summary.class'
}
Run Code Online (Sandbox Code Playgroud)

尝试在 Groovy 中

tasks.withType(Test) {
    exclude '**/calltest/Summary.class'
}
Run Code Online (Sandbox Code Playgroud)

或在Kotlin DSL中(build.gradle.kts)

test {
    exclude '**/calltest/Summary.class'
}
Run Code Online (Sandbox Code Playgroud)

  • 必须位于模块的“build.gradle”内部,而不是 root (2认同)