How to Test API/flow which are dependent on External API response using SOAPUI
Mocks are required in testing when you want to simulate the behavior of complex, external, or uncontrollable components in your system. They are particularly useful for isolating the unit of code under test and for verifying interactions with dependencies.
In this article, we will see how to Mocking REST APIs Using SoapUI. It is an open-source API Testing tool used for both Simple Object Access Protocol (SOAP) and Representational state transfers (REST) services. It is widely used in enterprise applications for the development, mocking, simulation, and testing of web services. This article provides a step-by-step guideline on how to create a REST Mock Service using SoapUI.
Now let’s see the step below.
Stepwise Implementation
Step 1:
Create a new REST project by clicking on REST present on the Toolbar.
Create REST Project Using SOAP UI
Step 2:
Specify the URL for the restful Mock service you want to create.
Specify Name for REST Project and click “OK”
The Rest project created is as follows
Step 3:
In order to create a new mock for the rest project, Right click on the project and click on New REST MockService
New REST MockService
Specify a name for the new mock service and click “OK”
Step 4:
Right click on the mock service and click on Add new mock action
Adding new Mock action
Specify HTTP Method and resource path and click “OK”
Step 5:
To set a mock response, Right click on the mock action and select New MockResponse.
Add a new Mock Response
Specify Name for Mock Response and click “OK”
Step 6:
Select the Media type. In the content section, specify the response that you want to get on calling the mock service. Here we are selecting Media type as application/json and json text in Editor
Content for Mock response
Step 7:
Double click on the mock service( i.e. Login) to open the mock service editor. Click on the green play button to start the mock service.
Start Mock Service
Now, It specifies the port it is running. The service can be stopped by clicking on the square red button.
Mock Service is running on port 8080
Step 8: Select request from Rest project with Post method and end point “http://localhost:8080/login”
Request Rest Project
Step 8: Run the request from Rest project and response from mock server is received
Comments
Post a Comment