Example REST Test in SoapUI

This tutorial walks you through how to perform a REST test in SoapUI. To make sure you get the most value out of this tutorial, please make sure you have the latest release of SoapUI downloaded.

Download SoapUI here

Why Use SoapUI for REST Testing?

While SoapUI Open Source can be seen as the Swiss Army knife for testing, SoapUI Pro is the tool with the sharpest edge. Applied to testing web services, SoapUI Pro focuses on enhancing efficiency and usability. With Point and Click Testing, you can drag and drop instead of manually writing the code. The Form Editor creates a form from your request, eliminating the need for you to spend time on repetitive coding. The Outline Editor simplifies and exposes the XML structure. These functions make your testing less time-consuming. If creativity, flow and speed are important to you as a tester, SoapUI Pro is for you.

REST Sample Project

Getting started with a new application is always a challenge, no matter how complex it is. In order to get started, SoapUI comes with a sample file that can be used as reference and inspiration.

Note: If you chose not to install tutorials when installing the product, you do not have the sample file. Use the SoapUI installer to update the existing installation and get access to the sample file.

The REST sample illustrates some of the basic concepts of testing REST services in SoapUI. Try out the project, run the included mock service and tests to familiarize yourself with the SoapUI interface, and then move on to the Your First SoapUI Project tutorial.

Importing the Project

Let's start by opening the project.

  1. Click Import project on the main toolbar or right-click the root node in the Navigator panel and select Import Project:

    Importing project

  2. In the Select SoapUI Project File dialog, select the Sample-REST-Project-soapui-project.xml file from the <Home directory>/SoapUI-Tutorials folder.

    Importing the REST sample project

  3. The sample project will be shown in the SoapUI Navigator.

    The REST sample project

The structure of a SoapUI project is like this:

  • Project

    • Interface

    • Test suites

    • Mock services

Run mock service

Endpoints of sample requests refer to a mock service. Run the mock service before sending a request to it. Otherwise, the test will fail. To learn more about mock services, see Web Service Mocking below.

To run the sample mock service, do the following:

  1. Double-click the Account creation mock node in the Navigator panel.

  2. In the mock editor, click

    Running Mock service

Functional Testing of REST Web Services

Let's look at how REST tests work in SoapUI.

  1. Expand the Test account creation test suite and the accountcreation test case:

    The REST test case

    As you can see, the test case consists of two REST Request test steps. Each test step sends a request to the testing service and gets a response.

  2. Double-click the Submit Account Details test step. This request contains two parameters. When you set values for them, the parameters are added to the request URL:

    Specifying REST parameters

    To learn more, see Understanding REST Parameters.

  3. Click Run to send the request. You will see the response in the Response panel on the right:

    Sending REST request

    Note: Make sure you run the mock service to get a response.

  4. To validate the response in SoapUI, you use assertions. Click on the test step toolbar, select the Property Content > Contains assertion and click Add.

    Adding an assetion to a REST request

  5. Enter the content that the response message must contain:

    Configuring assertion

    To learn more about assertions, see Getting Started With Assertions

The Test Run

After you add the assertion to the test step, you can run the test case. Double-click the test case in the Navigator panel and click Run in the test case editor. The test case progress bar shows the progress:

Running a test case

Note: If the test case fails, make sure the mock service is running.

REST Service Mocking

SoapUI allows you to simulate the functionality of a web service before it is implemented. This process is called Mocking. It is useful when you cannot use a web service for some reason.

The sample REST Project contains a mock service, so you can examine how it works.

  1. Expand the Account creation mock node and double-click the action that simulates responses to POST requests.

    Mock action editor

    The mock action contains possible responses. The Dispatch setting controls which response should be sent when the mock service receives a request. To learn more, see Mock Action Editor.

  2. Open the Successful response. In the Response editor, you can specify the HTTP status code, headers and the response body. To learn more, see Mock Response Editor.

    Mock Response editor

You may also be interested in ServiceV that provides more functionality for creating virtual services. Try ServiceV Pro for free.