一尘不染

PowerMock抛出NoSuchMethodError(setMockName)

java

我试图使用模拟一个构造函数,PowerMockito但是每次运行测试时,都会出现以下错误:

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依赖项:

  • org.powermock:powermock-module-junit4:1.5.6
  • org.powermock:powermock-mockito-release-full:1.5.6

我已经跟踪了项目的依赖关系树并修复了冲突,以便mockito-all:1.9.5将其包含在构建中。


阅读 557

收藏
2020-12-03

共1个答案

一尘不染

我的问题是由于项目的(传递)依赖项中的javassist版本冲突。我所做的是搜索所有将旧版本的Javassist放入构建中的依赖项,然后将其排除。例如:

<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>
2020-12-03