EasyMock / PowerMock导入问题

发布于 2024-10-26 13:21:17 字数 1004 浏览 7 评论 0原文

我遇到了一些我不太明白的问题,我发现一个网站建议如果模拟是使用 PowerMock 创建的,则存在与 verify() 不兼容的问题。

当我输入一行来创建模拟时,Eclipse 告诉我该方法不明确,我最终不得不将其指定为 EasyMock.createMock 或 PowerMock.createMock。

我最初刚开始使用 EasyMock,然后切换到 PowerMock。 import 语句的顺序重要吗?如果您使用 PowerMock,不包含某些 EasyMock 内容是否重要?

这是我得到的信息:

import org.easymock.EasyMock;  
import org.junit.*;  
import org.junit.runner.RunWith;  

import static org.easymock.EasyMock.*;  
import static org.powermock.api.easymock.PowerMock.*;  
import org.powermock.reflect.Whitebox;  
import org.powermock.api.easymock.*;  
import org.powermock.api.easymock.PowerMock.*;  
import org.powermock.api.mockito.expectation.*;  
import org.powermock.api.mockito.*;  
import org.powermock.api.support.membermodification.*;  
import org.powermock.api.support.membermodification.MemberMatcher.*;  
import org.powermock.core.classloader.annotations.*;  
import org.powermock.modules.junit4.*;  

那里可能有一些裁员。有可能发生冲突吗?为了消除歧义,顺序重要吗?

谢谢。

克雷格

I'm experiencing some problems I can't quite figure out, and one site I found suggested a problem with incompatibilities with verify() if the mocks were created with PowerMock.

When I type a line to create a mock, Eclipse is telling me the method is ambiguous, and I end up having to specify it as EasyMock.createMock or PowerMock.createMock.

I had originally just started with EasyMock and then switched to PowerMock. Does the order of import statements matter, and if you're using PowerMock is it important not to include certain EasyMock stuff?

Here's what I've got:

import org.easymock.EasyMock;  
import org.junit.*;  
import org.junit.runner.RunWith;  

import static org.easymock.EasyMock.*;  
import static org.powermock.api.easymock.PowerMock.*;  
import org.powermock.reflect.Whitebox;  
import org.powermock.api.easymock.*;  
import org.powermock.api.easymock.PowerMock.*;  
import org.powermock.api.mockito.expectation.*;  
import org.powermock.api.mockito.*;  
import org.powermock.api.support.membermodification.*;  
import org.powermock.api.support.membermodification.MemberMatcher.*;  
import org.powermock.core.classloader.annotations.*;  
import org.powermock.modules.junit4.*;  

There may be some redundancies there. Is a conflict possible? And is the order important in order to eliminate the ambiguity?

Thanks.

Craig

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

山田美奈子 2024-11-02 13:21:17

取自 PowerMock 示例

import static org.easymock.EasyMock.aryEq;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.expectLastCall;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.powermock.api.easymock.PowerMock.createMock;
import static org.powermock.api.easymock.PowerMock.expectNew;
import static org.powermock.api.easymock.PowerMock.replay;
import static org.powermock.api.easymock.PowerMock.verify;

请注意,它们不会从这两个库导入 createMock。您不应从已使用 PowerMockEasyMock 导入任何内容。

Taking from a PowerMock example

import static org.easymock.EasyMock.aryEq;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.expectLastCall;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.powermock.api.easymock.PowerMock.createMock;
import static org.powermock.api.easymock.PowerMock.expectNew;
import static org.powermock.api.easymock.PowerMock.replay;
import static org.powermock.api.easymock.PowerMock.verify;

Notice that they don't import createMock from both libraries. You shouldn't import anything from EasyMock that you are already using PowerMock for.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文