簡體   English   中英

將Mockito與IntelliJ的Java一起使用時發生IllegalStateException

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM