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"}

SafeTest: Next Generation Testing Framework from Netflix

Posted on 03/26/2024

When you think of Netflix the last thing you probably think about is ...

Top Free Automation Tools for Testing Desktop Applications (2024)

Posted on 03/24/2024

While many testers only focus on browser automation there is still a need ...

Bridging the Gap Between Manual and Automated Testing

Posted on 03/13/2024

There are some testers who say there’s no such thing as manual and ...