简体   繁体   中英

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

The code in question:

List<String> mockList = mock(List.class);

The build.gradle dependency:

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. 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:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM