开发者

EasyMock / PowerMock import question

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.create开发者_JAVA百科Mock 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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜