使用 mockito-android 发出警告

warning using mockito-android

我使用 mockito 收到此警告

You included the 'mockito-android' dependency in a non-Android environment. The Android mock maker was disabled. You should only include the latter in your 'androidTestCompile' configuration If disabling was a mistake, you can set the 'org.mockito.mock.android' property to 'true' to override this detection.

我在哪里可以设置消息说的 属性?

这个错误是关于什么的?

似乎对于 testImplementation 我们应该使用 mockito-core 而对于 androidTestImplementation 我们应该使用 mockito-android

Mockito Documentation

如果您将 mockito-android 用作 implementation(示例用例:如果您正在构建用于测试的库),则将 属性 设置为系统 属性在你的 @Before 方法中让 mockito 知道依赖项没有被错误地添加为 implementation

 @Before
 open fun setUp() {
    System.setProperty("org.mockito.mock.android", "true")
 }