简体   繁体   English

NoClassDefFoundError-使用Mockito和PowerMock时的org / mockito / exceptions / Reporter

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

I'm trying to add Powermock to my application that uses Mockito. 我试图将Powermock添加到使用Mockito的应用程序中。 This is what I currently have in my gradle build: 这就是我目前在gradle构建中所拥有的:

 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) 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)org.powermock.ref.internance.WhiteboxImpl.newInstance(WhiteboxImpl.java:251)org.powermock.reflect.Whitebox.newInstance(Whitebox.java:139)

The Reporter class should be contained in mockito-core. Reporter类应该包含在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 我使用以下站点检查了Mockito和Powermock的兼容性: 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. java.lang.IllegalStateException:扩展API内部错误:org.powermock.api.extension.proxyframework.ProxyFrameworkImpl无法位于类路径中。 at org.powermock.reflect.proxyframework.ProxyFrameworkHelper.register(ProxyFrameworkHelper.java:35) 在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. 什么对我有用...是我删除了我的lib文件夹中的所有powermock jar,然后使用上面的gradle代码并重建。 I was able to run the test. 我能够进行测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用mockito和powermock时ClassCastException - ClassCastException when using mockito & powermock 升级到 2.7 ClassNotFoundException 后:运行测试时的 org.mockito.exceptions.Reporter - after upgrade to 2.7 ClassNotFoundException: org.mockito.exceptions.Reporter when run test Junit 用于我的静态方法使用 PowerMock 失败:org.mockito.exceptions.misusing.MissingMethodInvocationException - Junit for my static method using PowerMock failing : org.mockito.exceptions.misusing.MissingMethodInvocationException 将Mockito与PowerMock一起使用时初始化异常错误 - Initializing Exception error when using Mockito with PowerMock 使用PowerMock / Mockito时,模拟对象为null - Mocked object is null when using PowerMock/Mockito 带有Mockito的Powermock - Powermock with Mockito MOCKITO 中的 org.mockito.exceptions.misusing.MissingMethodInvocationException - org.mockito.exceptions.misusing.MissingMethodInvocationException in MOCKITO 当我没有匹配器时org.mockito.exceptions.misusing.InvalidUseOfMatchersException - org.mockito.exceptions.misusing.InvalidUseOfMatchersException when i have no matcher PowerMock + Mockito VS Mockito一个人 - PowerMock + Mockito VS Mockito alone 线程“ main”中的异常java.lang.NoClassDefFoundError:org / mockito / Mockito - Exception in thread “main” java.lang.NoClassDefFoundError: org/mockito/Mockito
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM