[英]IllegalStateException when using Mockito with IntelliJ's Java
我收到的错误消息:
java.lang.IllegalStateException:无法初始化插件:接口org.mockito.plugins.MockMaker
有问题的代码:
List<String> mockList = mock(List.class);
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"
}
我尝试着看同样问题的其他人,并且不断获得有关PowerMock的引用。 我不知道那是什么意思,因此,如果这是重复的话,我深表歉意。 似乎没有其他问题可以解决我的问题。 该库已正确导入,因为我没有任何编译错误。 任何帮助将不胜感激。
我试图创建一个新项目并进行测试。 以下是我在gradle文件中的依赖关系外观:
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile "org.mockito:mockito-core:2.+"
}
下面是我的测试课:
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));
}
}
这可行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.