Thursday 7 May 2020

Introduction to WireMock

WireMock is a Java library used to simulate HTTP APIs. Wiremock is used in both unit, integration testing.

 

For example, your unit test cases can talk to wiremock service, instead of sending requests to actual REST API.

 

WireMock run in two modes.

a.   Embedded Mode

b.   Standalone Mode

 

We are going to develop an Employee Rest Client, which is going to talk to Employee Rest Service to perform CRUD operations.



Employee Rest Service provide the following APIs to perform CRUD operations against employee entities.

 

API

Method

Description

api/v1/employees

GET

Get all the Employees

api/v1/employees/{id}

GET

Get employee by id

api/v1/employees/by-name/?empName={name}

GET

Get all the employees that contain this name.

api/v1/employees

POST

Create new employee

api/v1/employees/{id}

PUT

Update Employee by id

api/v1/employees/{id}

DELETE

Delete Employee by id

 

But here the problem is ‘Employee Rest Service’ is not yet ready and take 2 more months to deliver. But one good thing here is that the contract is ready (means the payload structure and response format of these APIs).

 

Based on the contract we developed the client application. But still ‘Employee Rest Service’ is not available. How can we test the client application now? This is where WireMock comes to rescues us. You can mock the APIs using WireMock and test your client application. Once WireMock setup is done, you can call WireMock service instead of Employee Rest Service application.


Previous                                                    Next                                                    Home

No comments:

Post a Comment