PowerMock抛出NoSuchMethodError(setMockName) [英] PowerMock throws NoSuchMethodError (setMockName)

查看:1497
本文介绍了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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆