views:

1329

answers:

6

I have already read the posts link text and link text but these are covering the use case of building a REST service on the server and requiring a rapid client in order to test those services.

We have the opposite problem, we are building a web client that will communicate to the server via REST, but the decision has been taken to let the client drive the format of the services on the server, this means the client is being implemented first and the services on the server second.

I am trying to look for a tool which would allow me to very quickly knock up REST web services, which the client could then be tested against. Effectively mocking the server.

Does anyone know of such a tool?

A: 

You could just create a result document and put it on a web server.. Then point the REST URL at the document. No matter what your input the output is always the pre-formated result.

Chris Nava
Could do but that would only be useful for testing 200 -OK responses. I would love to have something where it could throw me some curve balls in terms of the responses in order to put the client through its paces.
ChrisInCambo
+1  A: 

Depends on how your REST service will actually return the data. You should be able to abstract all the service calls and then mock JSON responses - randomly rotating the responses should be pretty straight forward.

The other thing you could do is put several result docs on the server (as above) and rotate them from the client by randomly altering the requested service URLs.

Toby Hede
Mocking the service call methods and returning JSON is my current approach. This works quite well. I think I'm looking for something that doesn't exist :-)
ChrisInCambo
+1  A: 
Eugene Lazutkin
A: 

Consider using the Facade design pattern then simply add a configuration value for a "simulation mode". You can then create the entire client with a simulation mode. Then, when the server is ready, update the Facade to work with the new server.

I've done this with several projects and it has been tremendously successful. Especially in large enterprise applications where some small service could go down, but the rest of the system should continue running. Just have the facade give a "simulate mode" warning to the user so they know the results probably aren't real.

User1
+1  A: 

If you are in the Microsoft world then I would take a look at the Microsoft.Http libraries that are in the WCF REST starter kit. There is a Microsoft.Http.Test project that has a lot of examples of how to stub http requests by either adding a stub stage in the HttpClient processing pipeline, or by building a dummy server on top of HttpListener.

HttpListener is a great .Net framework class that allows you to build a running web server in just a few lines of code. Along with the Microsoft.Http library you could produce a server that returns fake results pretty easily.

Darrel Miller
A: 

Simple - use SoapUI from Eviware (free) to Mock your service.

It has the built in concept of a 'Mock' service where you can define an endpoint and have that enpoint respond to requests with realistic looking data. Once defined the mock service can be started and will happily sit there responding to requests from clients. You can even control it programatically and have it send back different responses depending on the request.

The online tutorial on service mocking is really good here.

It's easier if your application has a WADL or WSDL to work from, but not having these just means that you'll have to put in a little extra effort to create your initial Mock service.

benwilcock