代码之家  ›  专栏  ›  技术社区  ›  tynn

仅用于测试依赖项的渐变模块输出配置

  •  0
  • tynn  · 技术社区  · 7 年前

    格拉德尔 app 和 test 测试 包含仅用于测试的实用程序。现在我想设置这个模块,这样它就不会在 主要的 应用程序 即使不是偶然。

    implementation project(':test') # should fail or not contain any inputs
    
    testImplementation project(':test') # should include all inputs
    androidTestImplementation project(':test') # should include all inputs
    

    测试 表现得像这样?

    我想这和 插件处理构建类型和风格的配置,但我也不确定如何解决这个问题。

    我想这些都处理好了 Gradle consumer attributes . 也许有一个过滤器或属性可以应用到它,使它只对测试可用。

    0 回复  |  直到 7 年前
        1
  •  0
  •   Dmytro Batyuk    7 年前

    您可以为此使用注释: https://developer.android.com/studio/write/annotations#visible

    另一种方法是将测试代码排除到名为 sub_test testImplementation 或 androidTestImplementation sub_测试 test 模块

        2
  •  0
  •   Martin Zeitler    7 年前

    找到: Use separate test modules for instrumented tests

    ... 应用 com.android.test com.android.library

        3
  •  0
  •   tynn    6 年前

    这个 java-test-fixtures

    implementation project(':test') # should fail or not contain any inputs
    
    testImplementation testFixtures(project(':test'))
    androidTestImplementation testFixtures(project(':test'))
    

    现在还有其他的缺点

    作为汤姆·特雷桑斯基 Is the java-test-fixtures plugin incompatible with the Build and run using IntelliJ IDEA setting? 安卓工作室 testFixtures 震源设置良好。

    此外,它还不适用于 科特林 . 但是作为 Michael Evans pointed out ,有个任务已为打开 Android YouTrack .

    但是使用 安卓 这个项目对我来说很好。

    推荐文章