Easymock createMock与@Mock [英] Easymock createMock vs @Mock
问题描述
我正在将Easymock与junit一起使用来编写我的单元测试.我已经看到了使用不同方法创建模拟对象的不同测试.
Easymock.createMock()和@Mock注释之间有什么区别吗?
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);
和
@Mock
private Obj obj;
两者之间有什么区别吗?
Is there any difference between the two ?
推荐答案
带注释的创建模拟的方法仅在EasyMock 3.2之后可用.带有@Mock
批注的模拟将被注入,否则将由您创建.
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.
我注意到您已经问过一些有关EasyMock的问题,请务必查看用户指南,易于阅读的指南,上面有很多很好的例子!
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!
这篇关于Easymock createMock与@Mock的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!