【问题标题】:Gradle Wrapper 4.6 not recognising test filtering parameterGradle Wrapper 4.6 无法识别测试过滤参数
【发布时间】:2018-06-26 10:11:52
【问题描述】:

我在使用 gradle wrapper 过滤测试时遇到问题,因为无法识别 --tests 参数:

❯ ./gradlew test --continuous --tests "pt.joaomneto.titancompanion.adventure.twofm.TWOFMAdventureStateTest"                                                                                                                                                                                                              

Continuous build is an incubating feature.

> Configure project :
TitanCompanion: 'annotationProcessor' dependencies won't be recognized as kapt annotation processors. Please change the configuration name to 'kapt' for these artifacts: 'com.android.databinding:compiler:3.2.0-alpha10' and apply the kapt plugin: "apply plugin: 'kotlin-kapt'".


FAILURE: Build failed with an exception.

* What went wrong:
Problem configuring task :test from command line.
> Unknown command-line option '--tests'.

* Try:
Run gradlew help --task :test to get task usage details. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s

如您所见,帮助输出中没有这样的参数。

❯ ./gradlew help --task :test                                                                                                                                                                                                                                                                                          

> Configure project :
TitanCompanion: 'annotationProcessor' dependencies won't be recognized as kapt annotation processors. Please change the configuration name to 'kapt' for these artifacts: 'com.android.databinding:compiler:3.2.0-alpha10' and apply the kapt plugin: "apply plugin: 'kotlin-kapt'".

> Task :help
Detailed task information for :test

Path
     :test

Type
     Task (org.gradle.api.Task)

Description
     Run unit tests for all variants.

Group
     verification

我正在使用 gradle 4.6

❯ ./gradlew --version                                                                                                                                                                                                                                                                                                    

------------------------------------------------------------
Gradle 4.6
------------------------------------------------------------

Build time:   2018-02-28 13:36:36 UTC
Revision:     8fa6ce7945b640e6168488e4417f9bb96e4ab46c

Groovy:       2.4.12
Ant:          Apache Ant(TM) version 1.9.9 compiled on February 2 2017
JVM:          1.8.0_162 (Oracle Corporation 25.162-b12)
OS:           Mac OS X 10.13 x86_64

我在这里做错了什么?文档明确指出我可以使用这个参数来过滤测试:https://docs.gradle.org/4.6/userguide/java_plugin.html#test_filtering

你能帮我吗?

编辑:这只发生在 Android 项目中。在标准的 kotlin+spring 项目中使用相同的 gradle 版本,它可以正常工作...

【问题讨论】:

    标签: android testing gradle junit


    【解决方案1】:

    过了这么久才回答我的问题:

    问题来自这样一个事实,即 android 插件将测试任务用作更具体任务的保护伞,并且无法识别 --tests 过滤器参数。所以解决这个问题的方法是指定所需的测试任务,在我的情况下必须是:

    ./gradlew testDebugUnitTest --tests pt.joaomneto.titancompanion.adventure.twofm.TWOFMAdventureStateTest
    

    这里解释:https://developer.android.com/studio/test/command-line

    【讨论】:

      猜你喜欢
      • 2017-05-18
      • 2012-11-21
      • 2015-06-27
      • 1970-01-01
      • 1970-01-01
      • 2017-01-16
      • 1970-01-01
      • 2018-08-29
      • 2013-04-14
      相关资源
      最近更新 更多