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.

https://media.geeksforgeeks.org/wp-content/uploads/20220313204202/Step1-660x401.JPG

Create REST Project Using SOAP UI

Step 2: 

Specify the URL for the restful Mock service you want to create.

https://media.geeksforgeeks.org/wp-content/uploads/20220313204345/URLForMockService.JPG

Specify Name for REST Project and click “OK”

https://media.geeksforgeeks.org/wp-content/uploads/20220313204516/RESTProject2-660x322.jpg

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

https://media.geeksforgeeks.org/wp-content/uploads/20220313205022/Step2-660x322.jpg

New REST MockService

https://media.geeksforgeeks.org/wp-content/uploads/20220313205312/NameForNewMockService.JPG

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

https://media.geeksforgeeks.org/wp-content/uploads/20220313205429/Step3-660x322.jpg

Adding new Mock action

https://media.geeksforgeeks.org/wp-content/uploads/20220313205510/URLandHTTPmethod.JPG

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.

https://media.geeksforgeeks.org/wp-content/uploads/20220313205702/Step4-660x322.jpg

Add a new Mock Response

https://media.geeksforgeeks.org/wp-content/uploads/20220313211048/NameForMockResponse.JPG

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.

https://media.geeksforgeeks.org/wp-content/uploads/20220313211138/Step5-660x598.JPG

Start Mock Service

Now, It specifies the port it is running. The service can be stopped by clicking on the square red button.

https://media.geeksforgeeks.org/wp-content/uploads/20220313211223/MockServicerunning-660x624.JPG


                                      

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

Popular posts from this blog

How AI Integration with RPA Enhances Automation and Expands Its Scope

Exploring Different Types of Software Testing and Their Importance

Efficient Ways of Handling Excel with Blue Prism