Automatic testing method, device and computer equipment for TCP interface

Through automated testing methods, we receive test requests for the TCP interface, determine identification information, obtain message types and message data, and create message messages that meet the TCP interface message structure, which solves the problem that traditional testing tools cannot automatically test the TCP interface, and improves the problem that traditional testing tools cannot automatically test the TCP interface. Test efficiency and reduce costs.

CN113626320BActive Publication Date: 2025-01-07NANJING SUNING SOFTWARE TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202110858376.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-07-28
Publication Date
2025-01-07
Estimated Expiration
2041-07-28

AI Technical Summary

Technical Problem

Traditional testing tools cannot automate the testing of customized TCP interfaces, resulting in testers having to write complex code, increasing learning and time costs.

Method used

Provide an automated test method for TCP interface, by receiving test requests, determining identification information, obtaining message types and message data, creating message messages that meet the TCP interface message structure, and identifying the connection method to send service call requests, realizing Automatic testing of TCP interface.

Benefits of technology

It reduces the requirements for the programming ability of testers, reduces the testing workload, improves the testing efficiency, and realizes full-scene interface testing of the TCP interface.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113626320B_ABST
    Figure CN113626320B_ABST
Patent Text Reader

Abstract

The present application relates to an automated testing method, device, computer equipment and storage medium for a TCP interface, the method comprising: receiving a test request for a TCP interface, determining identification information of the TCP interface according to the test request; obtaining a message type and first message data of a first message message to be sent according to the identification information; obtaining message attribute information of a second message message according to the message type, obtaining target message data corresponding to the message attribute information from the first message data; creating a second message message according to the message attribute information and the target message data, the second message message being a message message that satisfies the message structure of the TCP interface; identifying a connection mode between the TCP interface and a server, and sending a service call request to the server according to the connection mode and the second message message, so as to perform an interface test on the TCP interface. The above method can perform automated testing on the TCP interface.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of automated testing technology, and in particular to an automated testing method, device, computer equipment and storage medium for a TCP interface. Background Art

[0002] Automated testing is a very important part of software engineering and a key step to ensure the successful launch of a system. Software products have fast iterations, many functions, and few testers, which cannot meet the full-scenario testing of each version. Considering the existing manpower and automation technology, automated testing of interfaces can be implemented for regression testing, which can not only ensure full-scenario interface testing of the version, but also reduce testing workload and improve testing efficiency.

[0003] However, in order to meet the needs of instant messaging services, some software products need to develop protocol interfaces, such as TCP interfaces. The connection method and message structure of TCP interfaces are customized, and traditional testing tools cannot perform automated testing on such interfaces. Usually, complex code programs need to be written to complete the testing tasks of such interfaces, which requires high programming skills of testers and results in high learning costs and time costs. Summary of the invention

[0004] Based on this, it is necessary to provide a method, device, computer equipment and storage medium for automatically testing a TCP interface in order to solve the above technical problems.

[0005] An automated testing method for a TCP interface comprises: receiving a test request for a TCP interface, determining identification information of the TCP interface according to the test request; obtaining a message type and first message data of a first message packet to be sent according to the identification information; obtaining message attribute information of a second message packet according to the message type, and obtaining target message data corresponding to the message attribute information from the first message data; creating a second message packet according to the message attribute information and the target message data, wherein the second message packet is a message packet that satisfies the message structure of the TCP interface; identifying a connection mode between the TCP interface and a server, and sending a service call request to the server according to the connection mode and the second message packet, so as to perform an interface test on the TCP interface.

[0006] In one of the embodiments, the TCP interface is a TCP protocol interface based on protobuf, the first message packet is a message packet in Json format, and the second message packet is a message packet in protobuf format.

[0007] In one embodiment, creating a second message message based on message attribute information and target message data includes: identifying each attribute field in the message attribute information; assigning the target message data to each attribute field to obtain second message data; and creating a second message message based on the second message data.

[0008] In one of the embodiments, an automated testing method for a TCP interface also includes: creating a first coroutine function, the first coroutine function is used to establish a long connection with a server; creating a first connection mode according to the first coroutine function; creating a second coroutine function, the second coroutine function is used to establish a message sending connection with the server; creating a second connection mode according to the second coroutine function; the connection mode between the TCP interface and the server includes a first connection mode and a second connection mode; sending a service call request to the server according to the connection mode and the second message message, including: sending a service call request to the server according to the first connection mode, the second connection mode and the second message message.

[0009] In one of the embodiments, sending a service call request to a server according to a first connection mode, a second connection mode and a second message message includes: sending a long connection establishment request to the server according to the first connection mode and the second message message; after establishing a long connection with the server, sending a service call request to the server according to the second connection mode and the second message message.

[0010] In one of the embodiments, a long connection establishment request is sent to a server according to a first connection mode and a second message message, including: obtaining a connection message from the second message message, the connection message being used to send a long connection with the server; sending a long connection establishment request encapsulated with a connection message to the server through the first connection mode; sending a service call request to the server according to the second connection mode and the second message message, including: obtaining a message message from the second message message, the message message being used to instruct the server to return a service message; and sending a service call request encapsulated with a message message to the server through the second connection mode.

[0011] In one of the embodiments, a method for automated testing of a TCP interface further includes: receiving a service message fed back by a server; and converting the service message into data in a corresponding format and storing the data.

[0012] An automated testing device for a TCP interface comprises: a determination module for receiving a test request for a TCP interface and determining identification information of the TCP interface according to the test request; a first acquisition module for acquiring a message type and first message data of a first message packet to be sent according to the identification information; a second acquisition module for acquiring message attribute information of a second message packet according to the message type and acquiring target message data corresponding to the message attribute information from the first message data; a creation module for creating a second message packet according to the message attribute information and the target message data, wherein the second message packet is a message packet that satisfies the message structure of the TCP interface; and a sending module for identifying a connection mode between the TCP interface and a server, and sending a service call request to the server according to the connection mode and the second message packet, so as to perform an interface test on the TCP interface.

[0013] A computer device includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of any of the above-mentioned embodiments are implemented.

[0014] A computer-readable storage medium stores a computer program, which implements the steps of any of the above-mentioned method embodiments when the computer program is executed by a processor.

[0015] The above-mentioned automated testing method, device, computer equipment and storage medium of the TCP interface receive a test request of the TCP interface, determine the identification information of the TCP interface according to the test request; obtain the message type and the first message data of the first message message to be sent according to the identification information; obtain the message attribute information of the second message message according to the message type, and obtain the target message data corresponding to the message attribute information from the first message data; create a second message message according to the message attribute information and the target message data, and the second message message is a message message that meets the message structure of the TCP interface; identify the connection mode between the TCP interface and the server, and send a service call request to the server according to the connection mode and the second message message to perform an interface test on the TCP interface. Therefore, the message message required for the test can be converted into a message message that meets the message structure of the TCP interface by means of message conversion. At the same time, the connection mode between the TCP interface and the server is identified, and a service call request is sent to the server based on the connection mode and the message message that meets the message structure of the TCP interface to implement an interface test on the TCP interface. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] Figure 1 An application environment diagram of an automated testing method for a TCP interface in one embodiment;

[0017] Figure 2 A schematic diagram of a flow chart of an automated testing method for a TCP interface in an embodiment;

[0018] Figure 3 A system architecture diagram of an automated testing system for a TCP interface in one embodiment;

[0019] Figure 4 A schematic diagram of a flow chart of an automatic testing method for a TCP interface implemented by an automatic testing system for a TCP interface in an embodiment;

[0020] Figure 5 An interface diagram of an automated testing system for a TCP interface in one embodiment;

[0021] Figure 6 A structural block diagram of an automatic testing device for a TCP interface in one embodiment;

[0022] Figure 7 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION

[0023] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0024] The present application provides an automated testing method for a TCP interface, which is applied to Figure 1In the application environment shown. The automated testing platform 10 is used to implement an automated testing method for a TCP interface of the present application. A database 104 and a server cluster 102 are provided in the automated testing platform 10. The database 104 is used to store the interface parameters of the TCP interface. The server cluster 102 is used to perform automated testing of the TCP interface. The user configures the interface parameters of the TCP interface through the terminal 30. After the automated testing platform 10 collects the interface parameters of the TCP interface from the terminal 30, the interface parameters are stored in the database 104. Among them, the interface parameters include case parameters of the test case, the message type of the first message to be sent, and the first message data, etc. When the automated testing platform 10 receives a test request for a TCP interface, it determines the identification information of the TCP interface according to the test request, obtains the message type and first message data of the first message to be sent by the TCP interface from the database 104 according to the identification information, obtains the message attribute information of the second message according to the message type, obtains the target message data corresponding to the message attribute information from the first message data, creates a second message according to the message attribute information and the target message data, and the second message satisfies the message structure of the TCP interface. Then, it identifies the connection mode between the TCP interface and the server, and sends a service call request to the server according to the connection mode and the second message to perform an interface test on the TCP interface.

[0025] In one embodiment, Figure 2 As shown, a method for automated testing of TCP interfaces is provided. Figure 1 The automated test platform 10 in the example is used as an example to illustrate, and includes the following steps:

[0026] S202, receiving a test request for a TCP interface, and determining identification information of the TCP interface according to the test request.

[0027] In this embodiment, the automated testing platform configures identification information for the TCP interface, and the identification information is used to uniquely identify the TCP interface. In addition, the data information related to the interface test of the TCP interface in the automated testing platform is bound to the identification information, and the automated testing platform can obtain the data information related to the TCP interface through the identification information. The data information related to the interface test of the TCP interface includes the message type of the first message message to be sent and the first message data. The TCP interface can be a TCP protocol interface based on protobuf. TCP: Transmission Control Protocol, is a connection-oriented, reliable, byte stream-based transport layer communication protocol.

[0028] When the automated testing platform receives a test request for a TCP interface, it parses the identification information of the TCP interface from the test request. The identification information may be the interface name of the TCP interface or the ID of the TCP interface. ID: Identity document, ID card identification number.

[0029] S204: Acquire the message type and first message data of the first message message to be sent according to the identification information.

[0030] In this embodiment, a first message is stored in the database. The automated test platform can obtain the first message through the identification information and identify the message type of the first message. Specifically, the user configures the message type and the first message data of the first message of the TCP interface through the terminal 30. For example, the user fills in the test case message body and message type of the TCP interface on the web interface of the terminal 30. Message refers to the message, which can be the first message here. For example:

[0031] Messages

[0032] {

[0033] "id":24;

[0034] "name":"zhangsan";

[0035] "email":"zhangsan@gmail.com";

[0036] }

[0037] S206: Acquire message attribute information of the second message message according to the message type, and acquire target message data corresponding to the message attribute information from the first message data.

[0038] In this embodiment, the second message message is a message message that is subsequently created and used to be sent to the server to request a service call. The message attribute information includes attribute information of each message data in the second message message. For example, the message attribute information includes a name, a data type, a data index, etc. Different message types have different corresponding message attribute information. As in the above example, the message type is Person, and its corresponding message attribute information includes a name and an email. When the message type is other types, its corresponding message attribute information is different from that of Person.

[0039] The automated test platform determines the message attribute information of the second message message according to the message type of the first message message. Specifically, it can be: the automated test platform reads a configuration file matching the message type from the configuration platform according to the message type, and reads the message attribute information of the second message message from the configuration file. Among them, the configuration platform pre-configures configuration files with different message types, and the configuration files record the corresponding message attribute information. Further, the target message data corresponding to the message attribute information is obtained from the first message data.

[0040] S208: Create a second message packet according to the message attribute information and the target message data, where the second message packet is a message packet that satisfies the message structure of the TCP interface.

[0041] In this embodiment, the automated test platform creates a second message according to the message attribute information and the target message data. Specifically, each message data in the target message data is associated with the corresponding message attribute information to generate a second message. The message structure of the second message meets the requirements of the message structure of the TCP interface. For example, the first message in the above example is converted into the second message as shown below:

[0042] The following is a message named Person:

[0043]

[0044] At this time, the message type is Person. The content in the message Person message body is the second message message. The message structure of the converted second message message meets the message structure requirements of the TCP interface.

[0045] S210, identifying the connection mode between the TCP interface and the server, and sending a service call request to the server according to the connection mode and the second message packet to perform an interface test on the TCP interface.

[0046] In this embodiment, the automated testing platform customizes the connection mode between the TCP interface and the server according to the interface protocol of the TCP interface. When executing the connection operation between the TCP interface and the server, the automated testing platform identifies the corresponding connection mode. Then, a service call request is sent to the server according to the connection mode and the second message packet. Among them, the connection mode is used to establish a communication connection between the TCP interface and the server, and the second message packet is used to establish data interaction between the TCP interface and the server. When the server receives the service call request, it obtains the corresponding service data based on the service call request and feeds back the corresponding service data. Therefore, the interface test of the TCP interface is realized.

[0047] The above-mentioned automated testing method for the TCP interface receives a test request for the TCP interface, determines the identification information of the TCP interface according to the test request; obtains the message type and the first message data of the first message message to be sent according to the identification information; obtains the message attribute information of the second message message according to the message type, and obtains the target message data corresponding to the message attribute information from the first message data; creates a second message message according to the message attribute information and the target message data, and the second message message is a message message that meets the message structure of the TCP interface; identifies the connection mode between the TCP interface and the server, and sends a service call request to the server according to the connection mode and the second message message to perform an interface test on the TCP interface. Therefore, the message message required for the test can be converted into a message message that meets the message structure of the TCP interface by means of message conversion. At the same time, the connection mode between the TCP interface and the server is identified, and a service call request is sent to the server based on the connection mode and the message message that meets the message structure of the TCP interface to implement an interface test on the TCP interface.

[0048] In one embodiment, the TCP interface is a TCP protocol interface based on protobuf, the first message packet is a message packet in Json format, and the second message packet is a message packet in protobuf format.

[0049] In this embodiment, the TCP interface is a TCP protocol interface based on protobuf. In order to support the interface test of the protocol interface, the automated test platform collects the first message message, which is in Json format and stored in the database. When the interface test of the TCP interface is started, the first message message in Json format is obtained from the database according to the identification information in the test request, such as the ID number. In the interface test of the TCP interface, the message body needs to be sent in the form of protobuf. In order to solve the above problem, the automated test platform designs corresponding components to realize the conversion between the Json format object and the protobuf format object. The automated test platform parses the Json field of the first message message, and obtains the message attribute information of the second message message, assigns corresponding values ​​to each field in the second message message in turn according to the message attribute information, and transforms and creates the second message message containing the protobuf message object. Therefore, the automated interface test of the TCP protocol interface based on protobuf is realized.

[0050] Specifically, in order to support the interface test of the TCP protocol interface based on protobuf, the system first needs to collect the .proto files used by the system to be tested to define the message type of the second message message and classify and manage them according to appcode, which refers to the identification code of the service caller. Introduce the dependency of proto in the project code, execute the compilation command to generate the corresponding _pb2.py file and introduce it into the project. Among them, the .proto file of the message type of the second message message contains the message attribute information of the second message message, and the _pb2.py file generated after the compilation contains the message attribute information of the second message message. When the message type of the first message message and the message type of the second message message are the same, the message attribute information of the second message message can be read from the _pb2.py file. That is, the message attribute information of the second message message can be obtained based on the message type of the first message message.

[0051] In one embodiment, the above-mentioned creation of the second message message based on the message attribute information and the target message data includes: identifying each attribute field in the message attribute information; assigning the target message data to each attribute field to obtain the second message data; and creating the second message message based on the second message data.

[0052] In this embodiment, the message attribute information of the second message message includes multiple attribute fields, such as name, type, index, etc. Each message data in the target message data is assigned to the corresponding attribute field to obtain the second message data, and then the second message message is created according to the second message data.

[0053] Specifically, based on the above embodiment, when the back-end server receives the interface test request of the TCP interface, it will choose to load the corresponding _pb2.py file according to the task appcode, and read the task status and messages in the database according to the task ID. Here, the messages are messages in Json format, and in the interface test of the TCP interface, the message body needs to be sent in protobuf form. In order to solve the above problems, the system designs corresponding components to realize the conversion between Json objects and protobuf objects. The system parses the Json field of the messages message and obtains the message attributes, such as name, type, index, etc., by reading the _pb2.py file. Assign corresponding values ​​to each member field in turn, parse the data and convert it into a protobuf message object.

[0054] For example, the first message in Json format is:

[0055] {

[0056] "id":24,

[0057] "name":"zhangsan",

[0058] "email":"zhangsan@gmail.com"

[0059] }

[0060] Convert it to get the second message named Person:

[0061]

[0062] In one embodiment, before the above step of identifying the connection mode between the TCP interface and the server, it also includes: creating a first coroutine function, the first coroutine function is used to establish a long connection with the server; creating a first connection mode according to the first coroutine function; creating a second coroutine function, the second coroutine function is used to establish a message sending connection with the server; creating a second connection mode according to the second coroutine function; the connection mode between the TCP interface and the server includes a first connection mode and a second connection mode; the above step of sending a service call request to the server according to the first connection mode, the second connection mode and the second message includes: sending a service call request to the server according to the first connection mode, the second connection mode and the second message.

[0063] In this embodiment, the coroutine function is used to process the establishment of a long connection for the interface test of the TCP interface and the establishment of a message sending connection. For example, a message sending connection is established with the server through send_msg, and the second coroutine function is _send_msg. For example, send_msg is a specific second message, and the second coroutine function _send_msg is as follows:

[0064]

[0065]

[0066] The main function of the second coroutine function is to send send_msg to the server and receive the return value from the server.

[0067] Similarly, the first coroutine function uses the above method to establish a long connection with the server.

[0068] In one embodiment, the above-mentioned sending a service call request to the server according to the first connection mode, the second connection mode and the second message message includes: sending a long connection establishment request to the server according to the first connection mode and the second message message; after establishing a long connection with the server, sending a service call request to the server according to the second connection mode and the second message message.

[0069] In this embodiment, the Asyncio programming model is used to perform asynchronous processing on the interface test of the TCP interface, and two coroutine functions are written to process the sending of bind_msg and send_msg. The first coroutine function is used to process the sending of bind_msg, and the second coroutine function is used to process the sending of send_msg. The second message packet contains bind_msg and send_msg. Among them, bind_msg is a message that needs to be sent to the server when the client establishes a long socket connection with the server, and is mainly used to establish a long connection. Send_msg is the message body sent by the client to the server after the long connection is established. That is, the client first sends a bind_msg to establish a long connection between the client and the server, and then sends send_msg to call the real TCP interface, and then sends a service call request to the server.

[0070] In one embodiment, the sending of a long connection establishment request to the server according to the first connection mode and the second message message includes: obtaining a connection message from the second message message, the connection message is used to send a long connection with the server; and sending a long connection establishment request encapsulated with the connection message to the server through the first connection mode. The sending of a service call request to the server according to the second connection mode and the second message message includes: obtaining a message message from the second message message, the message message is used to instruct the server to return a service message; and sending a service call request encapsulated with the message message to the server through the second connection mode.

[0071] In this embodiment, the second message message includes a connection message and a message message. The connection message is used to send a long connection with the server, and the message message is used to instruct the server to return a service message. The connection message includes the data required when the TCP interface establishes a connection with the server, and the message message includes data related to the specific calling service.

[0072] For example, after the automated test task of the automated test platform is started, the automated test platform first creates an AsyncioEventLoop event loop object, and then creates a task Task to encapsulate the first coroutine function. The task Tsak is mainly used to establish a long connection with the server's ip and port, and serialize the protobuf data read from the connection message into a binary stream and send it to the server, and obtain the client object of the connected client. After establishing a long connection with the server, create another task Task for concurrent scheduling. The task Task is mainly used to call the client.send function, serialize the message send_msg message, call the remote TCP server interface, and decode and deserialize the return value to obtain the final result.

[0073] In one embodiment, after the step of sending a service call request to the server according to the connection mode and the second message, the step further includes: receiving a service message fed back by the server; converting the service message into data of a corresponding format and storing it.

[0074] In this embodiment, the service message fed back by the server can be a message indicating the failure of the service call, or it can be a message related to the service call request fed back by the server after the service call is successful. The storage format of the service message is pre-set in the automated testing platform. When the service message is received, it is converted into data in a corresponding format and stored. Therefore, it is convenient for users to view the interface test data of the TCP interface, and then determine the test results of the TCP interface.

[0075] The present application also provides an automated testing system for a TCP interface, wherein the automated testing system for a TCP interface is used to implement an automated testing method for a TCP interface.

[0076] like Figure 3 As shown, the automated testing system for a TCP interface consists of several functional modules, including: a user authority management module, a test environment management module, an interface management module, a scenario management module, a script management module, a test task scheduling module, a test task execution module, a log generation module, and a statistical analysis module.

[0077] The user rights management module is responsible for controlling the access and operation rights of platform users, including login, logout, authentication, authorization and other operations. The system will determine the behavior of the user based on the role and group information of the logged-in user, so that user information of different groups is isolated and will not interfere with each other.

[0078] The test environment management module is responsible for the management of the test interface's IP / port, domain name and other related information, and provides operations such as addition, deletion, modification and query.

[0079] The interface management module is responsible for escaping the user's preset interface parameters to generate HTTP, TCP, and RSF test cases, including case name, request URL, service contract, implementation code, protocol type, method name, parameter list, verification method, etc., and parses this data and stores it in the background database.

[0080] The scenario management module is responsible for designing test scenarios. Users can freely combine the created test cases according to their needs and build a test process.

[0081] The script management module is responsible for the creation and maintenance of automated testing tasks, as well as allocating the operating environment and creating scheduled tasks.

[0082] The test task scheduling module is mainly responsible for test task allocation and scheduling, including the mutual scheduling between Java services and flask.

[0083] The test task execution module is mainly responsible for the execution of test tasks, response verification and returning execution results.

[0084] The log generation module is mainly responsible for the generation and display of logs, and provides an interface for users to download.

[0085] The statistical analysis module mainly uses Echarts charts to intuitively display the execution pass rate and failure rate of automated cases in the system dimension and scenario dimension within the cycle.

[0086] The case toolset module is responsible for maintaining the commonly used testing tools developed by testers and providing a download interface.

[0087] The automatic test system of a TCP interface executes various operation processes of an automatic test method of a TCP interface as follows: Figure 4 The result interface is shown as Figure 5 shown.

[0088] Therefore, an automated testing system for TCP interfaces is adapted to automated testing of TCP interfaces, supports self-developed TCP protocol interface testing, and realizes the separation of test data and programs, so that testers can complete full-scenario testing without having to change tools multiple times, thereby improving work efficiency and reducing time costs.

[0089] It should be understood that, although the steps in the flowchart are shown in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and these steps can be executed in other orders. Moreover, at least a portion of the steps in the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a portion of the sub-steps or stages of other steps.

[0090] The present application also provides an automated testing device for a TCP interface, such as Figure 6As shown, the device includes a determination module 602, a first acquisition module 604, a second acquisition module 606, a creation module 608 and a sending module 610. The determination module 602 is used to receive a test request of a TCP interface and determine the identification information of the TCP interface according to the test request; the first acquisition module 604 is used to obtain the message type and the first message data of the first message message to be sent according to the identification information; the second acquisition module 606 is used to obtain the message attribute information of the second message message according to the message type, and obtain the target message data corresponding to the message attribute information from the first message data; the creation module 608 is used to create a second message message according to the message attribute information and the target message data, and the second message message is a message message that meets the message structure of the TCP interface; the sending module 610 is used to identify the connection mode between the TCP interface and the server, and send a service call request to the server according to the connection mode and the second message message to perform an interface test on the TCP interface.

[0091] In one of the embodiments, the TCP interface is a TCP protocol interface based on protobuf, the first message packet is a message packet in Json format, and the second message packet is a message packet in protobuf format.

[0092] In one embodiment, creating a second message message based on message attribute information and target message data includes: identifying each attribute field in the message attribute information; assigning the target message data to each attribute field to obtain second message data; and creating a second message message based on the second message data.

[0093] In one embodiment, an automated testing device for a TCP interface also includes an establishment module, which is used to create a first coroutine function, the first coroutine function is used to establish a long connection with a server; create a first connection mode according to the first coroutine function; create a second coroutine function, the second coroutine function is used to establish a message sending connection with the server; create a second connection mode according to the second coroutine function; the connection mode between the TCP interface and the server includes a first connection mode and a second connection mode; the above-mentioned sending a service call request to the server according to the connection mode and the second message message includes: sending a service call request to the server according to the first connection mode, the second connection mode and the second message message.

[0094] In one of the embodiments, sending a service call request to a server according to a first connection mode, a second connection mode and a second message message includes: sending a long connection establishment request to the server according to the first connection mode and the second message message; after establishing a long connection with the server, sending a service call request to the server according to the second connection mode and the second message message.

[0095] In one of the embodiments, a long connection establishment request is sent to a server according to a first connection mode and a second message message, including: obtaining a connection message from the second message message, the connection message being used to send a long connection with the server; sending a long connection establishment request encapsulated with a connection message to the server through the first connection mode; sending a service call request to the server according to the second connection mode and the second message message, including: obtaining a message message from the second message message, the message message being used to instruct the server to return a service message; and sending a service call request encapsulated with a message message to the server through the second connection mode.

[0096] In one of the embodiments, an automated testing device for a TCP interface further includes a storage module, which is used to receive a service message fed back by a server; and to convert the service message into data in a corresponding format and then store the data.

[0097] The specific definition of the automated testing device for the TCP interface can be found in the definition of the automated testing method for the TCP interface above, which will not be repeated here. Each module in the automated testing device for the TCP interface can be implemented in whole or in part by software, hardware, and a combination thereof. Each of the modules can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each of the modules above.

[0098] In one embodiment, a computer device is provided. The computer device may be a server in a server cluster in an automated testing platform. The internal structure diagram thereof may be as follows: Figure 7 As shown. The computer device includes a processor, a memory, a network interface and a database connected via a system bus. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to connect to the platform of an external service provider to exchange data with the service provider. When the computer program is executed by the processor, an automated testing method for a TCP interface is implemented.

[0099] Those skilled in the art will understand that Figure 7 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0100] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the following steps when executing the computer program: receiving a test request for a TCP interface, and determining identification information of the TCP interface according to the test request; obtaining a message type and first message data of a first message packet to be sent according to the identification information; obtaining message attribute information of a second message packet according to the message type, and obtaining target message data corresponding to the message attribute information from the first message data; creating a second message packet according to the message attribute information and the target message data, wherein the second message packet is a message packet that satisfies the message structure of the TCP interface; identifying a connection mode between the TCP interface and a server, and sending a service call request to the server according to the connection mode and the second message packet, so as to perform an interface test on the TCP interface.

[0101] In one of the embodiments, the TCP interface is a TCP protocol interface based on protobuf, the first message packet is a message packet in Json format, and the second message packet is a message packet in protobuf format.

[0102] In one of the embodiments, when the processor executes a computer program to implement the above-mentioned step of creating a second message message based on the message attribute information and the target message data, the following steps are specifically implemented: identifying each attribute field in the message attribute information; assigning the target message data to each attribute field to obtain the second message data; and creating a second message message based on the second message data.

[0103] In one of the embodiments, when the processor executes the computer program, the following steps are also implemented: creating a first coroutine function, the first coroutine function is used to establish a long connection with the server; creating a first connection mode according to the first coroutine function; creating a second coroutine function, the second coroutine function is used to establish a message sending connection with the server; creating a second connection mode according to the second coroutine function; the connection mode between the TCP interface and the server includes a first connection mode and a second connection mode; when the processor executes the computer program to implement the above-mentioned step of sending a service call request to the server according to the connection mode and the second message message, the following steps are specifically implemented: sending a service call request to the server according to the first connection mode, the second connection mode and the second message message.

[0104] In one of the embodiments, when the processor executes a computer program to implement the above-mentioned step of sending a service call request to the server according to the first connection mode, the second connection mode and the second message message, the following steps are specifically implemented: sending a long connection establishment request to the server according to the first connection mode and the second message message; after establishing a long connection with the server, sending a service call request to the server according to the second connection mode and the second message message.

[0105] In one of the embodiments, when the processor executes a computer program to implement the above-mentioned step of sending a long connection establishment request to the server according to the first connection mode and the second message message, the following steps are specifically implemented: obtaining a connection message from the second message message, and the connection message is used to send a long connection with the server; sending a long connection establishment request encapsulated with the connection message to the server through the first connection mode; when the processor executes a computer program to implement the above-mentioned step of sending a service call request to the server according to the second connection mode and the second message message, the following steps are specifically implemented: obtaining a message message from the second message message, and the message message is used to instruct the server to return a service message; sending a service call request encapsulated with a message message to the server through the second connection mode.

[0106] In one of the embodiments, when the processor executes the computer program, the processor further implements the following steps: receiving a service message fed back by the service end; converting the service message into data in a corresponding format and storing the data.

[0107] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented: receiving a test request for a TCP interface, and determining identification information of the TCP interface according to the test request; obtaining a message type and first message data of a first message packet to be sent according to the identification information; obtaining message attribute information of a second message packet according to the message type, and obtaining target message data corresponding to the message attribute information from the first message data; creating a second message packet according to the message attribute information and the target message data, the second message packet being a message packet that satisfies the message structure of the TCP interface; identifying a connection method between the TCP interface and a server, and sending a service call request to the server according to the connection method and the second message packet, so as to perform an interface test on the TCP interface.

[0108] In one of the embodiments, the TCP interface is a TCP protocol interface based on protobuf, the first message packet is a message packet in Json format, and the second message packet is a message packet in protobuf format.

[0109] In one of the embodiments, when the computer program is executed by the processor to implement the above-mentioned step of creating a second message message based on the message attribute information and the target message data, the following steps are specifically implemented: identifying each attribute field in the message attribute information; assigning the target message data to each attribute field to obtain the second message data; and creating a second message message based on the second message data.

[0110] In one of the embodiments, when the computer program is executed by the processor, the following steps are also implemented: creating a first coroutine function, the first coroutine function is used to establish a long connection with the server; creating a first connection mode according to the first coroutine function; creating a second coroutine function, the second coroutine function is used to establish a message sending connection with the server; creating a second connection mode according to the second coroutine function; the connection mode between the TCP interface and the server includes a first connection mode and a second connection mode; when the processor executes the computer program to implement the above-mentioned step of sending a service call request to the server according to the connection mode and the second message message, the following steps are specifically implemented: sending a service call request to the server according to the first connection mode, the second connection mode and the second message message.

[0111] In one of the embodiments, when the computer program is executed by the processor to implement the above-mentioned step of sending a service call request to the server according to the first connection mode, the second connection mode and the second message message, the following steps are specifically implemented: sending a long connection establishment request to the server according to the first connection mode and the second message message; after establishing a long connection with the server, sending a service call request to the server according to the second connection mode and the second message message.

[0112] In one of the embodiments, when the computer program is executed by the processor to implement the above-mentioned step of sending a long connection establishment request to the server according to the first connection mode and the second message message, the following steps are specifically implemented: obtaining a connection message from the second message message, and the connection message is used to send a long connection with the server; sending a long connection establishment request encapsulated with the connection message to the server through the first connection mode; when the computer program is executed by the processor to implement the above-mentioned step of sending a service call request to the server according to the second connection mode and the second message message, the following steps are specifically implemented: obtaining a message message from the second message message, and the message message is used to instruct the server to return a service message; sending a service call request encapsulated with a message message to the server through the second connection mode.

[0113] In one of the embodiments, when the computer program is executed by the processor, the following steps are also implemented: receiving a service message fed back by the service end; converting the service message into data in a corresponding format and then storing it.

[0114] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).

[0115] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0116] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the attached claims.

Claims

1. A method for automated testing of a TCP interface, the method comprising: Receive a test request for a TCP interface, and determine identification information of the TCP interface according to the test request; Acquire a message type and first message data of a first message message to be sent according to the identification information; Acquire message attribute information of the second message message according to the message type, and acquire target message data corresponding to the message attribute information from the first message data; Creating the second message message according to the message attribute information and the target message data, wherein the second message message is a message message satisfying the message structure of the TCP interface; Creating a first coroutine function, where the first coroutine function is used to establish a persistent connection with the server; Create a first connection mode according to the first coroutine function; Creating a second coroutine function, where the second coroutine function is used to establish a message sending connection with the server; Create a second connection mode according to the second coroutine function; A service call request is sent to the server according to the first connection mode, the second connection mode and the second message packet to perform an interface test on the TCP interface.

2. The method according to claim 1, characterized in that The TCP interface is a protobuf-based TCP protocol interface, the first message packet is a message packet in Json format, and the second message packet is a message packet in protobuf format.

3. The method according to claim 1, characterized in that The creating the second message message according to the message attribute information and the target message data includes: Identify each attribute field in the message attribute information; Assigning the target message data to each of the attribute fields to obtain second message data; Create the second message message according to the second message data.

4. The method according to claim 1, characterized in that: The sending a service call request to the server according to the first connection mode, the second connection mode and the second message includes: Sending a persistent connection establishment request to the server according to the first connection mode and the second message; After establishing a long connection with the server, the service call request is sent to the server according to the second connection mode and the second message.

5. The method according to claim 4, characterized in that The sending a long connection establishment request to the server according to the first connection mode and the second message includes: Obtaining a connection message from the second message message, where the connection message is used to send a long connection with the server; Sending a long connection establishment request encapsulating the connection message to the server through the first connection mode; The sending the service call request to the server according to the second connection mode and the second message includes: Acquire a message message from the second message message, where the message message is used to instruct the server to return a service message; A service call request encapsulating the message message is sent to the server through the second connection mode.

6. The method according to claim 1, characterized in that The method further comprises: Receive a service message fed back by the server; The service message is converted into data in a corresponding format and then stored.

7. An automated testing device for a TCP interface, characterized in that: The device comprises: A determination module, configured to receive a test request for a TCP interface, and determine identification information of the TCP interface according to the test request; A first acquisition module, used to acquire a message type and first message data of a first message message to be sent according to the identification information; A second acquisition module, used to acquire message attribute information of a second message message according to the message type, and acquire target message data corresponding to the message attribute information from the first message data; A creation module, used for creating the second message message according to the message attribute information and the target message data, wherein the second message message is a message message satisfying the message structure of the TCP interface; A sending module is used to create a first coroutine function, which is used to establish a long connection with a server; create a first connection mode according to the first coroutine function; create a second coroutine function, which is used to establish a message sending connection with the server; create a second connection mode according to the second coroutine function; send a service call request to the server according to the first connection mode, the second connection mode and the second message message, so as to perform an interface test on the TCP interface.

8. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.

Citation Information

Patent Citations

  • Testing method and system based on message

    CN102694701A