CN114666258B - Interface testing method, device, electronic equipment and medium - Google Patents

Interface testing method, device, electronic equipment and medium Download PDF

Info

Publication number
CN114666258B
CN114666258B CN202210287904.1A CN202210287904A CN114666258B CN 114666258 B CN114666258 B CN 114666258B CN 202210287904 A CN202210287904 A CN 202210287904A CN 114666258 B CN114666258 B CN 114666258B
Authority
CN
China
Prior art keywords
interface
target
verification rule
tested
data
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202210287904.1A
Other languages
Chinese (zh)
Other versions
CN114666258A (en
Inventor
卢辉宇
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Apollo Zhilian Beijing Technology Co Ltd
Apollo Zhixing Technology Guangzhou Co Ltd
Original Assignee
Apollo Zhilian Beijing Technology Co Ltd
Apollo Zhixing Technology Guangzhou Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Apollo Zhilian Beijing Technology Co Ltd, Apollo Zhixing Technology Guangzhou Co Ltd filed Critical Apollo Zhilian Beijing Technology Co Ltd
Priority to CN202210287904.1A priority Critical patent/CN114666258B/en
Publication of CN114666258A publication Critical patent/CN114666258A/en
Application granted granted Critical
Publication of CN114666258B publication Critical patent/CN114666258B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L43/00Arrangements for monitoring or testing data switching networks
    • H04L43/50Testing arrangements

Abstract

The disclosure provides an interface testing method, relates to the field of artificial intelligence, and particularly relates to the technical fields of computer technology, automatic driving and the like. The implementation scheme is as follows: sending a user request to a server and determining a target interface corresponding to the user request; obtaining a response message aiming at a user request and information to be tested corresponding to a target interface from a server, wherein the information to be tested comprises first data, and the first data corresponds to a message body of the response message; obtaining a target verification rule corresponding to a target interface, wherein the target verification rule comprises a first verification rule for verifying first data; and verifying the information to be tested based on the target verification rule.

Description

Interface testing method, device, electronic equipment and medium
Technical Field
The present disclosure relates to the field of artificial intelligence, and in particular, to the technical field of computer technology, autopilot, etc., and more particularly, to an interface testing method, apparatus, electronic device, computer readable storage medium, and computer program product.
Background
Testing of the interface may be accomplished through contractual testing. The contract test is a test for synchronization when two ends of the micro service are developed between a consumer and a provider, and when the contract test is carried out, a contract document can be created by the consumer end of the interface, rules of request and response are defined, then the provider of the interface service is requested according to the contract document, and whether the actual response is matched with the expected response or not is checked, so that the test on the interface is realized.
The approaches described in this section are not necessarily approaches that have been previously conceived or pursued. Unless otherwise indicated, it should not be assumed that any of the approaches described in this section qualify as prior art merely by virtue of their inclusion in this section. Similarly, the problems mentioned in this section should not be considered as having been recognized in any prior art unless otherwise indicated.
Disclosure of Invention
The present disclosure provides an interface testing method, apparatus, electronic device, computer readable storage medium, and computer program product.
According to an aspect of the present disclosure, there is provided an interface testing method, including: sending a user request to a server and determining a target interface corresponding to the user request; obtaining a response message aiming at the user request and information to be tested corresponding to the target interface from the server, wherein the information to be tested comprises first data, and the first data corresponds to a message body of the response message; obtaining a target verification rule corresponding to the target interface, wherein the target verification rule comprises a first verification rule for verifying the first data; and verifying the information to be tested based on the target verification rule.
According to another aspect of the present disclosure, there is provided an interface testing method, including: responding to a user request received from a client, and acquiring a target interface and a response message corresponding to the user request; determining information to be tested corresponding to the target interface based on the user request and the response message, wherein the information to be tested comprises first data, and the first data corresponds to a message body of the response message; and transmitting the response message and the information to be tested to the client
According to another aspect of the present disclosure, there is provided an interface test apparatus including: a sending module configured to send a user request to a server and determine a target interface corresponding to the user request; the first acquisition module is configured to acquire a response message aiming at the user request and information to be tested corresponding to the target interface from the server, wherein the information to be tested comprises first data, and the first data corresponds to a message body of the response message; a second acquisition module configured to acquire a target verification rule corresponding to the target interface, wherein the target verification rule includes a first verification rule for verifying the first data; and the verification module is configured to verify the information to be tested based on the target verification rule.
According to another aspect of the present disclosure, there is provided an interface test apparatus including: the system comprises an acquisition module, a response module and a control module, wherein the acquisition module is configured to respond to a user request received from a client and acquire a target interface and a response message corresponding to the user request; a determining module configured to determine information to be tested corresponding to the target interface based on the user request and the response message, wherein the information to be tested includes first data, and the first data corresponds to a message body of the response message; and the sending module is configured to send the response message and the information to be tested to the client.
According to another aspect of the present disclosure, there is provided an electronic device including: at least one processor; and a memory communicatively coupled to the at least one processor; wherein the memory stores instructions executable by the at least one processor to enable the at least one processor to perform an interface test method.
According to another aspect of the present disclosure, there is provided a non-transitory computer-readable storage medium storing computer instructions for causing the computer to perform an interface test method.
According to another aspect of the present disclosure, a computer program product is provided, comprising a computer program, wherein the computer program, when executed by a processor, implements an interface test method.
According to one or more embodiments of the present disclosure, an interface testing method is provided, which monitors and tests an interface in real time through data generated by actual operations of a user while satisfying the use requirements of the user, so that the scene of interface testing is covered more comprehensively.
It should be understood that the description in this section is not intended to identify key or critical features of the embodiments of the disclosure, nor is it intended to be used to limit the scope of the disclosure. Other features of the present disclosure will become apparent from the following specification.
Drawings
The accompanying drawings illustrate exemplary embodiments and, together with the description, serve to explain exemplary implementations of the embodiments. The illustrated embodiments are for exemplary purposes only and do not limit the scope of the claims. Throughout the drawings, identical reference numerals designate similar, but not necessarily identical, elements.
FIG. 1 illustrates a schematic diagram of an exemplary system in which various methods described herein may be implemented, in accordance with an embodiment of the present disclosure;
FIG. 2 illustrates a flow chart of an interface testing method according to an embodiment of the present disclosure;
FIG. 3 illustrates a flow chart of an interface testing method according to an embodiment of the present disclosure;
FIG. 4 shows a block diagram of an interface testing apparatus according to an embodiment of the present disclosure;
FIG. 5 shows a block diagram of an interface testing apparatus according to an embodiment of the present disclosure; and
FIG. 6 illustrates a system that can be used to implement the present disclosure a block diagram of an exemplary electronic device of an embodiment.
Detailed Description
Exemplary embodiments of the present disclosure are described below in conjunction with the accompanying drawings, which include various details of the embodiments of the present disclosure to facilitate understanding, and should be considered as merely exemplary. Accordingly, one of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope of the present disclosure. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
In the present disclosure, the use of the terms "first," "second," and the like to describe various elements is not intended to limit the positional relationship, timing relationship, or importance relationship of the elements, unless otherwise indicated, and such terms are merely used to distinguish one element from another element. In some examples, a first element and a second element may refer to the same instance of the element, and in some cases, they may also refer to different instances based on the description of the context.
The terminology used in the description of the various illustrated examples in this disclosure is for the purpose of describing particular examples only and is not intended to be limiting. Unless the context clearly indicates otherwise, the elements may be one or more if the number of the elements is not specifically limited. Furthermore, the term "and/or" as used in this disclosure encompasses any and all possible combinations of the listed items.
In the related technology, contract testing for an interface can be performed based on a Pact open source framework, a contract document is created by a consumer side, a request for a service providing side is defined by simulating an actual user, the service providing side provides data in a corresponding format according to the contract document established by the consumer side and returns the data to the consumer, the contract document is checked, if the data provided by the service providing side is not matched with the contract document generated by the consumer, an abnormality is thrown and a prompt is given, so that the interface testing is realized. However, in this method, the consumer end needs to define multiple requests for different responses of the same interface and generate multiple contract documents, and the contract test needs to be performed manually by executing the test case, so that the change of the interface cannot be perceived, and the interface cannot be monitored. Meanwhile, the checking type supported by the Pact framework is simpler, the support on the complex interface is poorer, and the cost for modifying the contract document is higher.
In order to solve the problems, the contract test for the interface is driven by the data generated by the actual operation of the user, the real-time monitoring and test of the interface are realized while the use requirement of the user is met, the defect that the consumer request needs to be simulated in the conventional contract test is overcome, and the scene of the contract test is more comprehensive in coverage.
It should be noted that, in the technical solution of the present disclosure, the related processes of collecting, storing, using, processing, transmitting, providing, disclosing, etc. of the personal information of the user all conform to the rules of the related laws and regulations, and do not violate the popular regulations.
Embodiments of the present disclosure will be described in detail below with reference to the accompanying drawings.
Fig. 1 illustrates a schematic diagram of an exemplary system 100 in which various methods and apparatus described herein may be implemented, in accordance with an embodiment of the present disclosure. Referring to fig. 1, the system 100 includes one or more client devices 101, 102, 103, 104, 105, and 106, a server 120, and one or more communication networks 110 coupling the one or more client devices to the server 120. Client devices 101, 102, 103, 104, 105, and 106 may be configured to execute one or more applications.
In embodiments of the present disclosure, the server 120 may run one or more services or software applications that enable execution of the interface test method.
In some embodiments, server 120 may also provide other services or software applications that may include non-virtual environments and virtual environments. In some embodiments, these services may be provided as web-based services or cloud services, for example, provided to users of client devices 101, 102, 103, 104, 105, and/or 106 under a software as a service (SaaS) model.
In the configuration shown in fig. 1, server 120 may include one or more components that implement the functions performed by server 120. These components may include software components, hardware components, or a combination thereof that are executable by one or more processors. A user operating client devices 101, 102, 103, 104, 105, and/or 106 may in turn utilize one or more client applications to interact with server 120 to utilize the services provided by these components. It should be appreciated that a variety of different system configurations are possible, which may differ from system 100. Accordingly, FIG. 1 is one example of a system for implementing the various methods described herein and is not intended to be limiting.
The user may perform the interface test method using client devices 101, 102, 103, 104, 105, and/or 106. The client device may provide an interface that enables a user of the client device to interact with the client device. The client device may also output information to the user via the interface. Although fig. 1 depicts only six client devices, those skilled in the art will appreciate that the present disclosure may support any number of client devices.
Client devices 101, 102, 103, 104, 105, and/or 106 may include various types of computer devices, such as portable handheld devices, general purpose computers (such as personal computers and laptop computers), workstation computers, wearable devices, smart screen devices, self-service terminal devices, service robots, gaming systems, thin clients, various messaging devices, sensors or other sensing devices, and the like. These computer devices may run various types and versions of software applications and operating systems, such as MICROSOFT Windows, APPLE iOS, UNIX-like operating systems, linux, or Linux-like operating systems (e.g., GOOGLE Chrome OS); or include various mobile operating systems such as MICROSOFT Windows Mobile OS, iOS, windows Phone, android. Portable handheld devices may include cellular telephones, smart phones, tablet computers, personal Digital Assistants (PDAs), and the like. Wearable devices may include head mounted displays (such as smart glasses) and other devices. The gaming system may include various handheld gaming devices, internet-enabled gaming devices, and the like. The client device is capable of executing a variety of different applications, such as various Internet-related applications, communication applications (e.g., email applications), short Message Service (SMS) applications, and may use a variety of communication protocols.
Network 110 may be any type of network known to those skilled in the art that may support data communications using any of a number of available protocols, including but not limited to TCP/IP, SNA, IPX, etc. For example only, the one or more networks 110 may be a Local Area Network (LAN), an ethernet-based network, a token ring, a Wide Area Network (WAN), the internet, a virtual network, a Virtual Private Network (VPN), an intranet, an extranet, a Public Switched Telephone Network (PSTN), an infrared network, a wireless network (e.g., bluetooth, WIFI), and/or any combination of these and/or other networks.
The server 120 may include one or more general purpose computers, special purpose server computers (e.g., PC (personal computer) servers, UNIX servers, mid-end servers), blade servers, mainframe computers, server clusters, or any other suitable arrangement and/or combination. The server 120 may include one or more virtual machines running a virtual operating system, or other computing architecture that involves virtualization (e.g., one or more flexible pools of logical storage devices that may be virtualized to maintain virtual storage devices of the server). In various embodiments, server 120 may run one or more services or software applications that provide the functionality described below.
The computing units in server 120 may run one or more operating systems including any of the operating systems described above as well as any commercially available server operating systems. Server 120 may also run any of a variety of additional server applications and/or middle tier applications, including HTTP servers, FTP servers, CGI servers, JAVA servers, database servers, etc.
In some implementations, server 120 may include one or more applications to analyze and consolidate data feeds and/or event updates received from users of client devices 101, 102, 103, 104, 105, and 106. Server 120 may also include one or more applications to display data feeds and/or real-time events via one or more display devices of client devices 101, 102, 103, 104, 105, and 106.
In some implementations, the server 120 may be a server of a distributed system or a server that incorporates a blockchain. The server 120 may also be a cloud server, or an intelligent cloud computing server or intelligent cloud host with artificial intelligence technology. The cloud server is a host product in a cloud computing service system, so as to solve the defects of large management difficulty and weak service expansibility in the traditional physical host and virtual private server (VPS, virtual Private Server) service.
The system 100 may also include one or more databases 130. In some embodiments, these databases may be used to store data and other information. For example, one or more of databases 130 may be used to store information such as audio files and video files. Database 130 may reside in various locations. For example, the database used by the server 120 may be local to the server 120, or may be remote from the server 120 and may communicate with the server 120 via a network-based or dedicated connection. Database 130 may be of different types. In some embodiments, the database used by server 120 may be, for example, a relational database. One or more of these databases may store, update, and retrieve the databases and data from the databases in response to the commands.
In some embodiments, one or more of databases 130 may also be used by applications to store application data. The databases used by the application may be different types of databases, such as key value stores, object stores, or conventional stores supported by the file system.
The system 100 of fig. 1 may be configured and operated in various ways to enable application of the various methods and apparatus described in accordance with the present disclosure.
Fig. 2 shows a flowchart of an interface testing method according to an embodiment of the present disclosure. As shown in fig. 2, the interface test method 200 includes: step S201, a user request is sent to a server, and a target interface corresponding to the user request is determined; step S202, a response message aiming at the user request and information to be tested corresponding to the target interface are obtained from the server, wherein the information to be tested comprises first data, and the first data corresponds to a message body of the response message; step 203, obtaining a target verification rule corresponding to the target interface, wherein the target verification rule comprises a first verification rule for verifying the first data; and step S204, checking the information to be tested based on the target checking rule.
Therefore, contract test for the interface is driven through data generated by actual operation of a user, the user needs are met, the information to be tested returned through the target interface is verified through the target verification rule corresponding to the target interface, the user experience is not influenced, the interface is monitored and tested in real time, the defect that a user request needs to be simulated in the conventional contract test is overcome, and the scene of the interface test is covered more comprehensively.
According to some embodiments, step S203 comprises: acquiring an interface document of the target interface; defining the first verification rule based on the interface document; and determining the target verification rule based on the first verification rule.
It can be understood that, before testing the interface, a target verification rule for verifying the information to be tested needs to be predefined, that is, before performing contract testing on the interface, a contract document needs to be predefined to determine whether the information to be tested meets the expectations. For the first data of the message body corresponding to the response message in the information to be tested, which parameters can be included in the message body of the response message corresponding to the interface, namely the response body of the interface, can be determined based on the interface document of the target interface, so that a first check rule for checking the first data is defined, and the verification of the message body of the response message is realized based on the first check rule in the subsequent interface test to determine the correctness of the response body returned by the server.
According to some embodiments, the information to be tested further includes second data, the second data corresponding to a message body of a request message corresponding to the user request, and wherein step S203 further includes: defining a second verification rule for verifying the second data based on the interface document; and determining the target verification rule based on the second verification rule.
It can be understood that the second data corresponding to the message body of the request message corresponding to the user request is the request body. Similarly, it can be determined based on the interface document of the target interface, which parameters can be included in the message body of the request message corresponding to the interface, that is, the request body of the interface, and the types and value ranges of these parameters, so as to ensure that the request sent by the user is reasonable. Therefore, a second check rule for checking the second data can be predefined, and the verification of the message body of the request message can be realized based on the second check rule in the subsequent interface test, so as to determine the correctness of the request body sent by the client.
According to some embodiments, the information to be tested further includes third data, the third data corresponding to a header of the response message, and wherein step S203 further includes: defining a third verification rule for verifying the third data based on the interface document; and determining the target verification rule based on the third verification rule.
It is understood that the third data of the header corresponding to the response message is the response header. Similarly, it may be determined, based on the interface document of the target interface, which parameters may be included in the header of the response packet corresponding to the interface, and the types and value ranges of these parameters, so that a third verification rule for verifying the third data may be predefined, and in the subsequent interface test, verification of the header of the response packet may be implemented based on the third verification rule, so as to determine the correctness of the response header sent by the server.
According to some embodiments, the information to be tested further includes fourth data, the fourth data corresponding to a header of a request message corresponding to the user request, and wherein step S203 further includes: defining a fourth verification rule for verifying the fourth data based on the interface document; and determining the target verification rule based on the fourth verification rule.
It can be understood that the fourth data of the header corresponding to the request message corresponding to the user request is the request header. Similarly, it may be determined, based on the interface document of the target interface, which parameters may be included in the header of the request message corresponding to the interface, that is, the request header of the interface, and the types and value ranges of these parameters, so as to ensure that the source of the request is legal. Therefore, a fourth check rule for checking the fourth data can be predefined, and the check of the header of the request message is realized based on the fourth check rule in the subsequent interface test, so as to determine the correctness of the request header sent by the client.
According to the above embodiments, before testing the interfaces, a response body, a request body, a response header, and first, second, third and fourth verification rules corresponding to the request header for verifying the interfaces may be defined in advance according to respective interface documents of the interfaces to be tested, and the verification rules corresponding to the user request are matched in response to the user request, so as to implement the full coverage test of the data passing through the interfaces and the monitoring of the interfaces to be tested.
According to some embodiments, the data included in the information to be tested is in a key-value format, the key corresponds to a parameter to be verified, and the target verification rule is used to verify a relationship between the key and the value based on the key. Because the data to be tested are in the preset format of key-value, the target verification rule can determine whether the relation between the key and the value accords with the expected or illegal parameters to be tested exist or not based on the parameters to be tested represented by the key, so that the preset verification rule can support contract testing of interfaces with various data structures of the key-value type.
According to some embodiments, the target verification rule includes at least one of the following verification types: regular check, value check and type check. Because the target verification rule is defined in advance according to the interface document, multiple types of verification can be defined according to actual requirements, so that different verification requirements are met.
According to some embodiments, the method further comprises: acquiring a verification result of the information to be tested and generating a verification report; and rendering and displaying the verification report. For example, if a field of the interface is detected in the process of testing the interface, a verification report can be generated based on abnormal data in the information to be tested, and the verification report is rendered and displayed, so that abnormal reminding of a user is realized.
According to another aspect of the present disclosure, an interface testing method is provided. Fig. 3 shows a flowchart of an interface testing method according to an embodiment of the present disclosure. As shown in fig. 3, the interface testing method 300 includes: step S301, responding to a user request received from a client, and acquiring a target interface and a response message corresponding to the user request; step S302, determining information to be tested corresponding to the target interface based on the user request and the response message, where the information to be tested includes first data, and the first data corresponds to a message body of the response message; and step S303, the response message and the information to be tested are sent to the client.
The server can drive contract test for the interface through data generated by actual operation of a user, and after receiving a request message corresponding to a user request, the server obtains a corresponding target interface and a response message, determines information to be tested corresponding to the target interface, and sends the response message and the information to be tested back to the client. In one example, the information to be tested may be in json format. Therefore, the server also provides information to be tested for interface testing for testing of the target interface while meeting the use requirements of the user. Therefore, the real-time monitoring and testing of the interface are realized without influencing the user experience, the defect that the user request needs to be simulated in the conventional contract testing is overcome, and the scene of the interface testing is more comprehensive in coverage.
According to some embodiments, step S302 includes: generating a log file in a key-value format based on the user request and the response message, wherein the key corresponds to a parameter to be verified; and analyzing the log file to determine information to be tested corresponding to the target interface.
By way of example, a log file may be obtained using a retrofit to an engine x (nginx) service. In one example, the nginx service may be used to record a request message and a response message corresponding to a user request, and copy and reform the request message and the response message to generate a log file in a key-value format, where the key-value format may enable a verification rule to determine whether a relationship between a key and a value accords with an expected or illegal parameters to be tested or not based on parameters to be tested represented by the key in an interface test of a client, so that a preconfigured verification rule can support contract tests of interfaces with multiple data structures of a key-value type. In one example, the log file may be parsed with a python script to determine information to be tested corresponding to the target interface.
According to another aspect of the present disclosure, an interface testing apparatus is provided. As shown in fig. 4, the interface test apparatus 400 includes: a sending module 401 configured to send a user request to a server and determine a target interface corresponding to the user request; a first obtaining module 402, configured to obtain, from the server, a response message for the user request and information to be tested corresponding to the target interface, where the information to be tested includes first data, and the first data corresponds to a message body of the response message; a second obtaining module 403, configured to obtain a target verification rule corresponding to the target interface, where the target verification rule includes a first verification rule for verifying the first data; and a verification module 404 configured to verify the information to be tested based on the target verification rule.
The operation of the modules 401-404 of the interface test apparatus 400 is similar to the operation of steps S201-S204 described above and will not be described in detail herein.
Therefore, the contract test for the interface is driven through the data generated by the actual operation of the user, the user requirement is met, the verification module 404 verifies the information to be tested returned through the target interface through the target verification rule corresponding to the target interface, the user experience is not influenced, the interface is monitored and tested in real time, the defect that the user request needs to be simulated in the conventional contract test is overcome, and the scene of the interface test is covered more comprehensively.
According to some embodiments, the second acquisition module 403 comprises: an acquisition unit configured to acquire an interface document of the target interface; a first defining unit configured to define the first verification rule based on the interface document; and a first determination unit configured to determine the target verification rule based on the first verification rule.
It should be understood that, before the interface testing device 400 tests the interface, a target verification rule for verifying the information to be tested needs to be predefined, that is, before the interface is subjected to contract testing, a contract document needs to be predefined to determine whether the information to be tested meets the expectations. For the first data of the message body corresponding to the response message in the information to be tested, the first determining unit may determine, based on the interface document of the target interface, which parameters may be included in the message body of the response message corresponding to the interface, that is, the response body of the interface, and types and value ranges of the parameters, so as to define a first verification rule for verifying the first data, and in subsequent interface tests, the verification module 404 implements verification of the message body of the response message based on the first verification rule, so as to determine the correctness of the response body returned by the server.
According to some embodiments, the information to be tested further comprises second data corresponding to a message body of a request message corresponding to the user request, and wherein the second obtaining module 403 further comprises: a second definition unit configured to define a second check rule for checking the second data based on the interface document; and a second determination unit configured to determine the target verification rule based on the second verification rule.
It can be understood that the second data corresponding to the message body of the request message corresponding to the user request is the request body. Similarly, the second definition unit may determine, based on the interface document of the target interface, which parameters may be included in the message body of the request message corresponding to the interface, that is, the request body of the interface, and the types and value ranges of these parameters, so as to ensure that the request issued by the user is reasonable. Thus, a second check rule for checking the second data may be predefined, and in the subsequent interface test, the check module 404 performs, based on the second check rule, checking the message body of the request message, so as to determine the correctness of the request body sent by the client.
According to some embodiments, the information to be tested further includes third data, the third data corresponding to a header of the response message, and wherein the second obtaining module 403 further includes: a third definition unit configured to define a third verification rule for verifying the third data based on the interface document; and a third determination unit configured to determine the target verification rule based on the third verification rule.
It is understood that the third data of the header corresponding to the response message is the response header. Similarly, the third definition unit may determine, based on the interface document of the target interface, which parameters may be included in the header of the response packet corresponding to the interface, that is, the response header of the interface, and types and value ranges of these parameters, etc., so that a third verification rule for verifying the third data may be predefined, and in the subsequent interface test, the verification module 404 implements verification of the header of the response packet based on the third verification rule, so as to determine the correctness of the response header sent by the server.
According to some embodiments, the information to be tested further includes fourth data, the fourth data corresponding to a header of a request message corresponding to the user request, and wherein the second obtaining module 403 further includes: a fourth definition unit configured to define a fourth verification rule for verifying the fourth data based on the interface document; and a fourth determination unit configured to determine the target verification rule based on the fourth verification rule.
It can be understood that the fourth data of the header corresponding to the request message corresponding to the user request is the request header. Similarly, the fourth definition unit may determine, based on the interface document of the target interface, which parameters may be included in the header of the request message corresponding to the interface, that is, the request header of the interface, and the types and value ranges of these parameters, so as to ensure that the source of the request is legal. Thus, a fourth check rule for checking the fourth data may be predefined, and in the subsequent interface test, the check module 404 performs, based on the fourth check rule, checking the header of the request packet, so as to determine the correctness of the request header sent by the client.
As can be seen from the above embodiments, before testing the interfaces, the second obtaining module 403 may define, in advance, a response body, a request body, a response header, and a first check rule, a second check rule, a third check rule, and a fourth check rule corresponding to the request header for checking the interfaces according to respective interface documents of the interfaces to be tested, and match the check rules corresponding to the interfaces requested by the user in response to the user request, so as to implement the test of full coverage of the data passing through the interfaces and the monitoring of the interfaces to be tested.
According to some embodiments, the data included in the information to be tested is in a key-value format, the key corresponds to a parameter to be verified, and the target verification rule is used to verify a relationship between the key and the value based on the key. Because the data to be tested are in the preset format of key-value, the target verification rule can determine whether the relation between the key and the value accords with the expected or illegal parameters to be tested exist or not based on the parameters to be tested represented by the key, so that the preset verification rule can support contract testing of interfaces with various data structures of the key-value type.
According to some embodiments, the target verification rule includes at least one of the following verification types: regular check, value check and type check. Because the target verification rule is defined in advance according to the interface document, multiple types of verification can be defined according to actual requirements, so that different verification requirements are met.
According to another aspect of the present disclosure, an interface testing apparatus is provided. Fig. 5 shows a block diagram of an interface test apparatus according to an embodiment of the present disclosure. As shown in fig. 5, the interface test apparatus 500 includes: an obtaining module 501 configured to obtain, in response to receiving a user request from a client, a target interface and a response message corresponding to the user request; a determining module 502, configured to determine, based on the user request and the response message, information to be tested corresponding to the target interface, where the information to be tested includes first data, and the first data corresponds to a message body of the response message; and a sending module 503 configured to send the response message and the information to be tested to the client.
Contract testing for an interface may be driven by data generated by the actual operation of the user. The obtaining module 501 obtains the corresponding target interface and response message after receiving the request message corresponding to the user request, determines the information to be tested corresponding to the target interface, and sends the response message and the information to be tested back to the client. In one example, the information to be tested may be in json format. Therefore, the server also provides information to be tested for interface testing for testing of the target interface while meeting the use requirements of the user. Therefore, the real-time monitoring and testing of the interface are realized without influencing the user experience, the defect that the user request needs to be simulated in the conventional contract testing is overcome, and the scene of the interface testing is more comprehensive in coverage.
The operation of the modules 501-503 of the interface test apparatus 500 is similar to the operation of steps S301-S303 described above, and will not be described in detail herein.
According to some embodiments, the generating module 502 includes: a generating unit configured to generate a log file in a key-value format based on the user request and the response message, wherein the key corresponds to a parameter to be verified; and an analysis unit configured to analyze the log file to determine information to be tested corresponding to the target interface.
Illustratively, the generation unit may utilize a retrofit to engine x (ngine x, ngix) service to obtain the log file. In one example, the nginx service may be used to record a request message and a response message corresponding to a user request, and copy and reform the request message and the response message to generate a log file in a key-value format, where the key-value format may enable a verification rule to determine whether a relationship between a key and a value accords with an expected or illegal parameters to be tested or not based on parameters to be tested represented by the key in an interface test of a client, so that a preconfigured verification rule can support contract tests of interfaces with multiple data structures of a key-value type. In one example, the parsing unit may parse the log file using the python script to determine information to be tested corresponding to the target interface.
As shown in fig. 6, the electronic device 600 includes a computing unit 601 that can perform various appropriate actions and processes according to a computer program stored in a Read Only Memory (ROM) 602 or a computer program loaded from a storage unit 608 into a Random Access Memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the electronic device 600 can also be stored. The computing unit 601, ROM 602, and RAM 603 are connected to each other by a bus 604. An input/output (I/O) interface 605 is also connected to bus 604.
A number of components in the electronic device 600 are connected to the I/O interface 605, including: an input unit 606, an output unit 607, a storage unit 608, and a communication unit 609. The input unit 606 may be any type of device capable of inputting information to the electronic device 600, the input unit 606 may receive input numeric or character information and generate key signal inputs related to user settings and/or function control of the electronic device, and may include, but is not limited to, a mouse, a keyboard, a touch screen, a trackpad, a trackball, a joystick, a microphone, and/or a remote control. The output unit 607 may be any type of device capable of presenting information and may include, but is not limited to, a display, speakers, video/audio output terminals, vibrators, and/or printers. Storage unit 608 may include, but is not limited to, magnetic disks, optical disks. The communication unit 609 allows the electronic device 600 to exchange information/data with other devices through a computer network, such as the internet, and/or various telecommunication networksAnd may include, but is not limited to, a modem, a network card, an infrared communication device, a wireless communication transceiver, and/or a chipset, such as bluetooth TM Devices, 802.11 devices, wiFi devices, wiMax devices, cellular communication devices, and/or the like.
The computing unit 601 may be a variety of general and/or special purpose processing components having processing and computing capabilities. Some examples of computing unit 601 include, but are not limited to, a Central Processing Unit (CPU), a Graphics Processing Unit (GPU), various specialized Artificial Intelligence (AI) computing chips, various computing units running machine learning model algorithms, a Digital Signal Processor (DSP), and any suitable processor, controller, microcontroller, etc. The computing unit 601 performs the various methods and processes described above, such as interface test methods. For example, in some embodiments, the interface testing method may be implemented as a computer software program tangibly embodied on a machine-readable medium, such as storage unit 608. In some embodiments, part or all of the computer program may be loaded and/or installed onto the electronic device 600 via the ROM 602 and/or the communication unit 609. When the computer program is loaded into RAM 603 and executed by computing unit 601, one or more steps of the interface test method described above may be performed. Alternatively, in other embodiments, the computing unit 601 may be configured to perform the interface test method by any other suitable means (e.g., by means of firmware).
Various implementations of the systems and techniques described here above may be implemented in digital electronic circuitry, integrated circuit systems, field Programmable Gate Arrays (FPGAs), application Specific Integrated Circuits (ASICs), application Specific Standard Products (ASSPs), systems On Chip (SOCs), complex Programmable Logic Devices (CPLDs), computer hardware, firmware, software, and/or combinations thereof. These various embodiments may include: implemented in one or more computer programs, the one or more computer programs may be executed and/or interpreted on a programmable system including at least one programmable processor, which may be a special purpose or general-purpose programmable processor, that may receive data and instructions from, and transmit data and instructions to, a storage system, at least one input device, and at least one output device.
Program code for carrying out methods of the present disclosure may be written in any combination of one or more programming languages. These program code may be provided to a processor or controller of a general purpose computer, special purpose computer, or other programmable data processing apparatus such that the program code, when executed by the processor or controller, causes the functions/operations specified in the flowchart and/or block diagram to be implemented. The program code may execute entirely on the machine, partly on the machine, as a stand-alone software package, partly on the machine and partly on a remote machine or entirely on the remote machine or server.
In the context of this disclosure, a machine-readable medium may be a tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. The machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
To provide for interaction with a user, the systems and techniques described here can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to a user; and a keyboard and pointing device (e.g., a mouse or trackball) by which a user can provide input to the computer. Other kinds of devices may also be used to provide for interaction with a user; for example, feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form, including acoustic input, speech input, or tactile input.
The systems and techniques described here can be implemented in a computing system that includes a background component (e.g., as a data server), or that includes a middleware component (e.g., an application server), or that includes a front-end component (e.g., a user computer having a graphical user interface or a web browser through which a user can interact with an implementation of the systems and techniques described here), or any combination of such background, middleware, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: local Area Networks (LANs), wide Area Networks (WANs), and the internet.
The computer system may include a client and a server. The client and server are typically remote from each other and typically interact through a communication network. The relationship of client and server arises by virtue of computer programs running on the respective computers and having a client-server relationship to each other. The server may be a cloud server, a server of a distributed system, or a server incorporating a blockchain.
It should be appreciated that various forms of the flows shown above may be used to reorder, add, or delete steps. For example, the steps recited in the present disclosure may be performed in parallel, sequentially or in a different order, provided that the desired results of the disclosed aspects are achieved, and are not limited herein.
Although embodiments or examples of the present disclosure have been described with reference to the accompanying drawings, it is to be understood that the foregoing methods, systems, and apparatus are merely exemplary embodiments or examples, and that the scope of the present invention is not limited by these embodiments or examples but only by the claims following the grant and their equivalents. Various elements of the embodiments or examples may be omitted or replaced with equivalent elements thereof. Furthermore, the steps may be performed in a different order than described in the present disclosure. Further, various elements of the embodiments or examples may be combined in various ways. It is important that as technology evolves, many of the elements described herein may be replaced by equivalent elements that appear after the disclosure.

Claims (20)

1. An interface testing method, comprising:
sending a user request to a server and determining a target interface corresponding to the user request;
Obtaining a response message aiming at the user request and information to be tested corresponding to the target interface from the server, wherein the information to be tested comprises first data, and the first data corresponds to a message body of the response message;
obtaining a target verification rule corresponding to the target interface, wherein the target verification rule comprises a first verification rule for verifying the first data; and
and verifying the information to be tested based on the target verification rule.
2. The method of claim 1, wherein the obtaining a target verification rule corresponding to the target interface comprises:
acquiring an interface document of the target interface;
defining the first verification rule based on the interface document; and
and determining the target check rule based on the first check rule.
3. The method of claim 2, wherein the information to be tested further comprises second data corresponding to a message body of a request message corresponding to the user request, and wherein,
the obtaining the target verification rule corresponding to the target interface further includes:
Defining a second verification rule for verifying the second data based on the interface document; and
the target verification rule is determined based on the second verification rule.
4. The method of claim 2, wherein the information to be tested further comprises third data, the third data corresponding to a header of the response message, and wherein,
the obtaining the target verification rule corresponding to the target interface further includes:
defining a third verification rule for verifying the third data based on the interface document; and
and determining the target check rule based on the third check rule.
5. The method of claim 2, wherein the information to be tested further comprises fourth data corresponding to a header of a request message corresponding to the user request, and wherein,
the obtaining the target verification rule corresponding to the target interface further includes:
defining a fourth verification rule for verifying the fourth data based on the interface document; and
and determining the target check rule based on the fourth check rule.
6. The method of any of claims 1-5, wherein the information to be tested includes data in a key-value format, the key corresponding to a parameter to be verified, and the target verification rule is used to verify a relationship between the key and the value based on the key.
7. The method of any of claims 1-5, wherein the target verification rule comprises at least one of the following verification types:
regular check, value check and type check.
8. An interface testing method, comprising:
responding to a user request received from a client, and acquiring a target interface and a response message corresponding to the user request;
determining information to be tested corresponding to the target interface based on the user request and the response message, wherein the information to be tested comprises first data, and the first data corresponds to a message body of the response message; and
and sending the response message and the information to be tested to the client.
9. The method of claim 8, wherein the determining information to be tested corresponding to the target interface based on the user request and the response message comprises;
generating a log file in a key-value format based on the user request and the response message, wherein the key corresponds to a parameter to be verified; and
and analyzing the log file to determine the information to be tested corresponding to the target interface.
10. An interface testing apparatus, comprising:
a sending module configured to send a user request to a server and determine a target interface corresponding to the user request;
the first acquisition module is configured to acquire a response message aiming at the user request and information to be tested corresponding to the target interface from the server, wherein the information to be tested comprises first data, and the first data corresponds to a message body of the response message;
a second acquisition module configured to acquire a target verification rule corresponding to the target interface, wherein the target verification rule includes a first verification rule for verifying the first data; and
and the verification module is configured to verify the information to be tested based on the target verification rule.
11. The apparatus of claim 10, wherein the second acquisition module comprises:
an acquisition unit configured to acquire an interface document of the target interface;
a first defining unit configured to define the first verification rule based on the interface document; and
and a first determination unit configured to determine the target verification rule based on the first verification rule.
12. The apparatus of claim 11, wherein the information to be tested further comprises second data corresponding to a message body of a request message corresponding to the user request, and wherein the second obtaining module further comprises:
a second definition unit configured to define a second check rule for checking the second data based on the interface document; and
and a second determination unit configured to determine the target verification rule based on the second verification rule.
13. The apparatus of claim 11, wherein the information to be tested further comprises third data corresponding to a header of the response message, and wherein the second obtaining module further comprises:
a third definition unit configured to define a third verification rule for verifying the third data based on the interface document; and
and a third determination unit configured to determine the target verification rule based on the third verification rule.
14. The apparatus of claim 11, wherein the information to be tested further comprises fourth data corresponding to a header of a request message corresponding to the user request, and wherein the second obtaining module further comprises:
A fourth definition unit configured to define a fourth verification rule for verifying the fourth data based on the interface document; and
and a fourth determination unit configured to determine the target verification rule based on the fourth verification rule.
15. The apparatus of any of claims 10-14, wherein the information to be tested includes data in a key-value format, the key corresponding to a parameter to be verified, and the target verification rule is to verify a relationship between the key and the value based on the key.
16. The apparatus of any of claims 10-14, wherein the target verification rule comprises at least one of the following verification types:
regular check, value check and type check.
17. An interface testing apparatus, comprising:
the system comprises an acquisition module, a response module and a control module, wherein the acquisition module is configured to respond to a user request received from a client and acquire a target interface and a response message corresponding to the user request;
a determining module configured to determine information to be tested corresponding to the target interface based on the user request and the response message, wherein the information to be tested includes first data, and the first data corresponds to a message body of the response message; and
And the sending module is configured to send the response message and the information to be tested to the client.
18. The apparatus of claim 17, wherein the means for determining comprises:
a generating unit configured to generate a log file in a key-value format based on the user request and the response message, wherein the key corresponds to a parameter to be verified; and
and the analysis unit is configured to analyze the log file to determine information to be tested corresponding to the target interface.
19. An electronic device, comprising:
at least one processor; and
a memory communicatively coupled to the at least one processor; wherein the method comprises the steps of
The memory stores instructions executable by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-9.
20. A non-transitory computer readable storage medium storing computer instructions for causing the computer to perform the method of any one of claims 1-9.
CN202210287904.1A 2022-03-22 2022-03-22 Interface testing method, device, electronic equipment and medium Active CN114666258B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210287904.1A CN114666258B (en) 2022-03-22 2022-03-22 Interface testing method, device, electronic equipment and medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210287904.1A CN114666258B (en) 2022-03-22 2022-03-22 Interface testing method, device, electronic equipment and medium

Publications (2)

Publication Number Publication Date
CN114666258A CN114666258A (en) 2022-06-24
CN114666258B true CN114666258B (en) 2023-11-07

Family

ID=82030910

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210287904.1A Active CN114666258B (en) 2022-03-22 2022-03-22 Interface testing method, device, electronic equipment and medium

Country Status (1)

Country Link
CN (1) CN114666258B (en)

Citations (17)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2013074873A1 (en) * 2011-11-18 2013-05-23 Amazon Technologies, Inc. Virtual network interface objects
CN109298997A (en) * 2018-08-08 2019-02-01 平安科技(深圳)有限公司 Interface test method, system, computer equipment and storage medium
CN109783367A (en) * 2018-12-15 2019-05-21 中国平安人寿保险股份有限公司 Interface test method, device, computer installation and storage medium
CN110750409A (en) * 2018-07-23 2020-02-04 北京奇虎科技有限公司 Method, device and system for realizing test
CN111045756A (en) * 2019-12-10 2020-04-21 中国工商银行股份有限公司 Method, apparatus, computing device, and medium for generating interface service
WO2020119434A1 (en) * 2018-12-15 2020-06-18 深圳壹账通智能科技有限公司 Method and apparatus for interface data processing, method and apparatus for automated testing, device, and medium
CN111478969A (en) * 2020-04-09 2020-07-31 吉林亿联银行股份有限公司 Interface checking method and device
CN112199279A (en) * 2020-09-30 2021-01-08 北京一起教育信息咨询有限责任公司 Full-link inspection method and device
CN112269706A (en) * 2020-11-16 2021-01-26 北京百度网讯科技有限公司 Interface parameter checking method and device, electronic equipment and computer readable medium
US10901880B1 (en) * 2019-09-18 2021-01-26 Capital One Services, Llc API monitoring and validation for onboarded applications
CN112671605A (en) * 2020-12-16 2021-04-16 建信金融科技有限责任公司 Test method and device and electronic equipment
CN113032244A (en) * 2021-02-23 2021-06-25 中国工商银行股份有限公司 Interface testing method, device, computer system and computer readable storage medium
CN113282476A (en) * 2021-06-24 2021-08-20 深圳市商汤科技有限公司 Interface performance testing method and device and electronic equipment
CN113297078A (en) * 2021-05-24 2021-08-24 平安壹钱包电子商务有限公司 MOCK system and data testing method based on MOCK system
CN113778725A (en) * 2020-06-03 2021-12-10 北京沃东天骏信息技术有限公司 Data verification method and device
CN114003497A (en) * 2021-11-01 2022-02-01 北京百度网讯科技有限公司 Method, device and equipment for testing service system and storage medium
CN114003506A (en) * 2021-11-10 2022-02-01 广州易方信息科技股份有限公司 Interface testing and monitoring method based on log recording

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9740600B2 (en) * 2015-02-10 2017-08-22 Wipro Limited Method and device for improving software performance testing
US11163672B2 (en) * 2020-01-31 2021-11-02 Salesforce.Com, Inc. Test suite generation from metadata

Patent Citations (17)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2013074873A1 (en) * 2011-11-18 2013-05-23 Amazon Technologies, Inc. Virtual network interface objects
CN110750409A (en) * 2018-07-23 2020-02-04 北京奇虎科技有限公司 Method, device and system for realizing test
CN109298997A (en) * 2018-08-08 2019-02-01 平安科技(深圳)有限公司 Interface test method, system, computer equipment and storage medium
CN109783367A (en) * 2018-12-15 2019-05-21 中国平安人寿保险股份有限公司 Interface test method, device, computer installation and storage medium
WO2020119434A1 (en) * 2018-12-15 2020-06-18 深圳壹账通智能科技有限公司 Method and apparatus for interface data processing, method and apparatus for automated testing, device, and medium
US10901880B1 (en) * 2019-09-18 2021-01-26 Capital One Services, Llc API monitoring and validation for onboarded applications
CN111045756A (en) * 2019-12-10 2020-04-21 中国工商银行股份有限公司 Method, apparatus, computing device, and medium for generating interface service
CN111478969A (en) * 2020-04-09 2020-07-31 吉林亿联银行股份有限公司 Interface checking method and device
CN113778725A (en) * 2020-06-03 2021-12-10 北京沃东天骏信息技术有限公司 Data verification method and device
CN112199279A (en) * 2020-09-30 2021-01-08 北京一起教育信息咨询有限责任公司 Full-link inspection method and device
CN112269706A (en) * 2020-11-16 2021-01-26 北京百度网讯科技有限公司 Interface parameter checking method and device, electronic equipment and computer readable medium
CN112671605A (en) * 2020-12-16 2021-04-16 建信金融科技有限责任公司 Test method and device and electronic equipment
CN113032244A (en) * 2021-02-23 2021-06-25 中国工商银行股份有限公司 Interface testing method, device, computer system and computer readable storage medium
CN113297078A (en) * 2021-05-24 2021-08-24 平安壹钱包电子商务有限公司 MOCK system and data testing method based on MOCK system
CN113282476A (en) * 2021-06-24 2021-08-20 深圳市商汤科技有限公司 Interface performance testing method and device and electronic equipment
CN114003497A (en) * 2021-11-01 2022-02-01 北京百度网讯科技有限公司 Method, device and equipment for testing service system and storage medium
CN114003506A (en) * 2021-11-10 2022-02-01 广州易方信息科技股份有限公司 Interface testing and monitoring method based on log recording

Also Published As

Publication number Publication date
CN114666258A (en) 2022-06-24

Similar Documents

Publication Publication Date Title
KR102158557B1 (en) Method and device for determining response time
CN111858360B (en) Applet testing method, device, equipment and storage medium
WO2023125851A1 (en) Remote diagnostics method and apparatus, electronic device and storage medium
KR102488582B1 (en) Method and apparatus for verifying operation state of application
CN114417780B (en) State synchronization method and device, electronic equipment and storage medium
WO2022100075A1 (en) Method and apparatus for performance test, electronic device and computer-readable medium
CN114328132A (en) Method, device, equipment and medium for monitoring state of external data source
CN114666258B (en) Interface testing method, device, electronic equipment and medium
CN109656791B (en) gPC performance test method and device based on Jmeter
CN109408104B (en) Method and device for acquiring game integration information
US11954013B2 (en) Method of testing applet performance, electronic device, and computer-readable medium
CN113596011B (en) Flow identification method and device, computing device and medium
CN115934179A (en) Service function control method and equipment
CN112561208B (en) Method, apparatus, electronic device and storage medium for index generation system
CN113495843A (en) Method and device for testing play-starting performance of video player
CN111538656B (en) Monitoring method, device and equipment for gradient inspection and storage medium
CN113656313A (en) Automatic test processing method and device
CN114218166A (en) Data processing method and device, electronic equipment and readable storage medium
CN113434382A (en) Database performance monitoring method and device, electronic equipment and computer readable medium
CN113568797B (en) Testing method and device of intelligent interaction system, electronic equipment and medium
EP4195052A1 (en) Systems and methods for validating a cloud-hosted application
CN112799956B (en) Asset identification capability test method, device and system device
CN116610405A (en) Method and device for controlling page state and electronic equipment
CN116545836A (en) Alarm event list processing method and device, storage medium and electronic equipment
CN116545834A (en) Method and device for troubleshooting problem of network equipment, electronic equipment and medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant