When backend and frontend developers need a controllable response from the services they depend on, they use a service mock tool. In microservice environments, using service mocks allows reducing resource requirements and generally speeds up the development process.

Mockintosh is an Open Source service mock technology that is designed specifically for mocking in microservice environments. It offers a number of benefits. These include a small resource footprint, multi-service mocking and resiliency testing features.

In this article, we will learn how to install and run the Mockintosh tool for simulating multiple microservices from a single laptop. Towards the end of this article, we'll investigate the options for configuring clients to use a mock instead of a real service.

How dependencies are mocked:

image2

Installing Mockintosh

There are two main ways of installing Mockintosh: via the Python package manager and via Docker. The bare Python way allows for a simpler command-line, while Docker provides perfect isolation and is a step towards running mocks inside Kubernetes.

When installing Mockintosh as a Python package, you need Python 3.x+ as a prerequisite, with the standard pip package manager. The installation command is as simple as:

Copy to clipboard
pip install mockintosh

If you want to start using the Docker way, the prerequisite is to install Docker, and then pull the latest Mockintosh image:

Copy to clipboard
docker pull testrio/mockintosh:latest

Mockintosh aims for the smallest Docker image size, so the pull process should complete super-fast.

After installation, you can quickly validate it with a simple help command:

Copy to clipboard
mockintosh --help

for the Python installation.

Copy to clipboard
docker run testrio/mockintosh --help for the Docker variant.

That command will print out a short help message like this:

Copy to clipboard

usage: mockintosh [-h] [-q] [-v] [-i INTERCEPTOR [INTERCEPTOR ...]]
                  [-l LOGFILE] [-b BIND]
                  [source ...]