PowerMock throws NoSuchMethodError (setMockName)(PowerMock 抛出 NoSuchMethodError (setMockName))
问题描述
我正在尝试使用 PowerMockito
模拟构造函数,但每次运行测试时都会出现以下错误:
I'm trying to mock a constructor using PowerMockito
but every time I run the test I get the following error:
java.lang.NoSuchMethodError: org.mockito.internal.creation.MockSettingsImpl.setMockName(Lorg/mockito/mock/MockName;)Lorg/mockito/internal/creation/settings/CreationSettings;
at org.powermock.api.mockito.internal.mockcreation.MockCreator.createMethodInvocationControl(MockCreator.java:107)
at org.powermock.api.mockito.internal.mockcreation.MockCreator.mock(MockCreator.java:60)
at org.powermock.api.mockito.internal.expectation.DefaultConstructorExpectationSetup.createNewSubstituteMock(DefaultConstructorExpectationSetup.java:105)
at org.powermock.api.mockito.internal.expectation.DefaultConstructorExpectationSetup.withAnyArguments(DefaultConstructorExpectationSetup.java:71)
我的项目中有以下 PowerMock 依赖项:
I have the following PowerMock dependencies in my project:
- org.powermock:powermock-module-junit4:1.5.6
- org.powermock:powermock-mockito-release-full:1.5.6
我已经跟踪了我的项目的依赖树并修复了冲突,以便 mockito-all:1.9.5
被包含在构建中.
I've traced the dependency tree of my project and fixed conflicts so that mockito-all:1.9.5
gets included in the build.
推荐答案
我的问题是由于我的项目(传递)依赖项中的 javassist 版本冲突.我所做的是搜索将旧版本的 javassist 放入构建中的所有依赖项,然后排除它们.例如:
My problem was due to conflicting versions of javassist in my project's (transitive) dependencies. What I did was search for all dependencies that put old version of javassist in the build, then exclude them. For example:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.5.1-Final</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
</exclusion>
</exclusions>
</dependency>
这篇关于PowerMock 抛出 NoSuchMethodError (setMockName)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PowerMock 抛出 NoSuchMethodError (setMockName)


基础教程推荐
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13