gpt4 book ai didi

java - PowerMock 和 Java 8 问题 : InterfaceMethodrefInfo cannot be cast to MethodrefInfo

转载 作者:太空狗 更新时间:2023-10-29 22:39:00 39 4
gpt4 key购买 nike

我在尝试使用 PowerMock 和 Mockito 执行单元测试时遇到问题。我需要 PowerMockito 来模拟静态方法。

这些是我使用的版本:

PowerMock 1.6.2
Mockito 1.10.19
JUnit 4.12
Java 8

当我添加注解@PrepareForTest(Graph.class) 时,出现以下错误:

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

我在官方的PowerMock Google页面上看到这与javassist有关。但是我有点迷路,我不知道如何解决。

为了以防万一,我也尝试下载最新的 Powermock SNAPSHOT (1.6.3-SNAPSHOT),但也没有用。

谁能帮帮我,好吗?

提前致谢

最佳答案

正在关注 Francisco González's回答,这是我必须做的:

<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.5.5</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.20.0-GA</version>
<scope>test</scope>
</dependency>

关于java - PowerMock 和 Java 8 问题 : InterfaceMethodrefInfo cannot be cast to MethodrefInfo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31189086/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com