android - 如何将库添加到 testImplementation 和 androidTestImplementation

标签 android mockito build.gradle mockito-kotlin

用于两者的 kotlin 库 testandroid tests 、单元测试和 UI 测试。
如果我将下面两行作为 build.gradle 的一部分编写,它可以正常工作。
我的问题是,这是添加要在测试和 android 测试中使用的库的正确方法吗
构建.gradle

   androidTestImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
    testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
感谢您的宝贵建议
谢谢
R

最佳答案

is this the right way to add the library to use in both test and android tests


一般来说,是的,只要您需要同时拥有 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
}

关于android - 如何将库添加到 testImplementation 和 androidTestImplementation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65082915/

相关文章:

java - 如何创建 CloseableHttpResponse 对象来帮助测试?

java - 为 Mockito 创建自定义 VerificationMode 类

android - 在新的 Android Studio 中使用 OpenCL

java - Gradle 6 : get the list of implementation dependencies programmatically

java - 在 Java/Android 中从 LabView 读取共享变量

android - 如何在 webview 上播放视频

android opengl es 2.0 纹理切换

java - 为什么 getName() 使用 mockito 返回 null?

gradle - Samza构建与gradle失败

android - Xamarin Android 保存文件,Environment.Specialfolder 不存在