PowerMock抛出NoSuchMethodError(setMockName)

编程入门 行业动态 更新时间:2024-10-21 06:27:16
本文介绍了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.

推荐答案

我的问题是由于confli我的项目(传递)依赖项中的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)

本文发布于:2023-10-31 04:22:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1544988.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:抛出   PowerMock   setMockName   NoSuchMethodError

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!