什么是一个简单的方法来存根/虚拟RESTful Web服务? [英] What is an easy way to stub / dummy a restful web service?

查看:140
本文介绍了什么是一个简单的方法来存根/虚拟RESTful Web服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个Android应用程序,该应用程序将基于REST调用Web服务来获取一些数据。

I want to create an android application, this application will make RESTful calls to a web service to obtain some data.

我知道RESTful接口会有,但我不希望创建我自己的实现的麻烦。有一个简单的方法来创建一个存根REST风格的Web服务,它会返回一些静态的数据,而无需编写一个完全成熟的WS应用程序来做到这一点?

I know what the RESTful interface will be, but I don't want the hassle of creating my own implementation. Is there an easy way to create a stub RESTful web service that will return some static data without having to write a full blown WS application to do this?

推荐答案

大概是做的最好的事情就是创建一个模拟的REST Web服务的服务,您正在开发应用程序code一段时间,然后用$取代C $ C到调用实际的Web服务回归真实的数据,一旦你的应用程序编写。

Probably the best thing to do is create a mock for the REST web service service while you're developing your application code and then replace it with code to call the actual web service returning "real" data, once your application is written.

我目前正在写一个非常类似的应用到你这(就像你)获得从REST风格的Web应用程序的数据。在我的应用程序,我下面的 MVP 模式推荐通过GWT,也记录了Martin Fowler的作为 PassiveView 模式。

I'm currently writing a very similar application to yours which (like you) obtains data from a RESTful web application. In my application, I'm following the MVP pattern recommended by GWT and is also documented by Martin Fowler as the PassiveView pattern.

您想要做什么是抽象掉了code,使REST Web服务调用到一个界面(模型)。这个模型类的责任是提供数据到presenter /控制器。在presenter将处理所有的业务逻辑,然后将数据传递到视图(视图应该是pretty的哑巴,以及允许它也被嘲笑了)。在测试过程中,您将创建一个MockModel实现模型的接口和测试数据传递到presenter - 而不做一个实际的Web服务调用了!然后,当你准备好了,你将取代这个类与实际的Web服务,开始你的集成测试。

What you want to do is abstract away the code to make the REST web service call into an interface (the Model). The responsibility of this model class is to provide data to the Presenter/Controller. The Presenter will handle all of your business logic and then pass data up to the view (the view should be pretty dumb as well allowing it to also be mocked out). During testing, you will create a MockModel to implement the model interface and pass test data to the Presenter - without making an actual web service call at all! Then, when you're ready, you will replace this class with the actual web service and start your integration testing.

该方法有,它会很容易创建特定的(和重复)测试案例在模拟模型的好处。如果你没有实际的Web服务的控制(和我假设你不这样做),这可能是很难(甚至不可能)来实现。结果应该是一个更强大,更好的测试应用程序,而不需要创建任何测试XML或JSON或创建自己的Web服务。

This approach has the added benefit in that it will be easy to create specific (and repeatable) test cases in your mock model. If you don't have control of the actual web service (and I'm assuming you don't), this can be difficult (or even to impossible) to achieve. The result should be a more robust, better tested application without to need to create any test XML or JSON or creating the web services yourself.

这篇关于什么是一个简单的方法来存根/虚拟RESTful Web服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆