Rest – How to simulate a REST API

apirest

I am working on a new project which will query data from a 3rd party REST API. This is for a real time sports data feed, so the feed only works when a game is actually taking place.

Although the 3rd party provides good documentation (XSD, etc), they have no way to simulate a game happening, and so to test code I have written against this API I would have to wait for an actual game to be happening.

My only recourse is to write code to simulate a game on my own, but it seems like a lot of work. How would you approach this?

Best Answer

This is the perfect use case for a mock object. There are mocking libraries for every popular language. You would want to mock the object that provides the REST service responses to return test data. You can either hand-generate the test data or collect it from previous calls to the live system.