Could not initialize plugin: interface org.mockito.plugins.MockMaker

后端 未结 25 2069
走了就别回头了
走了就别回头了 2020-12-29 01:01

I\'m getting following exception once tests is started:

    Testcase: treeCtorArgumentTest(com.xythos.client.drive.cachedtree.CachedTreeTest):  Caused an ERR         


        
相关标签:
25条回答
  • 2020-12-29 01:06

    For android development you need to import a couple of things:

     dependencies {
       testCompile "org.mockito:mockito-core:+"
       androidTestCompile "org.mockito:mockito-android:+"
     }
    

    could not find any reference of this but this is the only one that has worked for me.

    0 讨论(0)
  • 2020-12-29 01:06

    It worked for me After I removed bytebuddy folder from ${home}.m2\repository\net\bytebuddy and removed byte-buddy-agent,byte-buddy and objenesis dependency from pom.xml

    0 讨论(0)
  • 2020-12-29 01:08

    Problem: PowerMock + Mockito + TestNG + PowerMockTestCase

    Sharing my problem/solution in case it helps anybody.

    My dependencies were all pointed correctly:

    testImplementation 'org.mockito:mockito-core:2.8.47'
    testImplementation 'org.powermock:powermock-core:1.7.4'
    testImplementation 'org.powermock:powermock-module-testng:1.7.4'
    testImplementation 'org.powermock:powermock-api-mockito2:1.7.4'
    

    But I still got the following error:

    java.lang.IllegalStateException: Could not initialize plugin: interface org.mockito.plugins.MockMaker
    
        at org.mockito.internal.configuration.plugins.PluginLoader$1.invoke(PluginLoader.java:66)
        at com.sun.proxy.$Proxy11.isTypeMockable(Unknown Source)
        at org.mockito.internal.util.MockUtil.typeMockabilityOf(MockUtil.java:29)
        at org.mockito.internal.util.MockCreationValidator.validateType(MockCreationValidator.java:22)
        at org.mockito.internal.creation.MockSettingsImpl.validatedSettings(MockSettingsImpl.java:186)
        at org.mockito.internal.creation.MockSettingsImpl.confirm(MockSettingsImpl.java:180)
        at org.mockito.internal.MockitoCore.mock(MockitoCore.java:62)
        at org.mockito.Mockito.mock(Mockito.java:1729)
        at org.mockito.internal.configuration.MockAnnotationProcessor.process(MockAnnotationProcessor.java:33)
        at org.mockito.internal.configuration.MockAnnotationProcessor.process(MockAnnotationProcessor.java:16)
        at org.mockito.internal.configuration.IndependentAnnotationEngine.createMockFor(IndependentAnnotationEngine.java:38)
        at org.mockito.internal.configuration.IndependentAnnotationEngine.process(IndependentAnnotationEngine.java:62)
        at org.mockito.internal.configuration.InjectingAnnotationEngine.processIndependentAnnotations(InjectingAnnotationEngine.java:57)
        at org.mockito.internal.configuration.InjectingAnnotationEngine.process(InjectingAnnotationEngine.java:41)
        at org.mockito.MockitoAnnotations.initMocks(MockitoAnnotations.java:69)
    

    My test was something as such:

    import org.powermock.core.classloader.annotations.PrepareForTest;
    import org.powermock.modules.testng.PowerMockTestCase;
    import static org.mockito.MockitoAnnotations.initMocks;
    
    @PrepareForTest(MyClass.class)
    public class MyTest extends PowerMockTestCase {
    
        @BeforeTest
        public void init() {
            initMocks(this);
        }
    }
    

    As mentioned in this thread, removing the initMocks() method removes the error, but all the mocks become null.


    ✅ Solution: BeforeTest VS BeforeMethod

    What I found out for my case is that @BeforeTest was actually posing a problem. Changing it to @BeforeMethod resolved the error.

    import org.powermock.core.classloader.annotations.PrepareForTest;
    import org.powermock.modules.testng.PowerMockTestCase;
    import static org.mockito.MockitoAnnotations.initMocks;
    
    @PrepareForTest(MyClass.class)
    public class MyTest extends PowerMockTestCase {
    
        @BeforeMethod // CHANGE THIS!
        public void init() {
            initMocks(this);
        }
    }
    

    My guess is that it is something to do with beans injection; @BeforeTest is executed before any beans got injected while @BeforeMethod is executed after beans injection. Not sure how it really affected though.

    0 讨论(0)
  • 2020-12-29 01:08

    Not the answer to the original poster, since s/he's using Netbeans, but in Eclipse I needed to do "Maven -> Update Project" in order to get tests working again.

    0 讨论(0)
  • 2020-12-29 01:15

    I had the same issue and tryed @Paskas's solution, worked well Junit Test ok at first. added the bytebuddy dependency to my pom.xml:

    <dependency>
                <groupId>net.bytebuddy</groupId>
                <artifactId>byte-buddy-dep</artifactId>
                <version>1.9.7</version>
    </dependency>
    

    Hope this helps.

    0 讨论(0)
  • 2020-12-29 01:16

    Delete the "byte-buddy-1.7.11.jar" manually from the maven repository path which appears in the error. Maven update the project and the issue will be resolved. Tried and worked for me.

    0 讨论(0)
提交回复
热议问题