September 22, 2004 Functional Testing of Web Services, QAI Conference 1
Functional Testing of Web Services
© Copyright 2004 – CGI Group Inc. September 22, 2003September 22, 2003
2004 International Quality Conference, Toronto, Ontario, Canada
2004 International Quality Conference, Toronto, Ontario, Canada
Yury Makedonov, CGI
Yury Makedonov, CGI
Agenda
¾Why we are getting more and more web services testing
¾What are web services ¾What is XML
¾How to test web services
¾Test Approach
¾ Tools
¾Summary ¾Q&A
September 22, 2004 Functional Testing of Web Services, QAI Conference 3
Introduction
¾
Webservices have no GUI. Typically this type of
testing is performed by developers.
¾
Independent testing teams started getting more and
more webservices testing projects
¾
Why are webservices so special?
Why web services?
¾
Web services are a simple interface using HTTP
protocol.
¾
Web services can be:
¾developed by one company, ¾used by another company, and ¾hosted by a third company.¾
Such involvement of several companies is a
business cases for independent testing of web
services.
September 22, 2004 Functional Testing of Web Services, QAI Conference 5
What are web services?
¾
What’s in the name
Web Services?
¾Web means HTTP protocol,
¾Services means request – response.
¾
Web services is a stateless protocol
¾we send a request, ¾we receive a response, ¾we are finished.
¾
Why is this so important from testing point of view?
¾Because we can prepare independent test cases that areseparate files. This makes our test approach relatively simple.
XML
¾
Web services use XML encoded data (XML files) for
communication.
¾
What is XML?
¾
XML file is a text file that uses tags, similar to HTML
tags, to describe data.
¾
Why is this so important from testing point of view?
¾Because our test cases (files) should be in XML format.September 22, 2004 Functional Testing of Web Services, QAI Conference 7
Examples of XML tags
¾
Examples of XML tags from auto insurance:
¾<DateFirstLicensed>1990-06-12</DateFirstLicensed> ¾<DateOfBirth>1969-07-21</DateOfBirth>¾<DriverTraining>Y</DriverTraining>
………
These samples are pretty intuitive.
¾
Examples of blank XML tags (value not specified):
¾<Company/>¾<Department></Department>
More XML details – document definition
¾
Every XML document has to have a certain structure
and certain values of parameters.
¾
Special files, defining XML documents, are used.
Two major types are:
¾DTD (Document Type Definition) – flat text file,
September 22, 2004 Functional Testing of Web Services, QAI Conference 9
Sample – “Document Type Definition”
¾
Note.xml:
¾<?xml version="1.0"?>
¾<!DOCTYPE note SYSTEM "note.dtd"> ¾<note>
¾ <to>Tove</to> ¾ <from>Jani</from>
¾ <body>Don't forget me this weekend</body> ¾</note>
¾
Note.dtd
:
¾<!ELEMENT note (to,from,body)> ¾<!ELEMENT to (#PCDATA)> ¾<!ELEMENT from (#PCDATA)> ¾<!ELEMENT body (#PCDATA)>
Sample – “Schema Definition” – Document
¾Note.xml:
¾<?xml version="1.0" encoding="UTF-8"?> ¾<ServiceAddressRequest xmlns:xsi="http://www.w3.org/2001/" xsi:noNamespaceSchemaLocation="Note.xsd"> ¾<note> ¾ <to>Tove</to> ¾ <from>Jani</from>¾ <body>Don't forget me this weekend</body> ¾</note>
September 22, 2004 Functional Testing of Web Services, QAI Conference 11
Sample – “Schema Definition” – Schema
¾
Note.xsd
:
¾<?xml version="1.0"?> ¾<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" ¾. . . . ¾<xs:element name="note"> ¾ <xs:complexType> ¾ <xs:sequence>¾ <xs:element name="to" type="xs:string"/> ¾ <xs:element name="from" type="xs:string"/> ¾ <xs:element name="body" type="xs:string"/> ¾ </xs:sequence>
¾ </xs:complexType> ¾</xs:element>
¾</xs:schema>
SOAP
¾
SOAP =
S
imple
O
bject
A
ccess
P
rotocol:
¾A SOAP envelope:
<?xml version="1.0" encoding="UTF-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <gs:doGoogleSearch xmlns:gs="urn:GoogleSearch"> . . . . <start>0</start> <maxResults>10</maxResults> <filter>true</filter> . . . . </soap:Body></soap:Envelope>>
September 22, 2004 Functional Testing of Web Services, QAI Conference 13
How to learn XML
¾
Do we need to know all intricacies of XML, DTD, and
XML schemas to start testing of web services?
¾
No!
¾
With basic XML principles, described above, you can
start development of XML test data files!
¾
I recommend an approach for XML learning:
¾Get sample XML files with corresponding DTD or XSD files for your new webservices project.
¾Go through major elements and try matching definitions from DTD/XSD and corresponding XML data.
¾Use web sites (e.g. http://www.w3schools.com) or XML books as additional sources of information.
Testing web services – Test Approach
¾
When testing webservices we use the same approach
as for any other testing project:
¾identify requirements,
¾Prepare high level test cases, ¾Document detailed test cases, etc.
¾
What would be an outcome of a test planning phase:
¾a set of test cases described in plain English language andbased on a requirements document, ¾a corresponding set of XML files.
September 22, 2004 Functional Testing of Web Services, QAI Conference 15
Sample test case
¾
Requirement:
¾“Location type” can be blank in a request ¾
Test case brief description:
¾“Location type” is blank in a request ¾
XML test data file:
. . . <locationInfo> <locationType></locationType> <locationVal>1600</locationVal> </locationInfo> . . . .
How to prepare XML test files
¾
How to prepare XML test files:
¾We have to get a sample XML file from a software developer and to enter our values of parameters.
¾This is not so terribly different from a standard GUI testing. ¾The only difference:
we have to enter our data into “fields” of XML document instead of fields of GUI.
¾
We have to follow a standard testing procedure,
familiar to every black box tester and to use standard
testing techniques when testing Web Services:
¾valid and invalid data, ¾ boundary values,
September 22, 2004 Functional Testing of Web Services, QAI Conference 17
Tools – to prepare XML test files
¾
What tools to use for XML files preparation:
¾Whatever you have,¾from Notepad
¾and Microsoft Word ¾to XMLSpy
¾
My favorite tools are:
¾ Notepad (or TextPad for bigger files) ¾ XMLSpy
Tools – to execute a test
¾
We have prepared a set of XML files that represent
our test cases.
¾
Next step is to process these files.
¾
To process XML files (XML requests) we need:
¾to POST an XML file (to send it to a specific URL and port), ¾to capture an XML response and to save it into a file. ¾We need a tool to do this.
September 22, 2004 Functional Testing of Web Services, QAI Conference 19
Tools – to execute a test
¾
Load Testing tools
¾Natural choice is any load testing tool, designed to handle HTTP traffic.
¾
XMLSpy.
¾XMLSpy can POST a SOAPdocument and capture a response.
¾
Custom tools/script:
¾A Perl script or a Java program can be developed to send a request and to capture a response.
¾
Empirix eTest:
¾Commercials tool to test SOAPbased web services. ¾
Many more options.
Analyzing results
¾
After we have XML response files we have to
compare them against expected results, described in
our test cases.
¾
Typically we have to verify values in some specified
fields.
¾
That task is not so different from a standard GUI
testing.
September 22, 2004 Functional Testing of Web Services, QAI Conference 21
Regression testing
¾
In case of a regression testing we can use a less time
consuming approach.
¾
We can automatically compare a new set of XML
responses to a previous set, using:
¾WinDiff.exe, ¾XMLSpy,
¾MS Windows commands: “Comp” or “fc”
Summary
¾
Testing of web services is not so different from a
standard GUI testing,
¾
New skills to learn are relatively simple (half a day or a
day to learn),
¾
Typical testing team already has most skills and
knowledge required for this type of testing,
¾
Testing web services can bring additional job and
visibility to an independent test team.
¾
Let’s leverage our skills and knowledge to a new field.
¾Let’s test web services.
September 22, 2004 Functional Testing of Web Services, QAI Conference 23
Contact Information
(416) 481-8685 [email protected] http://www.ivm-s.com¾
Yury Makedonov
References
¾
The above examples are from:
CGI projects
http://www.w3schools.com,
http://www.intertwingly.net/stories/2002/12/20/sbe.html
¾