[英]IllegalStateException when using Mockito with IntelliJ's Java
The error message I receive: 我收到的错误消息:
java.lang.IllegalStateException: Could not initialize plugin: interface org.mockito.plugins.MockMaker java.lang.IllegalStateException:无法初始化插件:接口org.mockito.plugins.MockMaker
The code in question: 有问题的代码:
List<String> mockList = mock(List.class);
The build.gradle dependency: build.gradle依赖项:
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
def mockito_version = 'latest.release'
// For local unit tests on your development machine
testCompile "org.mockito:mockito-core:$mockito_version"
}
I have tried looking at other people with the same issue and I keep getting references to PowerMock. 我尝试着看同样问题的其他人,并且不断获得有关PowerMock的引用。 I have no idea what that means, so if this is a duplicate I apologize. 我不知道那是什么意思,因此,如果这是重复的话,我深表歉意。 It just seems like no other question had a solution that resolved my issue. 似乎没有其他问题可以解决我的问题。 The library is imported properly, as I do not have any compilation errors. 该库已正确导入,因为我没有任何编译错误。 Any help would be greatly appreciated. 任何帮助将不胜感激。
i tried to create a new project and test this out. 我试图创建一个新项目并进行测试。 below is how my depdencies in gradle file looks: 以下是我在gradle文件中的依赖关系外观:
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile "org.mockito:mockito-core:2.+"
}
below is my test class: 下面是我的测试课:
import org.junit.Assert;
import org.junit.Test;
import java.util.List;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class TestList {
@Test
public void Test(){
List<String> myList = mock(List.class);
when(myList.get(0)).thenReturn("hello world");
Assert.assertEquals("hello world",myList.get(0));
}
}
this works. 这可行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.