【发布时间】:2017-06-10 14:03:01
【问题描述】:
尝试在 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(未知来源)
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);
}
}
构建.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);
构建良好(无异常),但模拟的上下文现在为空。
【问题讨论】:
-
发布完整版
ExampleInstrumentedTest -
@Intellij 这是一个完整的测试
标签: android android-studio gradle mockito android-library