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

Automatic Test of SOAP WebService Interface function

2025-02-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

Here we take the WebService API of qqCheckOnline as an example. The specific information of the API is as follows:

L API description: get Tencent QQ online status

L input parameter: qqCode,String type. Default QQ number: 8698053

L output parameter: qqCheckOnlineResult,String type

The meaning of the returned data is: y = online; N = offline; E = QQ number error; A = business user authentication failed; V = number of free users exceeds

L return format:

HTTP/1.1 200 OK

Content-Type: text/xml; charset=utf-8

Content-Length: length

String

After understanding the interface information, let's look at how to complete the design of the interface use case script, as shown in figure 5.1

Figure 5.1 Interface use case script design steps

5.2.1 Test method for single interface

After completing the preliminary setup according to the steps shown in figure 5.1, the script structure is shown in figure 5.2. This is the simplest script state, and there are many areas that need to be optimized and improved. Let's explain the common optimization methods respectively. Note: all subsequent operations are done in TestSuite.

Figure 5.2 script structure

According to the information of the interface, we may need to consider a variety of situations when designing test cases, including but not limited to the correct QQ number, the wrong QQ number, the online QQ number and the offline QQ number to verify the correctness of the interface under various conditions. Specific use cases need to be designed according to specific interface information. Here we will only take the correct and online QQ number as an example.

1. Parameterization

Open the qqCheckOnline interface under our TestSteps, as shown in figure 5.3, and you will find that the qqCode is written dead, obviously this is not what we want, we want it to be "alive".

Figure 5.3 qqCode

So how to make this parameter "live"? at this time, we should take advantage of the powerful function of DataSource. Parameterization can be achieved through a variety of external media in DataSource, such as:

L File: the form of a text file.

L Excel: it's best to use Excel in 2003 format.

L Grid: tabular form.

L JDBC:JDBC data source, which is obtained from the database.

L XML:XML format.

L Groovy:Groovy script form.

Here, we parameterize it in the form of a text file of type File, and the steps are as follows:

1) create a new text file on your local computer: qq.txt, and enter the contents shown in figure 5.4 in the file.

Figure 5.4 qq.txt

2) create a new DataSource, fill in the relevant data information, and note that its order should be in front of the interface. As shown in figure 4.5.

Figure 5.5 DataSource

Some of the fields are explained as follows:

L DataSource: select external storage media.

L File: select the path to the file.

L Properties: save the results obtained from the external storage media here.

L the rest of the fields can be kept by default.

3) switch to the qqCheckOnline interface to make the previously written qqCode "live". Just right-click on the qqCode parameter and select the Properties in the corresponding step under "Get Data". This is shown in figure 5.6.

Figure 5.6 Get Data

4) add DataSource Loop to complete the parameterized traversal. If you don't add this, the first QQ number will always be taken out, and the final script structure is shown in figure 5.7. Where DataSource Step is the selected source data and Target Step is the selected target step. You need to pay special attention to the order of DataSource, interface, and DataSource Loop here.

Figure 5.7 DataSource Loop

two。 Assertion (checkpoint)

Since we are automating the function of the interface, we must check the returned response data (output parameters). Only when we meet our expected results can we think that the interface has passed the test. To accomplish this, we need to use assertions, that is, checkpoints, which are often referred to as checkpoints, and the implementation steps are as follows:

1) double-click the interface in TestSteps and run it, add an assertion to what you want to check in the response area, and right-click Add Assertion- > for Cotent, as shown in figure 5.8.

Figure 5.8 selection assertion

2) in the pop-up "XPath Expression" dialog box, we can see that the content to be checked is the corresponding value Y of qqCheckOnlineResult, just click the "save" button, as shown in figure 5.9.

Figure 5.9 confirm assertion

3) the final result is shown in figure 5.10, where Assertions represents assertions.

Figure 5.10 assertion effect diagram

There are many forms of assertions in SoapUI, which are very powerful and can be viewed by clicking "Add Assertion", as shown in Chapter 5 of the book.

3. Operation and report

After completing the above steps, you can run the use case script, double-click the TestCase, and click the "small green arrow" in the pop-up "qqCheckOnline TestCase" dialog box, as shown in figure 5.13. If you want to see the test report generated by SoapUI, click the icon in the shape of "document". The test report style is shown in figure 5.14.

All single-interface tests like this are probably this process, and we need to make certain adjustments according to the specific interface information, but the overall ideas and methods are more or less the same. I also hope that everyone can understand the truth of "one-size-fits-all" in the process of continuous learning, so that even if you have only 2 years of work experience, you may exceed friends with 5 years of work experience.

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: 0

*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