【问题标题】:Could not find method test() for arguments on Android studio project在 Android Studio 项目中找不到参数的方法 test()
【发布时间】:2019-01-08 09:24:33
【问题描述】:

在我的 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.

请帮帮我。

【问题讨论】:

    标签: android build.gradle android-studio-3.0 android-junit


    【解决方案1】:

    尝试为我的 Jenkins 构建生成 XML 测试报告时遇到类似问题。 测试相关设置应在testOptions 中。我的档案:

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

    【讨论】:

      【解决方案2】:

      而不是

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

      试试 groovy

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

      在 kts 中

      tasks.withType<Test> {
          exclude '**/calltest/Summary.class'
      }
      

      【讨论】:

      • 从 Gradle 7+ 开始,我想应该是 tasks.withType(Test)
      猜你喜欢
      • 2017-02-22
      • 2015-01-09
      • 1970-01-01
      • 1970-01-01
      • 2017-07-21
      • 1970-01-01
      • 2016-12-27
      • 2018-11-20
      • 1970-01-01
      相关资源
      最近更新 更多