英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论