Advice on API Mocking Tools

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

Andy

1 Like

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.

1 Like

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.

Joe

1 Like

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, https://exit-23.co.uk/2018/03/15/lifes-a-riot-resources/

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.

3 Likes

Hi Andrew!

We’ve started our experience with data mocks even using some local json/xml files, then moved to local mock servers like Mockoon. It was pretty good, but there were troubles with sharing latest mocks and debugging them by anyone. But most frustrating was that after application upgrade, your previous data mocks were becoming inconsistent.
So, we’ve moved to online data mocking tools like QuickMocker (Online API Mocking Tool). The mocks and request records to mocks available from any location, you can forward requests to your local environment URL which pretty handy during webhooks integration with 3rd parties when you do not have a public URL yet.
I know Postman also has something similar, but it is a bit more difficult to use for data mocking, especially with public URLs. I prefer using postman for sending requests rather than receiving them.

One important reason for mocking apis is so that you are less dependent on the actual API. Here are some examples for why you’d want to mock apis.

The API is under development, but you have the contract and sample requests & responses. Then, you can mock the api to develop at least some automation before the api is available.

You are teaching a course on api testing. You don’t want to use rapidly changing public apis from Google, Twitter etc., or develop your own api. Changes in public APIs might break your break your course. So, you can use mock apis whenever possible.