org.jmock.Mock 不再可用?

发布于 2024-12-25 16:33:37 字数 1041 浏览 2 评论 0原文

添加了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

初见 2025-01-01 16:33:37

该教程使用 JMock 1,该版本已过时。在 JMock 2 中,Mock 类已被废除,取而代之的是 Mockery 和泛型。

而不是

Mock mockCollaborator = new Mock(ICollaborator.class);

您会执行

ICollaborator mockCollaborator  = mockery.mock(ICollaborator.class);

mockeryMockery 类型的字段的情况。

我建议完全忽略该教程,并使用 JMock 网站 上的教程。

That tutorial uses JMock 1, which is obsolete. In JMock 2, the Mock class has been done away with, replaced with Mockery and generics.

Instead of

Mock mockCollaborator = new Mock(ICollaborator.class);

you would do

ICollaborator mockCollaborator  = mockery.mock(ICollaborator.class);

where mockery is a field of type Mockery.

I suggest ignoring that tutorial completely, and using the ones on the JMock website.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文