Service Providers for Cucumber

November 13, 2010

Currently I am working on acceptance tests for front end applications that depend on back end services which don’t exist … yet? This means that I have a problem, I need my Cucumber features to create the data that the application will later retrieve. Later I need to test that the UI has retrieved the data and is displaying it.

To do this I need to mock each service, how difficult this is depends on how we access the service.

Consider mocking a service which returns rdf-json from a URL of the format


e.g. .../get_data/?type=story&team="Spurs"& ...

Now this mock server has to parse the query string, and then use this to assemble the data the data that will be returned from the query. This is no small task and could require the creation of a large number of objects. In addition making this as a post is difficult, as there is confusion between the post parameters and the query string.

Now if the mock service returns json from a proper restful url things are much easier

e.g. teams/arsenal/top_story

Here our mock server can respond to a POST on this URL by creating a top_story for Arsenal, using the parameters hash to populate the story. When later our test does a GET on the same URL it should be very simple to retrieve the top story