- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
尝试在 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);
}
}
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/
使用 TestNg + PowerMock + Mockito 时遇到 java.lang.ExceptionInInitializerError: Caused by: java.lang.Null
这是我的测试课: class RocketListVMTest { @get:Rule var instantTaskExecutorRule = InstantTaskExecuto
您好,我正在尝试模拟最终类(因为 kotlin 中的所有类默认都是最终类)并在我的 gradle 中添加了以下依赖项: testImplementation 'junit:junit:4.12' te
测试开始后,我收到以下异常: Testcase: treeCtorArgumentTest(com.xythos.client.drive.cachedtree.CachedTreeTest)
使用操作系统独立路径 'mockito-extensions/org.mockito.plugins.MockMaker' 找到多个文件添加时出现此错误androidTestImplementatio
尝试在 AS 上运行仪器测试。 遇到这个错误: java.lang.IllegalStateException: Could not initialize plugin: interface org.
我是用 spring boot 编写 junit4 测试的新手我已经探索了所有 SO 问题来解决以下问题,我进行了广泛的研究,但我无法解决这个问题。我一直在尝试使用 @MockBean 和 @Auto
我正在使用 Mockito 2 和 Espresso 进行单元测试,但在尝试在仪器测试中使用 Mockito 2 时遇到了问题。在运行测试时,我收到此错误 java.lang.IllegalState
我正在尝试使用 PowerMock 通过静态方法模拟一个类,但我特别希望在 Android Instrumentation 测试中执行此操作。明确地说,我希望在真实的 Android 设备或模拟器上运
我收到 PowerMock 错误,但我没有使用 PowerMocking。我正在使用正常的模拟。这是我要测试的类(class): import java.util.List; import org.a
我一直在将一个项目从 Java 8 迁移到 Java 12。除了单元测试外,一切都很顺利。当我使用 Maven 编译和启动测试时,许多测试失败并显示以下消息: java.lang.IllegalSta
我是一名优秀的程序员,十分优秀!