org.jmock.Mock 不再可用?
添加了 jMock 2.5.1 中的所有 jars
所以我在尝试遵循 http://www.ibm.com/developerworks/opensource/library/os-eclipse-rmock/index.html
import org.jmock.Mock;
import org.jmock.cglib.MockObjectTestCase;
public class ServiceClassTest extends MockObjectTestCase {
private ServiceClass serviceClass;
private Mock mockCollaborator;
private ICollaborator collaborator;
public void setUp(){
serviceClass = new ServiceClass();
mockCollaborator = new Mock(ICollaborator.class);
}
public void testRunServiceAndReturnFalse(){
mockCollaborator.expects(once()).method\
("executeJob").will(returnValue("failure"));
collaborator = (ICollaborator)mockCollaborator.proxy();
boolean result = serviceClass.runService(collaborator);
assertFalse(result);
}
}
但是,它不起作用?它找不到 org.jmock.Mock,而是建议 Mockery。我尝试使用 Mockery,但它似乎不允许传递参数。
so I added all the jars from jMock 2.5.1
While attempting to follow http://www.ibm.com/developerworks/opensource/library/os-eclipse-rmock/index.html
import org.jmock.Mock;
import org.jmock.cglib.MockObjectTestCase;
public class ServiceClassTest extends MockObjectTestCase {
private ServiceClass serviceClass;
private Mock mockCollaborator;
private ICollaborator collaborator;
public void setUp(){
serviceClass = new ServiceClass();
mockCollaborator = new Mock(ICollaborator.class);
}
public void testRunServiceAndReturnFalse(){
mockCollaborator.expects(once()).method\
("executeJob").will(returnValue("failure"));
collaborator = (ICollaborator)mockCollaborator.proxy();
boolean result = serviceClass.runService(collaborator);
assertFalse(result);
}
}
however, it doesn't work? It cannot find org.jmock.Mock instead suggest Mockery. I tried using Mockery but it doesn't seem to allow passing an argument.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该教程使用 JMock 1,该版本已过时。在 JMock 2 中,
Mock
类已被废除,取而代之的是Mockery
和泛型。而不是
您会执行
mockery
是Mockery
类型的字段的情况。我建议完全忽略该教程,并使用 JMock 网站 上的教程。
That tutorial uses JMock 1, which is obsolete. In JMock 2, the
Mock
class has been done away with, replaced withMockery
and generics.Instead of
you would do
where
mockery
is a field of typeMockery
.I suggest ignoring that tutorial completely, and using the ones on the JMock website.