Table of Content
- 1 Introduction
- 2 Use Case
- 3 Solution
- 4 Conclusion
- 5 References
SoapUI, a free and open source cross-platform Functional Testing tool implemented in Java is very stable and robust providing an easy-to-use graphical interface. SoapUI’s key features include Functional Testing, Service Simulation, Security testing, Load Testing, Technology Support, Automation, Analytics, Recording and Ecosystem.
SoapUI works very well with Soap and REST web services:
- Web service regression testing
- Web service test automation
- Web service load testing
Let’s discuss about API Functional Testing in this blog.
Let’s say your project has several web service APIs through which its data can be used on web applications. Today, most of the APIs are based on web services due to their ease of use, security and performance.
Testing web services is difficult, time consuming and error prone without a proper testing tool. The regression and load testing for a web service are impossible in these cases and testing becomes a manual recursive procedure without a chance for automation.
The SOAP UI testing tool solves these issues.
- Download and install the compatible SoapUI from http://www.soapui.org/
- Install JDK 1.6+
Create a new REST service in SoapUI using the graphical interface
- Open SoapUI
- Go to File -> Select New REST Project
- Type a webservice URL that is used in your project. Here is a sample URL – http://localhost:8080/restful/getdetails
- Click OK, a Request window opens that has
- Method: Get/POST
- Endpoint: Host of the webservice (http://localhost:8080)
- Resource: Name of the webservice
- Parameters: If the webservice has field and values then it is shown in Parameters
- Click the green button to run the webservice. The screenshot below illustrates the JSON response for the above webservice:
- Headers button at the bottom of the window shows the status of the HTTP request, content-type, data etc.,
Create TestCase for the above webservice
- Click the ‘+’ button next to STOP button
- It prompts to create a TestSuite, TestCase and TestStep. For the service mentioned above, we need to create a TestSuite in the project initially and then add this testcase to the testsuite
- Once a TestCase for the service is created, a new window appears with details such as endpoint, resource/method similar to creating a new REST service
Validating the service responses
Next, validate the webservices response using Assertions.
Now, before proceeding with the validation process, let’s understand about Assertions.
Assertions are used to validate the message received by a TestStep during execution, usually comparing parts of the message (or the entire message) to some expected value. We can add any number of assertions to a TestStep. During execution, if any TestStep fails, the status is marked as “failed” in the TestCase view and a corresponding FAILED entry is shown in the Test Execution Log.
There are two ways to validate the service response:
- Add Assertions to the REST test step
- Get the service response using Groovy script and add Assertions to the response
Adding Assertions to the REST test step
At the bottom of TestStep window, appears a button labeled “Assertions”.
SoapUI supports many assertions such as contains, validating HTTP status code, Xpath, script assertions etc.
Let’s understand the basic assertions – contains and validating HTTP status code.
- Click Assertions button and click + button, to add assertions to the TestStep
- In Add Assertion window, select Property Content then select Contains and click Add button
- Check for the content db_healthy and ignore the case in comparison
- If the JSON response has a content db_healthy then the Assertion status turns Green which is a passed testcase, otherwise the testcase status has failed and appears Red
Get the service response using Groovy script and add Assertions to the response
SoapUI has many TestSteps like REST Test Request, HTTP Test, Groovy script, JDBC Request, Properties etc.,
Let’s talk about Groovy Test Request:
Right click TestCase, select Add Step and then select Groovy script
The screenshot below illustrates the Groovy script to validate the HTTP status using JsonSlurper class for JSON response highlighting the assertions used to validate the service:
- SoapUI, the world’s leading and most complete SOA and web services testing tool allows you to rapidly create and execute automated functional, regression, compliance, and load tests at ease
- It offers a complete test coverage and supports all the standard protocols and technologies in a single test environment
- SoapUI is an essential tool for web service testing similar to MS Excel that facilitates creating spreadsheets