Advice on API Mocking Tools

(Andrew) #1

Hi there,

No, I don’t mean tittering away at an API as it tells a bad joke :slight_smile: (sorry had to get that one in there!)…but, seriously, I was interested in hearing peoples experiences of using mocking, specifically for API testing.

Whilst I’m (fairly!) well versed in automation techniques now, I haven’t yet used this approach but would like to find out more about it. I’m just interested to hear peoples opinions on the tools which are good to get to grips with(regardless of language), tutorials etc. Wiremock is one I have seen referenced quite a bit, but was interested to hear about others too.

I know that I need to firm up my understanding in this area as I’m yet to fully understand why as a tester we’d want to mock APIs(I’m sure in time, all will be revealed!)

Thanks as ever


(Dave) #2

I’ve just started playing around with mocking myself - I’m trying it out in a couple of tools (Postman and SoapUI). The reason I’m looking at it is so that I can see how the front end component works with Post calls. I can’t run the backend in our component builds so I need some way to give my component data ‘responsively.’

I"m just at the early stages of using this so I don’t have much advice on it at this point, but I’ll probably share something about it on my blog once I figure out how it might be valuable for the work I’m doing.

To be honest, I would guess that the tool used to do the mocking, matters much less than actually understanding why to mock and when it makes sense to do so in a way that is going to add value :slight_smile:. Understanding that is where I’ll be spending most of my time exploring how to use mocks.

(Joe) #3

We recently completed a project to centralized the use of a vendor API. When someone in the enterprise wants to use the services of the vendor, they go through our product. It is, basically, and API wrapper around the vendor API.
We wanted to execute some performance testing of our product however the vendor did not provide a performance environment. My solution was to create mocks that simulate the vendor behavior. That is, I created an API to match vendor responses to API wrapper requests. With the use of the mocks, the API wrapper does not know if it is talking to the vendor or the mock. To use the vendor mock, we had only to change a configuration file in the API wrapper.

Additionally, we used mocks (specifically RhinoMocks) extensively for both unit tests and behavioral tests. These mocks simulated behaviors of database responses and other low level dependencies so that we could exercise specific bits of code.


(Christopher) #4

Hi Andrew,

There are plenty of options. Tools like Wiremock are a great way to get started. Postman includes a Mock server which is handy if you’re already using Postman.

I tend to write mocks using either Sinatra (Ruby) or Express (JavaScript). Ash Winter and I have some materials on Github that might be useful,

Why use mocks? Here are some common scenarios:

  • You’re app/website uses a third party API and you want to test scenarios involving errors which can’t be reproduced on the test environment they’ve supplied. Using mocks you can return whatever responses you can think you can imagine.

  • You have slow automated checks because some of your API’s are slow to respond. In this case, you can mock the APIs to ensure response data and times are consistent.

  • You’re working with a 3rd party who are building an API. You have an agreed schema but it’s still early days and they don’t have anything you can test against. Your developers build based on the spec, and you mock the API so you can test.