android - 如何将库添加到 testImplementation 和 androidTestImplementation
问题描述
用于test
and android tests
、单元测试和 UI 测试的 kotlin 库。
如果我将下面两行作为 build.gradle 的一部分编写,它可以正常工作。
我的问题是,这是添加要在测试和 android 测试中使用的库的正确方法吗
构建.gradle
androidTestImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
感谢您的宝贵建议
谢谢R
解决方案
这是添加要在测试和android测试中使用的库的正确方法吗
一般来说,是的,只要你需要一个androidTestImplementation
和一个testImplementation
语句,即使它们都用于同一个库。
如果你想让库保持同步,你可以为库的 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 - KeyguardManager.isKeyguardSecure 导致 StrictMode 策略违规
- c++ - MySQL C++ 连接器循环
- css - 如果我使用粘性元素,页面会在 Firefox 中无限滚动
- typescript - 用于从具有可选键的对象映射的对象时,keyof 结果包含“未定义”
- javascript - 在 ReactJS 中按列搜索
- ios - 当数据从一个视图控制器传递到另一个视图控制器时,我如何能够传递图像?
- asp.net-core - ASP.NET Core 3.0 将 HTTP 4XX 和 5XX 请求重定向到自定义错误页面,同时保留错误代码
- android - 图形 API。没有收到电子邮件字段。获取登录用户名或电子邮件 ID 的任何其他方式?
- r - 无法在 Bluesky Statistics 中设置“R 主目录路径”
- oracle - Sql Developer上出现此问题“IO错误:网络适配器无法建立连接”的原因是什么?