java EasyMock / PowerMock 导入问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5435438/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 11:07:33  来源:igfitidea点击:

EasyMock / PowerMock import question

javajuniteasymockpowermock

提问by Craig Anderson

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.

我遇到了一些我无法弄清楚的问题,如果模拟是使用 PowerMock 创建的,我发现的一个站点建议存在与 verify() 不兼容的问题。

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.

当我键入一行来创建模拟时,Eclipse 告诉我该方法不明确,我最终不得不将其指定为 EasyMock.createMock 或 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?

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

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

克雷格

回答by stevebot

Taking from a PowerMockexample

从以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;

Notice that they don't import createMock from both libraries. You shouldn't import anything from EasyMockthat you are already using PowerMockfor.

请注意,它们不会从两个库中导入 createMock。你不应该从EasyMock你已经使用的东西中导入任何东西PowerMock