Android mockito单元测试无法解析MockitoAnnotations.openMocks。

huangapple go评论56阅读模式
英文:

Android mockito Unit test can't resolve MockitoAnnotations.openMocks

问题

当我尝试使用Mockito库为我的ViewModel编写单元测试时,我无法调用MockitoAnnotations.openMocks(this)函数。

我尝试了以下依赖项:

testImplementation "org.mockito:mockito-core:2.19.0"
testImplementation "org.mockito.kotlin:mockito-kotlin:2.19.0"
testImplementation "io.mockk:mockk:2.19.0"
implementation 'androidx.arch.core:core-testing:2.1.0'
英文:

When I am trying to write Unit test for my ViewModels using Mockito library, I am not able to call openMocks MockitoAnnotations.openMocks(this) funtion

I tried the following dependencies.

  testImplementation "org.mockito:mockito-core:2.19.0"
  testImplementation "org.mockito.kotlin:mockito-kotlin:2.19.0"
  testImplementation "io.mockk:mockk:2.19.0"
  implementation 'androidx.arch.core:core-testing:2.1.0'

答案1

得分: 1

您的版本似乎已过时。请使用最新版本的Mockito适用于Android。

testImplementation "org.mockito:mockito-core:3.11.2"
testImplementation "org.mockito.kotlin:mockito-kotlin:3.11.2"

注意:io.mockk:mockk可能与Mockito发生冲突,因此您可能需要将其移除。

英文:

Your version seems outdated. Use the latest version of Mockito for Android

testImplementation "org.mockito:mockito-core:3.11.2"
testImplementation "org.mockito.kotlin:mockito-kotlin:3.11.2"

Note: io.mockk:mockk can cause conflict with mockito, so could be that you need to remove it.

huangapple
  • 本文由 发表于 2023年5月28日 22:32:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/76351999.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定