You are reading the article Web Services Testing Tutorial: How To Test? Learn With Example updated in September 2023 on the website Benhvienthammyvienaau.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested October 2023 Web Services Testing Tutorial: How To Test? Learn With Example
What is WebService?Web Services is the mechanism or the medium of communication through which two applications / machines will exchange the data irrespective of their underline architecture and the technology.
What is Web Service Testing?Web Services Testing is a type of software testing that validates Web services. The purpose of Web Services Testing is to check the functionality, reliability, performance, and security of an API(Application Program Interface). Web Service Testing is similar to unit testing in some cases. You can test a Webservice manually or create your own automation code or use an off-the shelf automation tool like Postman.
Why is WebService Needed?In general, software applications are developed to be consumed by the human beings, where a person sends a request to a software service which in-turn returns a response in human readable format.
In the modern era of technology if you want to build a software application you don’t need to build each and everything from scratch. There are lots of readymade services available which you can plug into your application and you can start providing those services in your application.
For example you want to display weather forecast information you don’t need to collect, process and render the data in your application. You can buy the services from the people who already well-established in processing and publishing such kind of data.
Web services allow us to do these kind of implementations.
As an example, consider the following WebService
It gives Share Value for a Company.
Let’s find share price for Google (Symbol: GOOG )
The response XML gives the stock price.
This WebService can be called by a Software Application using SOAP or HTTP protocol.
Web Service ProtocolsWeb Services can be implemented in different ways, but the following two are the popular implementations approaches.
SOAP (Simple Object Access Protocol)
REST (Representational State Transfer architecture)
SOAPSOAP is a standard protocol defined by the W3C Standard for sending and receiving web service requests and responses.
SOAP uses the XML format to send and receive the request and hence the data is platform independent data. SOAP messages are exchanged between the provider applications and receiving application within the SOAP envelops.
RESTREST means REpresentational State Transfer; it is an architecture that generally runs over HTTP. The REST style emphasizes the interactions between clients and services, which are enhanced by having a limited number of operations. REST is an alternative to SOAP (Simple Object Access Protocol) and instead of using XML for request REST uses simple URL in some cases. Unlike SOAP, RESTFUL applications uses HTTP build in headers to carry meta-information.
There are various code that REST use to determine whether user has access to API or not like code 200 or 201 indicates successful interaction with response body while 400 indicates a bad request or the request URI does not match the APIs in the system. All API request parameters and method parameters can be sent via either POST or GET variables.
Rest API supports both XML and JSON format for WebServices API Testing. It is usually preferred for Mobile and web apps as it makes app work faster and smoother
WSDLWSDL (Web Services Description Language) is an XML based language which will be used to describe the services offered by a web service.
WSDL describes all the operations offered by the particular web service in the XML format. It also defines how the services can be called, i.e what input value we have to provide and what will be the format of the response it is going to generate for each kind of service.
How to test a Web Service?To test web service, you can
Test Manually
Create your own Automation Code
Use an off-the shelf automation tool like SoapUI.
Web Services Automation Testing involves following steps –
Suppose we want to test web service which provides Currency Conversion Facility. It will the current conversion rates between the different countries currency. This service we can use in our applications to convert the values from one currency to the other currency.
Now lets look at above steps
Step 1 to 4: Understanding WSDL and determining operations & XML formats Step 5: Using a tool or writing code to send request and validate the response
Using Java
Using SoapUI
PART 1) WebService Testing Using Apache Axis2 API (Java).Generally web service takes the request and sends the response in the XML format.
Apache Axis2 API project is a Java implementation API, which will be used to create the Web services for both server side (service provider) and client side (service consumer).
Axis2 is capable of sending SOAP messages and Receives & Processes the SOAP messages. We can write a small Java program using the API to create the web service. Axis2 will generate the WSDL from Java program which will be used to communicate the services offered by the web service. We can use the same Axis2 to generate the Java class (stub) from WSDL file which we can use as a client program to generate the web service request, to send the request to the service end point and to process the response.
Basically we will create a simple Java program in which we will instantiate the stub class.
Using the stub we will invoke the request method by passing all the required information.
Stub program will convert that request into XML request format and sends it the service end point which will read the request and processes the request and sends the response in XML format.
The XML response will be converted into Java class by stub and returned to the actual program.
Let’s look at above steps in detail
Step b) Create a folder to keep all the generated artifacts
Ex : C:AxisProjectsCurrencyConverter
Step c) Open the command prompt and navigate to the folder structure where you want to generate the artifacts and Run the following command which will generate the stubs
Step d) Once the command is successfully run, you will see the folder with required files.
Step e)In the next step of this Web Services Testing tutorial, we have to create the client program, through which we will send the actual request using the generated stubs. Open the eclipse and create the new Java project and select the folder which we have created above.
Step f) Add all the axis2 related jars to project build path, which will be there in lib folder of the axis2 software folder
(for ex : C:Axisaxis2-1.6.2lib)
Step g) Create a new Java class (ex : Client.Java) and instantiate stub object. Using the stub object we can call all the supported methods of the particular WebService.
Client.Java Program package org.apache.axis2.currencyconvertor; import org.apache.axis2.currencyconvertor.CurrencyConvertorStub.ConversionRate; import org.apache.axis2.currencyconvertor.CurrencyConvertorStub.ConversionRateResponse; import org.apache.axis2.currencyconvertor.CurrencyConvertorStub.Currency; public class Client { public static void main(Java.lang.String args[]) { try { ConversionRate conversionRate = new ConversionRate(); conversionRate.setFromCurrency(Currency.USD); conversionRate.setToCurrency(Currency.INR); ConversionRateResponse conversionRateResponse = stub.conversionRate(conversionRate); System.out.println("Conversion Rate from INR to USD : " + conversionRateResponse.getConversionRateResult()); } catch (Exception e) { e.printStackTrace(); } } } PART 2) How to Test Using SoapUI Web ServiceIn SoapUI
Enter the project Name and the WSDL URI location
Enter the From Currency and To Currency
Response XML will be displayed right side pane.
As you may conclude, usage of WebService Test tools like SoapUI expedites your Web Services Automation Testing Effort. Hence SoapUi will be focus of our learning in the succeeding tutorials.
Summary
Software Applications communicate and exchange data with each other using a WebService
SOAP and REST are 2 popular protocols to create a WebService
SOAP supports XML based data exchange
REST support XML, Json or exchange of data in simple URL for WebServices API Testing.
WSDL is XML based language which will be used to describe the services offered by a web service. SOAP is defined using WSDL.
To test WebService you can
Create your own code. For instance use Axis2 API for Java
Use WebService Test Automation tools like SoapUI
Automation Tools like SoapUI will jumpstart your Web Services Automation Testing efforts, will require less coding effort compared to creating your own code using Axis2 API
FAQWhat is Difference between WebService and WebAPI?
Web Service Web API
Defined by W3C, all communication & data exchange is based on XML
Web API communication & data exchange could be XML, JSON or plain data
It has defined standards – WSDL
No defined standard
You cannot compress the data but you can compress the HTML request
You can compress the data
Example: SOAP
Example: REST
Learn more about Web API Testing
This Web Services Testing tutorial is made possible with contributions of Mr. Narender Reddy Nukala
You're reading Web Services Testing Tutorial: How To Test? Learn With Example
Update the detailed information about Web Services Testing Tutorial: How To Test? Learn With Example on the Benhvienthammyvienaau.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!