问题
I'm using Easymock with junit for writing my unit tests. I have seen different tests following different methods to create mock objects.
Is there any difference between Easymock.createMock() and @Mock annotation ?
Obj obj = EasyMock.createMock(Obj.class);
and
@Mock
private Obj obj;
Is there any difference between the two ?
回答1:
The annotated way of creating the mock is only available since EasyMock 3.2. With the @Mock
annotation the mock is injected, otherwise it's created by you.
From a functional viewpoint, they are the same, it's just the way you set things up/configure it that is different.
I noticed you allready asked some questions about EasyMock, be sure to check the userguide, it's an easy to read guide with a lot of good examples!
来源:https://stackoverflow.com/questions/30527972/easymock-createmock-vs-mock