【问题标题】:how to add a library to testImplementation and androidTestImplementation如何将库添加到 testImplementation 和 androidTestImplementation
【发布时间】:2020-12-01 00:05:56
【问题描述】:

用于 testandroid tests、单元测试和 UI 测试的 kotlin 库。

如果我将以下两行作为 build.gradle 的一部分编写,它可以正常工作。

我的问题是,这是添加要在测试和 android 测试中使用的库的正确方法

build.gradle

   androidTestImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
    testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"

感谢您的宝贵建议

谢谢 回复

【问题讨论】:

  • 这才是对的方式……其实我没什么要补充的:)

标签: android mockito build.gradle mockito-kotlin


【解决方案1】:

这是添加库以在测试和 android 测试中使用的正确方法

一般来说,是的,只要您需要同时拥有 androidTestImplementationtestImplementation 语句,即使它们都用于同一个库。

如果您想让库保持同步,您可以为库的 Maven 坐标定义一个常量:

def mockLibrary = "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"

// TODO other good stuff here

dependencies {
// TODO other great libraries here
// TODO OK, maybe a few not-so-great libraries too
  androidTestImplementation mockLibrary
  testImplementation mockLibrary
}

【讨论】:

  • 非常感谢,它减少了一点代码。
猜你喜欢
  • 2019-02-04
  • 1970-01-01
  • 2011-04-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-30
  • 2022-01-08
  • 2021-05-15
相关资源
最近更新 更多