Automation Testing

soapUI – How to Test a REST Service

By Test Guild
  • Share:
Join the Guild for FREE
API Testing Tools

What is REST? Why is it Needed

REST (Representational State of Transfer) is a lightweight option for developing web services the uses the HTTP protocol –a fact that makes is simpler with less overhead than a web service that uses the SOAP protocol.

Today we'll be looking at soapUI but you can also programmatically test a rest service using a library like rest-assured without using a vendor tool.

(If you're interested in learning how to use soapUI to test SOAP web services, check out my post/video: soapUI – How to test a web service.)


Twitter API

For this example, I'll be using the Twitter API (GET statuses/user_timeline Resource) to perform a search for and return the last five tweets on my Twitter timeline:

https://api.twitter.com/1/statuses/user_timeline.rss?screen_name=jcolantonio&count=5

How to use soapUI to test REST service

Here are the steps to follow to get started using the free version of soapUI with REST testing:

    1. Create a new project in soapUI named TWITTER REST (make sure you select the Opens dialog to create REST Service); click “OK”


    1. In the New REST Service dialog, enter the Service Endpoint:
      https://api.twitter.com/1/statuses/user_timeline.rss?screen_name=jcolantonio&count=5
    2. Click on the “Extract Resource/Method” and click “OK”


    1. On the New REST Resource dialog, click on the “Extract Params” button. You should have two parameters named id and count. Click “OK”


    1. In the New REST Method dialog, enter the Method Name, “GET JOE TIMELINE” and click “OK”


    1. Click on the “GET JOE TIMELINE” Request 1 and click on the green run arrow


  1. Cool! You should be able to see the XML results returned from the Twitter service:


Now let's add assertions to validate the response

In order to verify that the correct response has been returned, you'll need to add an assertion. For this example our assertion is going to verify that five twitter entries were indeed returned by response of the service.

    1. First, click on the request's “Add this REST request to a testcase” icon.


    1. Name the testsuite “TWITTER REST,” and the TestCase “GET TIMELINE.”
    2. Add the Request to TestCase. Accept all the default values and click “OK.”


    1. You should now have a TWITTER REST testsuite under your soapUI project:


Click on “GET JOE TIMELINE” Request and click “Assertions” then click on the “Add an assertion” icon.


    1. In the “Add Assertion” screen, click on Property
      Content>XPath Match and click the “Add” button.


    1. For the XPath Expression, enter:
declare namespace ns1='http://www.w3.org/2005/Atom';
count(//ns1:feed/ns1:entry)

 

    1. Expected Result: enter “5.”


  1. Click the “Save” button and re-run.
  2. Your “assertion” should be green.


How to Test a REST service and Rest Easy

That's it! You can now rest easy in the knowledge that you now know how to test a REST service using soapUI!

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

The 4 Destroyers of Any Automation Test Script

Posted on 09/05/2023

After interviewing over 500 test engineers on my podcast, I've identified the four ...

Unraveling the Automation Scorecard: Where Do You Stand?

Posted on 08/03/2023

Do you know what your Automation Scorecard Score is? No? Not sure you ...

3 Time Saving AI Assisted Features for Testers (Katalon Studio)

Posted on 07/11/2023

The software testing landscape is rapidly evolving, with artificial intelligence (AI) and machine ...