Easymock createMock vs @Mock

烈酒焚心 提交于 2019-12-13 01:54:04

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!