我在尝试使用PowerMock和Mockito执行单元测试时遇到了问题。我需要PowerMockito来模拟静态方法。
I´m having issues while trying to execute a unit test using PowerMock with Mockito. I need PowerMockito to mock an static method.
这些是我使用的版本:
PowerMock 1.6.2 Mockito 1.10.19 JUnit 4.12 Java 8当我添加注释@PrepareForTest(Graph.class)时,我收到以下错误:
When I add the annotation @PrepareForTest(Graph.class) I get the following error:
java.lang.IllegalStateException: Failed to transform class with name name.of.my.package.GraphUtil. Reason: javassist.bytecode.InterfaceMethodrefInfo cannot be cast to javassist.bytecode.MethodrefInfo我已阅读过这是与javassist相关的官方PowerMock Google页面。但我有点失落,我不知道如何解决它。
I have read in the official PowerMock Google page that this is related to javassist. But I´m a bit lost and I don´t know how to fix it.
为了以防万一,我也尝试下载最新的Powermock SNAPSHOT(1.6.3-SNAPSHOT),但也没有用。
Just in case, I also tried downloading the latest SNAPSHOT of Powermock (1.6.3-SNAPSHOT) but did not work either.
有人可以帮助我吗?
提前致谢
推荐答案是的,这就是问题所在。 PowerMock依赖于javassist,因此我只需在我的pom中排除该传递依赖,然后将依赖包含在javassist的固定版本中。这对我有用。谢谢!
Yes, that was the problem. PowerMock has a dependency to javassist, so I just had to exclude that transitive dependency in my pom and later include the dependency to the fixed version of javassist. And that worked for me. Thanks!
更多推荐
PowerMock和Java 8问题:InterfaceMethodrefInfo无法强制转换为MethodrefInfo
发布评论