1

I'm looking to mock responses from an external API service that returns JSON during live events.

The first response would contain (fake) events that have happened up to time X, the second response would contain (fake) events up to time X + N where N is the interval between requests.

I'm not sure how to do this. Up until this point I have only mocked single responses, which was easy by just intercepting the response. However now I need to test against multiple requests.

3

In unit testing, you'd mock the client part of this system so the calls never get made and the replace client library simply returns the results you expect the real system to return.

If you're doing a wider unit test and need the server, then you'll need to implement a real http server (there are many embedded servers that I'd use here as they're easier to setup and run - they could be part of your build for local testing) and have it return the required responses.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.