This post summarises the benefits of using backend service mocks during APIs development. It lists the most popular API mocking frameworks and libraries used across the industry. Read the API mocking tutorial for practical steps.
Why we need mocks?
Mocking is part of software development lifecycle in almost every organization.
Why its so common?
In times of continuos deployment and DevOps practices – automation is the key element of modern software development lifecycle.
Automation allows development teams to utilise the array of software tools to significantly increase the productivity and software quality and faster time to market.
However, in order to continuously develop and test applications you have to handle multiple dependencies.
Many times, the dependencies are not under our control. We have no influence how these dependency systems are developed, released or tested.
This is where mocking comes to the rescue.
Your team can build and maintain mocks which behave like dependency systems as far as your consumer applications are concerned.
Usually, while developing applications you teams have several environments.
Starting with development and team specific environments, other common ones are testing, performance testing, user acceptance, etc.
Development environments are by definition mostly broken and unstable. And they mostly benefit from dependency mocking.
You should carefully asses what problems mocks are solving in other environments and use mocks there if needed as well.
In environments like user acceptance – mocks are not recommended. As all systems should be running smoothly.
The main rule of mocking is that mocks should behave like the actual services.
The common way of agreeing this is to have fixed specifications and contracts between client and the service.
In REST API integration world, this is usually achieved by using OpenAPI specification (previously Swagger).
Such specification document can be version controlled and tracked for any changes. (consumer driven contracts are popular within the industry).
This way, even if the full dependency service functionality is not ready – we can create mocked ones which still correspond to the agreed specification.
API mocking frameworks and tools
Below list has the most popular API integration and mocking frameworks and tools.
- WireMock – Java based, simple API mock server.
- sMockin – Java based API simulator
- Mockbin – API response generator with cloud based UI.
- Mocky – simple API response mocking tool, based on Scala.
- Mountebank – is advanced mocking framework. Allows you to create service virtualisation and emulate APIs.
- Karate – Testing framework, which can be used for creating API mocks.
- SoapUI Mocks – best known tool for working with SOA type services, it also provided mocking capabilities.
- Mockapi.io – cloud based API response mock service.
- Wilma – Service stub and transparent proxy, which allows to capture and analyse API requests.