android – java.lang.IllegalStateException:无法初始化插件:MockMaker
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了android – java.lang.IllegalStateException:无法初始化插件:MockMaker,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1865字,纯文字阅读大概需要3分钟。
内容图文
![android – java.lang.IllegalStateException:无法初始化插件:MockMaker](/upload/InfoBanner/zyjiaocheng/820/406ffeebb68c4f70ab4c0e4b85c84e67.jpg)
尝试在AS上运行检测测试.
坚持这个错误:
java.lang.IllegalStateException: Could not initialize plugin: interface org.mockito.plugins.MockMaker
at org.mockito.internal.configuration.plugins.PluginLoader$1.invoke(PluginLoader.java:66)
at java.lang.reflect.Proxy.invoke(Proxy.java:393)
at $Proxy4.isTypeMockable(Unknown Source)
ExampleInstrumentedTest.java
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Mock
Context context;
@Before
public void init(){
MockitoAnnotations.initMocks(this);
}
@Test
public void testDisabledFlag() {
ChanceValidator chanceValidator = new ChanceValidator(context);
Validator.ValidationResult result = chanceValidator.validate(2);
assertEquals(result, Validator.ValidationResult.NO_ERROR);
}
}
的build.gradle
apply plugin: 'com.android.application'
android{
..
defaultConfig {
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
testOptions {
unitTests.returnDefaultValues = true
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
// Unit testing dependencies
testCompile 'junit:junit:4.12'
// Set this dependency if you want to use the Hamcrest matcher library
testCompile 'org.hamcrest:hamcrest-library:1.3'
// more stuff, e.g., Mockito
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.1.0'
compile project(':mortar')
compile project(':mockito-core-2.6.6')
}
更新:
评论线后 –
MockitoAnnotations.initMocks(本);
它构建正常(没有例外)但是被模拟的上下文现在为空.
解决方法:
工作:
dependencies {
def mockito_version = '2.7.1' // For local unit tests on your development machine
testCompile "org.mockito:mockito-core:$mockito_version" // For instrumentation tests on Android devices and emulators
androidTestCompile "org.mockito:mockito-android:$mockito_version"
}
无需评论initiMocks
内容总结
以上是互联网集市为您收集整理的android – java.lang.IllegalStateException:无法初始化插件:MockMaker全部内容,希望文章能够帮你解决android – java.lang.IllegalStateException:无法初始化插件:MockMaker所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。