Test RESTful API Using SoapUI

This article explains how to test RESTful API using an open source tool SoapUI.

What is SoapUI?

SoapUI is an API testing tool for SOAP and REST APIs.

Why we need SoapUI

We can use SoapUI for testing of the web API and web services. SoapUI supports many things like functional testing, regression testing, load testing, and performance testing etc.

How to download and install SoapUI.

Download SoapUI from here and download 32-bit or 64-bit version which is suitable for your system. For installation, there is no need to do much. Please read the instructions and finish installation like the below screen.

How to test Web API using SoapUI.

SoapUI supports many features but here I am going to explain how we can test the REST API.

To demonstrate API testing here, I have taken a small example of Web API application which has the below methods.

GetEmployees - This will return the list of employees

GetEmployee - It returns single employee based on the employeeId

PutEmployee - It updates existing employee based on the employeeId

PostEmployee - It creates a new employee in database

DeleteEmployee - It deletes existing employee based on the employeeId

Let's start with creating a new Web API application and SoapUI project set up for testing all methods.

Step 1

Create a Web API application.

Step 2

Create a class and decorate with a few validations for properties because we are going to test it later using SoapUI.

publicclass Employee

{

publicint EmployeeId { get; set; }

[Required(ErrorMessage="First Name is Required")]

publicstring FirstName { get; set; }

[Required(ErrorMessage = "Last Name is Required")]

publicstring LastName { get; set; }

publicstring City { get; set; }

[MaxLength(6, ErrorMessage="Zipcode must be six digits")]

publicstring ZipCode { get; set; }

}

Step 3

Create a controller with all operation like GET, PUT, POST and DELETE and give the name as Employeecontroller.

Finally, I will test my validation for required fields, first name and last name. To create this scenario, I will try to pass firstName and LastName empty in my post operation as below it will throw message "The request is invalid" and it will throw our validation message which we had written in our model for first name and last name.

Conclusion

Here we had tested all operations using SoapUI. It's very easy to use SoapUI for testing Web APIs or web services and it has more features like functional testing, load testing, performance testing and regression testing, etc. It is an open source tool so we can download the free version and test our RESTful service very easily.