你好,我正在尝试模拟一个最终类(因为 kotlin 中的所有类默认都是最终类)并在我的 gradle 中添加了以下依赖项:
testImplementation 'junit:junit:4.12'
testImplementation 'au.com.dius:pact-jvm-consumer-junit_2.11:3.5.10'
testImplementation "org.mockito:mockito-android:2.13.0"
testImplementation 'org.mockito:mockito-inline:2.13.0'
testImplementation "org.mockito:mockito-core:2.13.0"
//testImplementation 'io.mockk:mockk:1.8'
testImplementation 'org.assertj:assertj-core:3.8.0'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
androidTestImplementation 'junit:junit:4.12'
androidTestImplementation "org.mockito:mockito-core:2.13.0"
androidTestImplementation "org.mockito:mockito-android:2.13.0"
androidTestImplementation 'org.mockito:mockito-inline:2.13.0'
androidTestImplementation "com.android.support.test.espresso:espresso-intents:3.0.2"
mockito-inline 应该使您能够模拟最终的 kotlin 类,因此我使用 testImplementation 和 androidTestImplementation 添加到我的 java 单元测试和仪器测试中
在构建项目时,我收到以下错误:
More than one file was found with OS independent path 'mockito-extensions/org.mockito.plugins.MockMaker'
有什么想法吗?如果我删除mockitio内联的androidTestImplementation,它编译得很好,但是在运行仪器测试时,我收到mockito错误,说它无法模拟最终类。
为了能够在 Kotlin 中模拟最终类,您需要创建一个文件org.mockito.plugins.MockMaker
(字面意思)仅包含这一行
mock-maker-inline
并将其放入test/resources/mockito-extensions
.
欲了解更多信息,请阅读https://antonioleiva.com/mockito-2-kotlin/ https://antonioleiva.com/mockito-2-kotlin/.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)