Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

SoapUI introduced by an example of Web Service unit testing tool

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

Copyright notice: this article is originally created by the blogger and may not be reproduced without the permission of the blogger.

SoapUI is a relatively simple and practical open source Web Service testing tool, which provides two ways to use desktop applications and IDE plug-ins. The ability to quickly build projects and organize test cases is a major feature of the tool. Here is an example of how to use SoapUI for Web Service unit testing.

L build the project

The project (Project) in the SoapUI tool is made up of one or more Web Service. Here we preview the Web service with "Chinese TV programs:

Take http://www.webxml.com.cn/webservices/ChinaTVprogramWebService.asmx?wsdl" as an example, create a new WSDL project. Click File è New WSDL Project, and enter the project name "ChinaTV", initial WSDL "

Http://www.webxml.com.cn/webservices/ChinaTVprogramWebService.asmx?wsdl", as shown in figure 1:

Where WSDL can be a static file of URL or wsdl.

Running of a single service request

The SoapUI tool parses the WSDL file acquisition service interface and creates a request. Figure 2, 3: the service provides eight interfaces and two depending on the version of Soap.

Expand Soap request "Request 1" for interface "getTVstationDataSet":

Double-click to view the requested SOAP message: figure 4

What we see is the service request Soap message, in which "?" The question mark represents the input parameter, which is modified to request the input value "- 1" (in this example,-1 represents CCTV), and then click the icon button to run to get the request result: figure 5

We see the returned Soap message and the data in it.

L build test cases

Select the project "ChinaTV" and right-click, select New TestSuite, and build a test suite as shown in figure 6

Then, right-click in TestSuite, select New TestCase, create a new TestCase, and add the service request to the TestCase: figure 7

In this way, we have the first test case: figure 8

Because the service request input parameters have been set in the above process, here we double-click TestCase 1 and click to run it directly: figure 9

We see the "green bar", which means that the run is passed.

L increase checkpoints

As shown in the figure, open the service request getTVstationDataSet-Request 1, click, and add the checkpoint: as shown in figure 10

There are many types of checkpoints. Here we choose to include "Contains" and enter the check content "CCTV": figure 11

We run the service request getTVstationDataSet-Request 1: as shown in figure 12

You can see that the checkpoint is valid: Contains-VALID.

L organize test steps

Add getAreaDataSet (list of supported provinces, cities (regions) and classified TV), getTVstationDataSet (get the list of TV stations through provincial and municipal ID or classified TV ID), getTVchannelDataSet (obtain the channel list of the TV station through ID), getTVprogramDataSet (obtain the program list of the channel through channel ID) into the test step of TestCase 1, and then organize the test step to obtain the program list of "CCTV-1".

Test steps:

1. Obtain the classification of "CCTV" ID "- 1"

2. Obtain "CCTV" ID: "39" in the category of "CCTV"

3. Get the CCTV channel "CCTV-1" ID: "606"

4. Get the program list of "CCTV-1" channel as shown in figure 13.

We need to use "CCTV" ID "- 1" in the service request getAreaDataSet result as the input parameter of the service request getTVstationDataSet. Right-click getAreaDataSet-Request 1 and select Insert Step è Property Transfer, as shown in figure 14:

This Property Transfer is used for the interaction between two service requests, and we name it "AreaTransferStation" as shown in figure 15.

In Source, we select the Request of getAreaDataSet-Request 1 in the Response,Target of getTVstationDataSet-Request 1, and through the script select service request getAreaDataSet returns the value of (areaID [1]) in the node (AreaList [4]) in the result Soap message to the service request getTVstationDataSet as the input parameter (theAreaID [1]).

Among them: declare namespace diffgr=

"urn:schemas-microsoft-com:xml-diffgram-v1"; used to declare namespaces that correspond to namespaces in SOAP messages. As shown in figure 16

With the same operation steps, we organized the interaction between several other service requests and completed a complete test step. Finally, we ran TestCase and saw all the results: (green indicates that the run passed) as shown in figure 17.

Note: soapui official website http://www.soapui.org/

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 259

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report