用于创建模拟器的软件设计模式

发布于 2024-10-25 09:20:19 字数 133 浏览 2 评论 0原文

我当前的任务是等待来自后端(DB)的几个字段,然后在我这边修改它们。后端更改需要时间,同时,我想创建一个模拟器并开始我的更改。有人可以建议是否有一种设计模式,它可以帮助我为后端设计一个模拟器,然后在不进行太多代码更改的情况下,允许我移植到真实的后端值?

My current task is to wait for a couple of fields from the backend (DB) and then modify them at my side. The backend changes will take time and in the meanwhile, I want to create a simulator and start of with my changes. Is there a design pattern, somebody can suggest, which will help me design a simulator for the backend and later on, without much code changes, allow me to port to the real backend values?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

枕梦 2024-11-01 09:20:19

存根应该足够了。

存根为测试期间拨打的电话提供预设答案,通常根本不响应测试编程之外的任何内容。存根还可以记录有关调用的信息,例如记住它“发送”的消息的电子邮件网关存根,或者可能只记录它“发送”的消息数量。

(来自下面链接的 Fowler 文章)

流行的 Java 模拟框架包括:

有关模拟的其他文章:

A stub should be sufficient.

Stubs provide canned answers to calls made during the test, usually not responding at all to anything outside what's programmed in for the test. Stubs may also record information about calls, such as an email gateway stub that remembers the messages it 'sent', or maybe only how many messages it 'sent'.

(From the Fowler article linked below)

Popular mocking frameworks for Java include:

Other articles on mocking:

倾听心声的旋律 2024-11-01 09:20:19

完全模拟您的协作者的东西称为存根。您可以使用一系列框架轻松构建它:jMock、EasyMock、Mockito 等。
存根不是一种设计模式。这是开发、测试和原型设计的总体思路。

The thing that fully emulates your collaborator is called stub. You can build it easy with bunch of frameworks: jMock, EasyMock, Mockito, etc.
Stub is not a design-pattern. It is a general idea for developing, testing and prototyping.

失去的东西太少 2024-11-01 09:20:19

看看mockito,它非常棒。基础知识是:

ClassYouAreTesting fake = mock(ClassYouAreTesting.class);
when(fake.callsSomeMethod()).thenReturn(sampleData);

您可能还需要使用一些依赖注入,以便您可以真实地传递(在生产期间)或模拟(在测试期间)对象到函数。

Look into mockito, it is pretty great. The basics are:

ClassYouAreTesting fake = mock(ClassYouAreTesting.class);
when(fake.callsSomeMethod()).thenReturn(sampleData);

You may also need to use some dependency injection so that you can pass in real (during production) or mock (during testing) objects to functions.

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