banner



How To Write Web Services Test Cases

API Testing Tools

What is a Web Service?

Web Services are defined in many means.

Spider web Services are client-server applications or components. Some other way to think of them is that spider web services are methods of communication betwixt ii devices over the network.

There are two types of web services: Lather and Remainder (Yous'll learn more than about them after on)

Just how do y'all exam them?

How to Test a Web Service

I often get asked the question "How exercise I go virtually testing spider web services?" and the answer I always requite may surprise you – the aforementioned manner you would test any other application!

In this testing web services guide, yous'll observe:

  • Questions to ask earlier automating a web service
  • Web Service Testing Terminology
  • What well-nigh Rest Services?
  • How To Create a Spider web Service
  • Why create a web service?
  • Create a Web Service
  • Verify that the web service works
  • Information technology's All About the WSDL
  • Looking at a WSDL
  • The iv primary sections of a WSDL
  • Web Service Testing Response and Requests
  • Web Service Request/Response
  • What does Lather have to do with Web Services
  • Soap Faults
  • Open up Source API Testing Tools for Rest and WSDL based services

In general, the best arroyo to normal functional testing is the aforementioned for spider web services (except for the fact that unlike about other applications, web services don't take GUI user interfaces). So accept comfort in knowing the functional testing techniques that yous have ever used still apply. Simply think of a web service every bit a business organization process without a UI, and write your exam case accordingly.

Questions to ask before automating a spider web service

Because web services can be used past many different clients and used in multiple ways, functioning testing and negative testing become more disquisitional. I would suggest y'all brand sure at that place is practiced test coverage in those areas.

Some good question to enquire when automating a web service is:

  • Does the service answer with the correct values?
  • How quickly does the service ship a response to the user?
  • Can the service handle expected and unexpected user loads?
  • Can the service handle invalid values and exceptions caused by bad data?
  • API Testing Tools

What is a Spider web Service Testing Terminology

The biggest hurdle for virtually testers is acclimating to the terminology used when talking almost web services. For example:

  • WSDLs – an XML format that tells you how to access a web service. A WSDL is automatically generated for you. Nigh test tools read in a WSDL and present all the data you need to interact with it.
  • Lather (Simple Object Access Protocol) – a protocol that uses XML format to substitution info to and from a Web service.
  • SOA (Service-oriented architecture) – a mode in which companies tin organize software that tin can be apace inverse to answer to the requirements of the marketplace.
  • Web Service – units of software that run in a network. Typically written to handle a specific business procedure. Spider web services tin be strung together in multiple ways and used by different applications to create desired functionality.

I believe that once the above terms are demystified, the job of testing web services is pretty straightforward. I too feel that the best way to demystify something is to intermission it down into uncomplicated, hands-on examples.

In this series, I hope to present some uncomplicated easily-on examples that suspension down what a web service actually is, and how one works in general. Hopefully, knowledge plus know-how will equal automation awesomeness!

What about Rest Services?

REST (Representational Land of Transfer) is a lightweight choice for developing web services the utilise the HTTP protocol –a fact that makes it simpler with less overhead than a web service that uses the Soap protocol.

Near folks have moved from this older method of using a WSDL web service to using Residual instead.

For this mail service, we'll exist looking at WSDL-based services, not Residuum. For advice on how to get started testing REST APIs check out my mail service on balance-assured.

How To Create a Web Service

Ok to get started – let's create our very own spider web service. We will then utilise the web service we created as the basis for the balance of this serial.

When we first testing and looking at the WSDL and the services request, and response the information should make more than sense since we volition be able to map the values dorsum to the source where they came from.

Why create a web service?

If you're annihilation like me, the all-time way for yous to learn is past actually doing.

I've plant that to empathize how something works it sometimes helps to actually try information technology yourself –then I devised a simple example of how to create a web service to help teach some of the concepts of web service testing.

Create a Web Service

Now nosotros will create a simple service that contains 1 method that adds ii numbers together. Okay… I admit information technology's not the coolest web service, but information technology volition serve our purpose. Before you lot first, make sure you have the following setup:

  • Microsoft's Internet Information Services (IIS) is upwards and running on your car
  • The latest.Net Framework SDK is installed
  • Create a directory under your C:\Inetpub\www.root named WebServices (wwroot image)

Next, go ahead and copy the post-obit lawmaking into notepad:

Basically, the first line s saying that this a spider web service, and the language used is C#.

Then we import 2 namespaces Organization and Organization.Web.Services.

Next, we create our form DEMOAddNumbers and add together our method named AddThis that accepts two parameters of type integer — x and y. Finally, we add the values together and return an integer value mySum that contains the sum of the passed parameters.

Save the file every bit DEMOAddNumbers.asmx and identify information technology nether your wwwroot/WebServices directory. FYI asmx is the file extension used for ASP.NET.

Create a web.config file

To get this to piece of work on my auto I as well had to add a web.config file to my C:\Inetpub\wwwroot directory. Open notepad and copy the following:

Proper name the fileweb.config and save it under C:\Inetpub\wwwroot

Verify that the web service works

Next, open upwards your browser and enter the following accost:

http://localhost/WebServices/DEMOAddNumbers.asmx/AddThis?x=forty&y=2

The page should return the value of 42 (Which by the fashion is also the reply to the pregnant of life – hehe)


Sweet – we now have a working web service! In Part 2 of this series, we volition utilise this web service to help reply the question of what is a WSDL?

It's All Nearly the WSDL

Nosotros're now going to take a look at what is WSDL is. A WSDL is an XML certificate that describes the methods, method parameters, namespace, and handling URL for a spider web service.

WSDLs, along with some other forms of documentation, are generated automatically whenever an HTTP-Become request is received by a .asmx file. For an instance, navigate to:

http://localhost/WebServices/DemoAddNumbers.asmx


This should bring upwards an HTML page that describes the methods of the DEMOAddNumbers web service along with some other info.

Clicking on the link for the AddThis method from this page will bring up some other HTML page that allows you to examination the operations of the service.

Pretty absurd, huh?!? And now, let's take a expect at the actual WSDL.

Looking at a WSDL

For our spider web service, enter the following URL into your browser:

http://localhost/Webservice/DEMOAddNumbers.asmx?WSDL

The WSDL for our web service (DEMOAddNumbers) should appear. Observe, once again, that nosotros didn't do annihilation special to generate the WSDL — it was created for us automatically. As you can see, a WSDL document is really just an XML document that contains information about a web service.

The four main sections of a WSDL

A WSDL is broken up into four main sections: elements types, letters, portType, and binding.

element types – Is the data types that are used by the web services.
Detect how the data in the WSDL matches the code in our web services.

 bulletin element – This section describes the letters used by the web service and defines the information elements of an performance:

the binding element describes the communication protocols used by the spider web service:

portType element – The fourth chemical element, portType, is mostly considered to be the virtually important chemical element because it describes the web services and all the operations that can exist performed, as well as all the letters of the service:

In the section above, the portType chemical element defines DEMOAddNumbersSoap, DEMOAddNumbersHttpGet, and DEMOAddNumbersSoapPost every bit the proper noun of the ports, and "AddThis" as the name of the performance.

Also notice that the ports are a Request-Response operation, meaning that our web service can receive a request and will return a response. For example:

Request a request chosen AddThisHttpGetIn
wsdl:input bulletin="tns:AddThisHttpGetIn"
Return a response called AddThisHttpGetIn
wsdl:output message="tns:AddThisHttpGetOut"

Next, let'due south expect at the process of sending and receiving a request from a web service using a exam tool.

Web Service Testing Response and Requests

Now that we accept a working web service and empathise a basic WSDL, let's accept a look at a spider web service's request and response.

First, allow's import our WSDL into our exam tool of selection. I will exist using SOAPUI (a free open source tool), just you tin can employ whatever tool yous like.

In SoapUI, click on 'File\New soupUI projection'. In the New soapUI project, enter the Project Proper noun: AddNums, and for Initial WSDL/WADL enter:

http://localhost/Webservice/DEMOAddNumbers.asmx?WSDL

SoapUI should import the "AddThis" method under projects AddNums\DEMOAddNumbersSOAP. Double-clicking on the AddThis 'Asking one' will show the post-obit:

*Remember — the WSDL should include all the info needed to interact with a spider web service. That's why soapUi was able to read in the WSDL and automatically generate a asking with the correct inputs for y'all.

Web Service Asking/Response

Our DEMOAddNumbers web service is the most typical kind, in that, a requester (in this case our test tool) sends a asking to the service and waits.

The service and so processes the request and sends a reply. Let's encounter this in activity:

For our request, let'southward do a positive test past sending the service valid values:

This is the response I get dorsum when I transport the request from SOAPUI:

What does SOAP accept to practice with Web Services

How does this communication take identify? Basically, Lather — which is an XML-based protocol used for communicating with a Web Service — sends info to the asking over HTTP. SOAP stands for Simple Object Admission Protocol. If we expect at our asking, we volition see lather elements such equally SOAP Envelope, Header, and Body.

This is what a typical Lather XML bulletin contains.

Lather Faults

For a Negative Exam — if nosotros transport bad data in the request, a SoapFault should occur. And so, if we ship:

We should get back a soapFault:

As we can see, the SOAP XML is the aforementioned as our previous response, merely now it as well contains a Fault element. A Error chemical element contains errors and status info.

Open Source API Testing Tools for Remainder and WSDL based services

Remember Selenium is just for browser-based testing, you may exist wondering which tool to use for Residuum and Soap web service-based testing.

Bank check out my article on fifteen Open Source API Testing Tools For REST & SOAP Service

Testing Web Services Wrap Up

And that's my have on web services in a nutshell. For a deeper swoop, I recommend checking out the site www3school. I've too found SOA for the Business Developer: Concepts, BPEL, and SCA (Business Developers serial)
to be a slap-up resources volume.

If y'all are using Unified Functional Testing also check out my latest Pluralsight video course

Quick Guide to API Testing with HP's Unified Functional Testing

How To Write Web Services Test Cases,

Source: https://testguild.com/test-web-services/

Posted by: culpculoak.blogspot.com

0 Response to "How To Write Web Services Test Cases"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel