java.lang.IllegalStateException:无法初始化插件:MockMaker [英] java.lang.IllegalStateException: Could not initialize plugin: MockMaker
问题描述
尝试在AS上运行仪器测试.
Trying to run instrumentation test on AS.
因此错误而卡住:
java.lang.IllegalStateException:无法初始化插件:接口org.mockito.plugins.MockMaker在org.mockito.internal.configuration.plugins.PluginLoader $ 1.invoke(PluginLoader.java:66)在java.lang.reflect.Proxy.invoke(Proxy.java:393)位于$ Proxy4.isTypeMockable(未知来源)
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
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
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(this);
MockitoAnnotations.initMocks(this);
它运行良好(无异常),但是模拟的上下文现在为空.
It is building fine(No Exception) but context mocked is now null.
推荐答案
工作过:
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
No need to comment initiMocks
这篇关于java.lang.IllegalStateException:无法初始化插件:MockMaker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!