gpt4 book ai didi

testng - PowerMockito 不工作 : -java. lang.NoClassDefFoundError: org/mockito/internal/creation/CglibMockMaker

转载 作者:行者123 更新时间:2023-12-04 00:22:50 38 4
gpt4 key购买 nike

我正在尝试使用 powermockito 模拟 CouchbaseCluster.create() 的静态方法。这是我的测试课。

@PrepareForTest(CouchbaseCluster.class)
public class IAMKafkaConsumerTest extends PowerMockTestCase {

private IAMKafkaConsumer iamKafkaConsumer;
private CouchbaseCluster mockCouchbaseCluster;
private Bucket mockBucket;

@ObjectFactory
public IObjectFactory getObjectFactory() {
return new org.powermock.modules.testng.PowerMockObjectFactory();
}

@Test
public void happyPath()
{
PowerMockito.mockStatic(CouchbaseCluster.class);

}

}
我的项目 pom 包括以下依赖项:
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-testng</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-testng-agent</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>

当我通过 TestNG 框架运行测试时,我收到此错误日志。

java.lang.NoClassDefFoundError:org/mockito/internal/creation/CglibMockMakerat org.powermock.api.mockito.internal.mockmaker.PowerMockMaker.(PowerMockMaker.java:40)at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)at java.lang.reflect.Constructor.newInstance(Constructor.java:526)at java.lang.Class.newInstance(Class.java:379)at org.mockito.internal.configuration.plugins.PluginLoader.loadImpl(PluginLoader.java:61)at org.mockito.internal.configuration.plugins.PluginLoader.loadPlugin(PluginLoader.java:24)

最佳答案

事实证明,PowerMockito 1.5.X 版本与 mockito 1.10.9 一起使用时已损坏

因此将版本更改为 1.6.X 对我有用。
这个链接帮助了我。

https://code.google.com/p/powermock/issues/detail?id=524

关于testng - PowerMockito 不工作 : -java. lang.NoClassDefFoundError: org/mockito/internal/creation/CglibMockMaker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31361420/

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