Introduction to Soapui

1. Tool introduction

Soapui provides a tool to check, call, and implement web service function/load testing tool through soap/http.

Two, Webservice interface introduction

Web service is divided into two major types of architecture. One is based on the soap protocol (the interface at the end of wsdl), and the other is based on the restful idea. Due to the restful api interface (the interface of the http address, but the request message is xml/json) Design thinking, the latter has more commercial applications abroad. For example, the api interface provided by Google Twitter.

Third, the use of tools

1. Soap style webservice interface call
Directly click the SOAP button to pop up the new soap project dialog box. Browse the wsdl file generated by the webservice interface server in the Initial WSDL. Click ok. to
Insert picture description hereInsert picture description here
enter the interface for setting input parameters. It is the automatically generated parameter input message, just input the parameter, click the green triangle to run, and the interface call is completed. The return parameter XML is displayed on the right.
Insert picture description here
2. Call the webservice interface in rest style.
Click the rest button directly on the interface, and the new rest project dialog box will pop up. Enter the URI here is the interface address provided by the server. Click ok
Insert picture description here
interface address will be automatically split into three parts, among which parameters is empty. By selecting the requested method-Method, the type of the parameter has been selected Media Type to set the input parameter type and the content of the input parameter. As shown in the picture. All set up, and input the parameter information, click the green triangle to call the interface. You can see the return value on the right. There are also several return values: xml, json, Html, etc.
Insert picture description here
Fourth, the difference between SOAP protocol and Rest

1. The soap style depends on the wsdl interface service description file. Through this wsdl file, all methods in the exposed interface can be displayed, and then select the method you want to call in the list, and enter the parameters. Wsdl can only be located on the interface/class, not the specific method. The rest-style URI method directly locates the method.

2. The soap style does not set whether the request method is get, post, or delete, put. Because soap defaults to post request. The rest can set the request type by itself.

3. The bottom transmission of soap style parameters is fixed. The input and output parameters are fixed in xml format, and there is no other parameter format such as json. The data type of the rest-style input and output parameters can be in common formats such as xml, json, etc. The input parameters do not have anything generated by the underlying layer, and all are done by yourself. The xml or json format must strictly conform to the selected data type.

5. Soapui implements MockService
1. Right-click the project and select Create MockService
Insert picture description here
2. Add new mock action on the created MockService and edit the mock action. Key points: Note that the Method and resource path in the mock action must be consistent with the Method and resource path in the service request, so that it can be used as a barrier for the service request.
Insert picture description here
Insert picture description here
3. Right-click the newly created mock action, create a new Mock Response, and define the response content under each response status codeInsert picture description here

Such as customized xml format response content:
Insert picture description here

For example, the customized json format response content:
Insert picture description here
4. Double-click the first step to add MockService and click the start button (green triangle symbol) in the following figure in the pop-up box to start the mock service. After the startup is complete, we can see which port the service is running on, and the request path (the running port can also be changed, as shown in the setting button in the figure below).
Insert picture description here
Now a mock server of the http protocol has been set up.

So how to use this MockService

After ensuring that the MockService is started, open the service request and change the endpoint to a newly created service locally. The Method and Resource are the same as those in the MockService. Click the green triangle on the upper left to send the service request. You can see that the response content on the right is the customized response. content.
Insert picture description here

Remarks : You can also right-click on the service request and select Generate REST Mock Service, you can directly generate the Mock Service of the service without adding a mock action
Insert picture description here

Guess you like

Origin blog.csdn.net/baidu_24752135/article/details/112394255