gpt4 book ai didi

android - java.lang.IllegalStateException : Could not initialize plugin: MockMaker 错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:26:39 27 4
gpt4 key购买 nike

尝试在 AS 上运行仪器测试。

遇到这个错误:

java.lang.IllegalStateException: Could not initialize plugin: interface org.mockito.plugins.MockMakerat 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);
}
}

构建.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 : Could not initialize plugin: MockMaker 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41850779/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com