简体   繁体   中英

NoClassDefFoundError - org/mockito/exceptions/Reporter when Using Mockito and PowerMock

I'm trying to add Powermock to my application that uses Mockito. This is what I currently have in my gradle build:

 compile("junit:junit:4.12"){force = true}
  compile("org.powermock:powermock-api-mockito-common:1.7.0")     
  compile("org.powermock:powermock-api-mockito2:1.7.0")
  compile("org.powermock:powermock-api-support:1.7.0")
  compile("org.powermock:powermock-core:1.7.0")
  compile("org.powermock:powermock-module-junit4:1.7.0")
  compile("org.powermock:powermock-module-junit4-common:1.7.0")
  compile("org.powermock:powermock-reflect:1.7.0")
  compile("org.javassist:javassist:3.12.0.GA")
  compile("org.mockito:mockito-core:2.8.9")

This is the test file that I have so far...

@RunWith(PowerMockRunner.class)
@PrepareForTest(XMLTransaction.class)
public class CloseSummaryOrCloseTrailerResponseTest {

     public final static String URL="WL_APPSERVER";
     private XMLTransaction xmlTransaction; 

    @Before
    public void initMocks() throws Exception {
        xmlTransaction = PowerMockito.spy(new XMLTransaction(URL));
        PowerMockito.doNothing().when(xmlTransaction, "initialize");    
    }

    @Test
    public void whenCloseSummaryResponseNoErrorExpectCorrectXmlMsgProduced ()
    {
        ...test code here
    }
}

I get the error:

java.lang.NoClassDefFoundError: org/mockito/exceptions/Reporter at sun.reflect.GeneratedSerializationConstructorAccessor8.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at org.objenesis.instantiator.sun.SunReflectionFactoryInstantiator.newInstance(SunReflectionFactoryInstantiator.java:48) at org.powermock.reflect.internal.WhiteboxImpl.newInstance(WhiteboxImpl.java:251) at org.powermock.reflect.Whitebox.newInstance(Whitebox.java:139)

The Reporter class should be contained in mockito-core. What additional jars do I need? I reviewed the compatiability of Mockito and Powermock using this site: https://github.com/powermock/powermock/wiki/Mockito#supported-versions

But it seems I am missing some other jar.

UPDATE Checked that answer but it did not solve my problem. I changed

compile("org.powermock:powermock-api-mockito2:1.7.0")

to

compile("org.powermock:powermock-api-mockito2:1.7.0RC2")

Now I get a different error:

java.lang.IllegalStateException: Extension API internal error: org.powermock.api.extension.proxyframework.ProxyFrameworkImpl could not be located in classpath. at org.powermock.reflect.proxyframework.ProxyFrameworkHelper.register(ProxyFrameworkHelper.java:35)

What jar does this need?

What worked for me...was that I deleted all of powermock jars in my lib folder and then used the above gradle code and rebuilt. I was able to run the test.

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