CN116775446A - Interface testing method and device - Google Patents

Interface testing method and device Download PDF

Info

Publication number
CN116775446A
CN116775446A CN202210235939.0A CN202210235939A CN116775446A CN 116775446 A CN116775446 A CN 116775446A CN 202210235939 A CN202210235939 A CN 202210235939A CN 116775446 A CN116775446 A CN 116775446A
Authority
CN
China
Prior art keywords
test case
interface
executed
case set
test
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.)
Pending
Application number
CN202210235939.0A
Other languages
Chinese (zh)
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.)
Jingdong Technology Holding Co Ltd
Original Assignee
Jingdong Technology Holding 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 Jingdong Technology Holding Co Ltd filed Critical Jingdong Technology Holding Co Ltd
Priority to CN202210235939.0A priority Critical patent/CN116775446A/en
Publication of CN116775446A publication Critical patent/CN116775446A/en
Pending legal-status Critical Current

Links

Landscapes

  • Computer And Data Communications (AREA)

Abstract

The invention discloses a method and a device for testing an interface, and relates to the technical field of testing. One embodiment of the method comprises the following steps: receiving an acquisition request of a user, wherein the acquisition request indicates a test case set to be executed; loading the test case set to be executed, and analyzing interface information corresponding to the test case set to be executed from the test case set to be executed, wherein the interface information comprises a protocol type; and calling an interface corresponding to the protocol type according to the interface information, and executing the test case set to be executed to generate a test report of the interface. The embodiment can support the automatic interface test of a plurality of test cases with different protocols, reduce the technical requirements of testers and improve the readability of the test cases.

Description

Interface testing method and device
Technical Field
The present invention relates to the field of testing technologies, and in particular, to a method and an apparatus for testing an interface.
Background
Common tools for interface testing include a web proxy type tool, an HTTP specific tool, a browser plug-in type tool, a unit test framework tool, and a test tool Jmeter supporting multiple protocols.
However, the interface testing tool only supports a few protocol interface tests, has high technical requirements for testers, has poor readability of test cases, and the like.
Disclosure of Invention
In view of this, the embodiment of the invention provides an interface testing method, which can support the testing of multiple interfaces with different protocols, reduce the technical requirements of testers, and realize the automatic testing of interfaces.
To achieve the above object, according to one aspect of the embodiments of the present invention, there is provided a method for testing an interface, including:
receiving an acquisition request of a user, wherein the acquisition request indicates a test case set to be executed;
loading the test case set to be executed, and analyzing interface information corresponding to the test case set to be executed from the test case set to be executed, wherein the interface information comprises a protocol type;
and calling an interface corresponding to the protocol type according to the interface information, and executing the test case set to be executed to generate a test report of the interface.
Optionally, before loading the test case set to be executed, the method includes:
and storing the test case set of the interface of any protocol type according to a preset test case template aiming at the interface of any protocol type.
Optionally, before loading the test case set to be executed, the method includes:
and responding to the condition that the test case set to be executed indicated by the acquisition instruction is empty, and taking all the test case sets in the configuration as the test case set to be executed.
Optionally, the preset test case template includes one or more fields of an interface method, a routing parameter, a template parameter, an assertion, and an extraction variable, and the interface information further includes one or more fields of an interface method, a routing parameter, a template parameter, an assertion, and an extraction variable, where the assertion is used to indicate an execution result of the test case in the test case set to be executed;
analyzing interface information corresponding to the test case set to be executed from the test case set to be executed, including:
and verifying the test case set to be executed, and analyzing the protocol type, the interface method, the routing parameters, the template parameters, the assertion and the extraction variables from the test case set to be executed.
Optionally, calling an interface corresponding to the protocol type according to the interface information, and before executing the test case set to be executed, including:
and in response to the execution mode of the test cases in the test case set to be executed being not sequential execution, splitting the test case set to be executed into a plurality of test case subsets to be executed, so that the plurality of test case subsets to be executed are executed according to the sequential execution mode.
Optionally, calling an interface corresponding to the protocol type according to the interface information, and executing the test case set to be executed, including:
sequentially selecting the test cases which are not executed in the test case set to be executed;
acquiring an actual value corresponding to the template parameter of the unexecuted test case;
determining the interface according to the routing parameters of the unexecuted test case;
an interface request is constructed according to the actual value and the interface method of the unexecuted test case, and the interface is called to execute the unexecuted test case;
and acquiring an interface return result corresponding to the interface request, and extracting template parameter data from the interface return result according to the extraction variable of the unexecuted test case so as to determine an actual value corresponding to the template parameter of the next unexecuted test case in the test case set to be executed.
Optionally, the template parameters include an interface entry; generating a test report of the interface, comprising:
and collecting the interface entry, the interface return result and the assertion result of the interface, and generating a test report of the interface.
According to still another aspect of an embodiment of the present invention, there is provided an apparatus for interface testing, including:
the receiving module is used for receiving an acquisition request of a user, wherein the acquisition request indicates a test case set to be executed;
the analysis module is used for loading the test case set to be executed, and analyzing interface information corresponding to the test case set to be executed from the test case set to be executed, wherein the interface information comprises a protocol type;
and the execution module is used for calling an interface corresponding to the protocol type according to the interface information, and executing the test case set to be executed so as to generate a test report of the interface.
According to another aspect of an embodiment of the present invention, there is provided an electronic apparatus including:
one or more processors;
storage means for storing one or more programs,
the one or more programs, when executed by the one or more processors, cause the one or more processors to implement the methods of interface testing provided by the present invention.
According to yet another aspect of an embodiment of the present invention, there is provided a computer readable medium having stored thereon a computer program which when executed by a processor implements the method of interface testing provided by the present invention.
One embodiment of the above invention has the following advantages or benefits: according to the interface test method provided by the embodiment of the invention, the acquisition request of the user is received, the test case set to be executed is loaded according to the test case set to be executed indicated by the acquisition request, then the interface information of the test case set to be executed is analyzed, the protocol type of the interface information can be one or more, then the interface of the corresponding protocol type can be called according to the interface information, and the test case set to be executed is executed so as to generate the test report of the interface. The interface testing method of the embodiment of the invention can support the automatic testing of interfaces with a plurality of different protocols and can reduce the code requirements of testers.
Further effects of the above-described non-conventional alternatives are described below in connection with the embodiments.
Drawings
The drawings are included to provide a better understanding of the invention and are not to be construed as unduly limiting the invention. Wherein:
FIG. 1 is a schematic diagram of the main flow of a method of interface testing according to an embodiment of the present invention;
FIG. 2 is a schematic diagram of a main flow of executing a test case set to be executed according to an embodiment of the present invention;
FIG. 3 is a schematic diagram of the main modules of an apparatus for interface testing according to an embodiment of the present invention;
FIG. 4 is a flow chart of an interface test performed by the interface test apparatus according to the embodiment of the present invention;
FIG. 5 is an exemplary system architecture diagram in which embodiments of the present invention may be applied;
fig. 6 is a schematic diagram of a computer system suitable for use in implementing an embodiment of the invention.
Detailed Description
Exemplary embodiments of the present invention will now be described with reference to the accompanying drawings, in which various details of the embodiments of the present invention are included to facilitate understanding, and are to be considered merely exemplary. Accordingly, those 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 and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
Among the commonly used interface test tools, the network proxy type tools have the following disadvantages: (1) typically only HTTP/HTTPs protocol interface testing is supported; (2) When the sequence dependency relationship exists among the request parameters of a plurality of interfaces in the interface test process, manual test can be generally only performed, and automatic test can not be realized; (3) Although the interface request and response results can be saved, the saved data is the original protocol content, the readability is poor, and the data has great difference with the general test case; (4) The support of assertions in the interface test process is limited, and it is difficult to support multiple assertions on the same interface return result. Disadvantages of HTTP specific test tools include: (1) only HTTP/HTTPs protocol interface testing is supported; (2) And the exclusive client exists, the use case data is stored in JSON, and the readability is poor. The disadvantages of browser plug-in class tools are similar to web proxy tools. Disadvantages of the unit test frame tool include: (1) The technical requirements on testers are high, and the testers are required to master the programming language of the used test frame; (2) As the scale of the system is rapidly enlarged and the business complexity is improved, when the test class of the test warehouse reaches hundreds, the readability of the test cases existing in the test codes is poor, the understanding difficulty is increased, and the maintenance cost is higher and higher; the disadvantage of the test tool Jmeter supporting multiple protocols: (1) The stored use cases need to be opened by using a Jmeter, and the readability of the text format file (XML format file) is poor; (2) the development difficulty of the private protocol expansion in the enterprise is high; (3) After the test cases are stored in the code warehouse, the change of the code after the test cases are modified cannot obviously show the change meaning of the cases. Therefore, in order to solve the above problems, the embodiment of the invention provides an interface testing method, which can support the interface testing of a plurality of different protocols, reduce the technical requirements of testers and improve the readability of test cases.
Fig. 1 is a schematic diagram of the main flow of a method for testing an interface according to an embodiment of the present invention, as shown in fig. 1, the method for testing an interface includes the following steps:
step S101: receiving an acquisition request of a user, wherein the acquisition request indicates a test case set to be executed;
step S102: loading a test case set to be executed, and analyzing interface information corresponding to the test case set to be executed from the test case set to be executed, wherein the interface information comprises a protocol type;
step S103: and calling an interface of a corresponding protocol type according to the interface information, and executing the test case set to be executed to generate a test report of the interface.
In the embodiment of the invention, the acquisition request of the user indicates the test case set to be executed, and the user can send the acquisition request in the following two ways: one way is to select a test case set to be executed by opening the device for interface test of the embodiment of the invention in a browser; the other way is to input a command of the device for interface test of the embodiment of the present invention through the shell terminal CLI (command line interface) to indicate a test case set to be executed.
In the embodiment of the invention, after the acquisition request of the user is received, the test case set to be executed can be resolved from the acquisition request. Then, judging whether the test case set to be executed is empty, if so, taking all the test case sets in the configuration as the test case set to be executed, namely, all the test cases in the current catalog (or the test case catalog configured on the web server), and then loading the test case set to be executed; if not, directly loading the test case set to be executed.
In the embodiment of the invention, loading the test case set to be executed comprises the following steps: loading the test case set to be executed into a memory; in the process, the test case set to be executed needs to be read, whether the format of the test case set to be executed is a correct format or not is checked, if yes, the test case set to be executed is directly loaded into a memory, and the success of loading is determined; if not, the loading exception is indicated, the execution is interrupted, and the failure reason is returned.
In the embodiment of the invention, the preset test case template comprises one or more fields of an interface method, a routing parameter, a template parameter, an assertion and an extraction variable, the test case set to be executed is a test case set stored according to the preset test case template, and the interface information also comprises one or more of the interface method, the routing parameter, the template parameter, the assertion and the extraction variable. Loading a test case set to be executed, and further comprising: analyzing interface information of the test case set to be executed from the test case set to be executed, wherein the interface information comprises information such as protocol types, interface methods, routing parameters, template parameters, assertion, extraction variables and the like, and the interface information is obtained from the test case set stored according to a preset test case template; the routing parameters are used for determining interfaces called by test cases, and the routing parameters can be obtained from uri (Uniform Resource Identifier ); the template parameters are parameters in a preset test case template, and the template parameters can be replaced by the actual values which can be analyzed according to the hierarchy of the test case; the assertion is used for indicating the result of the test case in the test case set to be executed and judging whether the test case is executed successfully or not, and the assertion can be realized by means of response codes, keywords, regular matching and the like; the extraction variable is a variable for extracting template parameter data from the interface return result. Such as $.data.orderid, is a variable that extracts the order number. Optionally, parsing interface information corresponding to the test case set to be executed from the test case set to be executed includes: and analyzing the protocol type, the interface method, the routing parameters, the template parameters, the assertion and the extraction variables from the test case set to be executed. The assertion can be set according to the service requirement, and multiple assertions can be performed by the same interface to return the result.
In the embodiment of the invention, before loading the test case set to be executed, the method comprises the following steps: aiming at any protocol type interface, the test case set of any protocol type interface is stored according to a preset test case template, so that when the code changes, the meaning of the test case change can be obviously seen. Optionally, a preset test case template is formulated according to the idea of 'contract greater than configuration', then a test case set of any protocol type interface is stored as a YAML format according to the preset test case template, and the test case in the YAML format can promote the readability of the test case. Alternatively, support for test cases of Excel, JSON, database, etc. types may be added.
The test case set to be executed may be one or more YAML format test case sets, such as YAML format test case sets A, B, C and D, respectively analyze interface information of each YAML format test case set, and store each test case set in a memory.
Alternatively, the protocol type may be one or more of Http/Https protocol, JSF protocol (a rpc protocol), websocket protocol, dubbo protocol (a rpc protocol), thraft protocol, protobuf protocol, JSF protocol, JMQ protocol, R2M protocol (a rpc protocol), mysql protocol, etc.; the protocol type can also be extended according to the service requirements.
The preset test case set templates may be adjusted according to different protocol types. For example, the representation format of the jsf protocol interface in the YAML test case template may be agreed, including uri (Uniform Resource Identifier ), alias, method, req, assert, vars, and other contents, where uri represents the jsf interface requested, alias is a packet where the interface is located in the jsf protocol, method is an internal method of the interface, req is a request parameter, servers is interface assertion, and vars is data that needs to be extracted and saved from the interface return result. For example, the expression format of the YAML test case template of the interface for executing the sql in the mysql database may be agreed, which includes uri, userName, passworld, method, sql, asserts, vars and other contents, where uri represents a connection string for connecting the mysql database, userName represents a user name of the database, password represents a user password of the database, method represents a method for executing the database (for example, query is a query method), sql represents an sql statement executed in the database, asserts is an interface assertion, and vars is data that needs to be extracted from the interface return result.
In the embodiment of the present invention, after analyzing interface information corresponding to a test case set to be executed from the test case set to be executed, before calling an interface of a corresponding protocol type according to the interface information to execute the test case set to be executed, the method includes: judging whether the execution mode of the test cases in the test case set to be executed is sequential execution or not, if so, selecting unexecuted test cases from the test case set to be executed according to the sequence, if not, splitting the test case set to be executed into a plurality of test case subsets to be executed aiming at the test cases to be executed in parallel, and then enabling each test case subset to be executed according to the sequence execution mode so as to realize automatic test of interfaces. Each subset of test cases to be executed may be executed as a subtask in a sequential execution manner. The test cases of the sequential execution mode are test cases with dependency relationships, and the test cases of the parallel execution mode are independent test cases without dependency relationships.
Optionally, calling an interface of a corresponding protocol type according to the interface information, and executing the test case set to be executed, including:
selecting unexecuted test cases in the test case set to be executed according to the sequence;
acquiring an actual value corresponding to a template parameter of an unexecuted test case;
determining an interface according to the routing parameters of the unexecuted test case;
constructing an interface request according to the actual value and an interface method of the unexecuted test case, and calling an interface to execute the unexecuted test case;
and acquiring an interface return result corresponding to the interface request, and extracting template parameter data from the interface return result according to the extraction variable of the unexecuted test case so as to determine an actual value corresponding to the template parameter of the next unexecuted test case in the test case set to be executed.
In the embodiment of the invention, after analyzing interface information of test cases to be executed (including interface information of each test case), executing the test cases to be executed, sequentially selecting unexecuted test cases in the set of test cases to be executed, and performing protocol routing according to the protocol types of the unexecuted test cases, namely determining the protocol instance corresponding to the unexecuted test cases, executing the unexecuted test cases by adopting the corresponding protocol instance, for example, the protocol type is jsf protocol, executing subsequent operations by the protocol instance of the processing jsf protocol, the protocol type is mysq protocol, and executing subsequent operations by the protocol instance of the processing mysql protocol; the protocol type is an http protocol, and subsequent operations can be executed by a protocol instance for processing the http protocol; the protocol type is an R2M protocol, and subsequent operations may be performed by a protocol instance that processes the R2M protocol.
After determining the protocol instance of the test case which is not executed, the actual value of the template parameter is obtained, namely, the template parameter in the preset test case is replaced by the actual value, and the actual value can be obtained from the context of the test case which is not executed. For example, the parameters in the test case that are not executed are an sql statement that includes template parameters: SELECT = '$ { context. Ordeid }', the actual value of $ { context. Ordeid } required to be parsed according to the hierarchy of the current test case is JDZF2021091201, and the actual sql statement in the subsequent interface invocation process is: SELECT FROM lan_0000 where orderid= 'JDZF2021091201'. Also for example, the request parameter in the test case is a JSON object including a template parameter: { pin: 'baitiao_user', amount: '$ { context. Amount }', channel: 'RepayPage' }, the actual value of $ { context. Amountj } is 200, and the following interface parameters are: { pin: 'baitiao_user', amounto: '200', channel: 'RepayPage' }.
Then, according to the routing parameters, the interface routing is carried out, namely, the called interface is determined, and the interface method of the test case which is not executed can be determined through analysis; the interface route can facilitate separation of interface methods, interface entry, and the like. For example, the interface method may be obtained by parsing uri of the test case not executed. And then, according to the determined actual value and the interface method, constructing an interface request, calling an interface, executing the unexecuted test case, acquiring an interface return result, and according to the extracted variable, acquiring template parameter data from the interface return result, wherein the template parameter data can be returned to serve as the actual value of the next unexecuted test case, so that the execution of the next unexecuted test case is realized. That is, for multiple interfaces that have sequential dependencies, some of the data in the interface return results need to be saved for use in the replacement process of the template parameters of the subsequent interfaces. For example, if the interface returns the result: { "code": "SUCCESS", "info": "SUCCESS", "SUCCESS": true ":" data "{" orderId ":"31144164012865"," amount ":68}, template parameter data" 31144164012865 "is extracted according to the extraction variable, and then the orderId is saved to context.
In the embodiment of the invention, the template parameters comprise interface entry parameters; generating a test report of the interface, comprising: collecting interface parameter entering, interface returning results and interface assertion results, and generating a test report of the interface. After the interface is tested, the test condition of the interface can be obtained through the generated test report of the interface. The test report of the interface includes the interface entry, the interface return result, and the interface assertion result.
FIG. 2 is a schematic flow chart of a method for executing a test case set to be executed according to an embodiment of the present invention, including:
step S201: sequentially selecting an i-th unexecuted test case in the test case set to be executed, wherein i=1;
step S202: acquiring an actual value of a template parameter of an i-th unexecuted test case;
step S203: determining an interface according to the routing parameters of the i-th unexecuted test case;
step S204: constructing an interface request according to the actual value and an interface method of the i-th unexecuted test case, and calling an interface to execute the i-th unexecuted test case;
step S205: acquiring an interface return result corresponding to the interface request;
step S206: extracting template parameter data from a return result of the interface according to the extraction variable to determine an actual value of the (i+1) th unexecuted test case;
step S207: judging whether the number of the test cases which are not executed in the test case set to be executed is greater than 0, if so, jumping to the step S201 by i=i+1, and if not, executing the step S208;
step S208: and collecting interface entering results, interface returning results and interface assertion results of each test case so as to generate an interface test report.
According to the interface test method provided by the embodiment of the invention, the acquisition request of the user is received, the test case set to be executed is loaded according to the test case set to be executed indicated by the acquisition request, then the interface information of the test case set to be executed is analyzed, the protocol type of the interface information can be one or more, then the interface of the corresponding protocol type can be called according to the interface information, and the test case set to be executed is executed so as to generate the test report of the interface. The interface testing method of the embodiment of the invention can support the testing of interfaces of various different protocols, can reduce the code requirement of testers, adopts a better preset test case template with readability, such as a YAML format test case, and can improve the readability of the test case. In addition, when the sequence dependency relationship exists among the request parameters of the interfaces, the method can realize the automatic test of the interfaces in a mode of sequence execution and a mode of extracting template parameter data; in addition, the test case set of the embodiment of the invention adopts a preset test case template, and the meaning of the test case change can be obviously seen after the code is modified; and a plurality of assertions can be added in a preset test case template according to service requirements, and the assertions can be realized by returning results to the same interface.
As shown in fig. 3, another aspect of the embodiment of the present invention provides an apparatus 300 for interface testing, including:
the receiving module 301 receives an acquisition request of a user, wherein the acquisition request indicates a test case set to be executed;
the analysis module 302 loads a test case set to be executed, analyzes interface information corresponding to the test case set to be executed from the test case set to be executed, wherein the interface information comprises a protocol type;
and the execution module 303 calls an interface of a corresponding protocol type according to the interface information, and executes the test case set to be executed to generate a test report of the interface.
In the embodiment of the present invention, the parsing module 302 is further configured to: before loading the test case set to be executed, storing the test case set of the interface of any protocol type according to a preset test case template aiming at the interface of any protocol type.
In the embodiment of the present invention, the parsing module 302 is further configured to: before loading the test case set to be executed, responding to the condition that the test case set to be executed indicated by the acquisition request is empty, and taking all the test case sets in the configuration as the test case set to be executed.
In the embodiment of the invention, the preset test case template comprises one or more fields of an interface method, a routing parameter, a template parameter, an assertion and an extraction variable, and the interface information also comprises one or more of the interface method, the routing parameter, the template parameter, the assertion and the extraction variable, wherein the assertion is used for indicating the execution result of the test case in the test case set to be executed; the parsing module 302 is further configured to: and verifying the test case set to be executed, and analyzing the protocol type, the interface method, the routing parameters, the template parameters, the assertion and the extraction variables from the test case set to be executed.
In an embodiment of the present invention, the execution module 303 is further configured to: before calling an interface of a corresponding protocol type according to interface information and executing the test case set to be executed, splitting the test case set to be executed into a plurality of test case subsets to be executed in response to the fact that the execution mode of the test cases in the test case set to be executed is not sequential execution, so that the plurality of test case subsets to be executed are executed according to the sequential execution mode.
In an embodiment of the present invention, the execution module 303 is further configured to: selecting unexecuted test cases in the test case set to be executed according to the sequence; acquiring an actual value corresponding to a template parameter of an unexecuted test case; determining an interface according to the routing parameters of the unexecuted test case; constructing an interface request according to the actual value and an interface method of the unexecuted test case, and calling an interface to execute the unexecuted test case; and acquiring an interface return result corresponding to the interface request, and extracting template parameter data from the interface return result according to the extraction variable of the unexecuted test case so as to determine an actual value corresponding to the template parameter of the next unexecuted test case in the test case set to be executed.
In the embodiment of the invention, the template parameters comprise interface entry parameters; an execution module 303, further configured to: collecting interface parameter entering, interface returning results and interface assertion results, and generating a test report of the interface.
Fig. 4 is a schematic flow chart of an interface test performed by using the device for interface test according to the embodiment of the present invention, a user may select a set of test cases to be executed, where the set of test cases to be executed is a YAML format test case set, and the device for interface test may be a YAML interface automation test tool. The user can open a YMAL test tool page on a browser Web Server, can input YAML test tool commands through a shell terminal CLI, sends an acquisition request, the acquisition request indicates a test case set to be executed, the YAML test tool receives the acquisition request and analyzes the test case set to be executed, then judges whether the test case set to be executed is empty, if so, all the test cases are set as the test case set to be executed, if not, the test case set to be executed is loaded, interface information in the test case set to be executed is analyzed, in the loading process, whether the loading is successful needs to be judged, if the loading is unsuccessful, abnormality is indicated, and the flow is ended; and if the loading is successful, calling an interface of a corresponding protocol according to the interface information, executing the test case set to be executed, then generating a test report of the interface, and ending the flow. The interface testing device provided by the embodiment of the invention realizes the passing test of interfaces supporting a plurality of different protocols, improves the readability of test cases and reduces the technical requirements on testers.
Fig. 5 illustrates an exemplary system architecture 500 of a method of interface testing or an apparatus of interface testing to which embodiments of the present invention may be applied.
As shown in fig. 5, the system architecture 500 may include terminal devices 501, 502, 503, a network 504, and a server 505. The network 504 is used as a medium to provide communication links between the terminal devices 501, 502, 503 and the server 505. The network 504 may include various connection types, such as wired, wireless communication links, or fiber optic cables, among others.
A user may interact with the server 505 via the network 504 using the terminal devices 501, 502, 503 to receive or send messages or the like. Various communication client applications may be installed on the terminal devices 501, 502, 503, such as a software test class application, a web browser application, a search class application, an instant messaging tool, a mailbox client, social platform software, etc. (as examples only).
The terminal devices 501, 502, 503 may be a variety of electronic devices having a display screen and supporting web browsing, including but not limited to smartphones, tablets, laptop and desktop computers, and the like.
The server 505 may be a server providing various services, such as a test server (by way of example only) providing support for software test class applications browsed by a user using the terminal devices 501, 502, 503. The test server may analyze and/or the like the received data such as the interface test request and feed back the processing result (e.g., interface test report—only an example) to the terminal device.
It should be noted that, the method for testing an interface according to the embodiment of the present invention is generally executed by the server 505, and accordingly, the device for testing an interface is generally disposed in the server 505.
It should be understood that the number of terminal devices, networks and servers in fig. 5 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
Referring now to FIG. 6, there is illustrated a schematic diagram of a computer system 600 suitable for use in implementing an embodiment of the present invention. The terminal device shown in fig. 6 is only an example, and should not impose any limitation on the functions and the scope of use of the embodiment of the present invention.
As shown in fig. 6, the computer system 600 includes a Central Processing Unit (CPU) 601, which can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM) 602 or a program loaded from a storage section 608 into a Random Access Memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the system 600 are also stored. The CPU 601, ROM 602, and RAM 603 are connected to each other through a bus 604. An input/output (I/O) interface 605 is also connected to bus 604.
The following components are connected to the I/O interface 605: an input portion 606 including a keyboard, mouse, etc.; an output portion 607 including a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, a speaker, and the like; a storage section 608 including a hard disk and the like; and a communication section 609 including a network interface card such as a LAN card, a modem, or the like. The communication section 609 performs communication processing via a network such as the internet. The drive 610 is also connected to the I/O interface 605 as needed. Removable media 611 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is installed as needed on drive 610 so that a computer program read therefrom is installed as needed into storage section 608.
In particular, according to embodiments of the present disclosure, the processes described above with reference to flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method shown in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication portion 609, and/or installed from the removable medium 611. The above-described functions defined in the system of the present invention are performed when the computer program is executed by a Central Processing Unit (CPU) 601.
The computer readable medium shown in the present invention may be a computer readable signal medium or a computer readable storage medium, or any combination of the two. The computer readable storage medium can be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or a combination of any of the foregoing. More specific examples of the computer-readable storage medium may include, but are not limited to: an electrical connection having 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. In the context of this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In the present invention, however, the computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, with the computer-readable program code embodied therein. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination of the foregoing. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
The flowcharts and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The modules involved in the embodiments of the present invention may be implemented in software or in hardware. The described modules may also be provided in a processor, for example, as: a processor includes a receiving module, a parsing module, and an executing module. The names of these modules do not constitute a limitation on the module itself in some cases, and for example, the receiving module may also be described as "a module that receives an acquisition request of a user".
As another aspect, the present invention also provides a computer-readable medium that may be contained in the apparatus described in the above embodiments; or may be present alone without being fitted into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to include: receiving an acquisition request of a user, wherein the acquisition request indicates a test case set to be executed; loading a test case set to be executed, and analyzing interface information corresponding to the test case set to be executed from the test case set to be executed, wherein the interface information comprises a protocol type; and calling an interface of a corresponding protocol type according to the interface information, and executing the test case set to be executed to generate a test report of the interface.
According to the technical scheme of the embodiment of the invention, the to-be-executed test case set is loaded according to the to-be-executed test case set indicated by the acquisition request by receiving the acquisition request of the user, then the interface information of the to-be-executed test case set is analyzed, the protocol type of the interface information can be one or more, then the interface of the corresponding protocol type can be called according to the interface information, and the to-be-executed test case set is executed to generate the test report of the interface. The interface testing method of the embodiment of the invention can support the testing of interfaces of various different protocols, can reduce the code requirement of testers, adopts a better preset test case template with readability, such as a YAML format test case, and can improve the readability of the test case. In addition, when the sequence dependency relationship exists among the request parameters of the interfaces, the method can realize the automatic test of the interfaces in a mode of sequence execution and a mode of extracting template parameter data; in addition, the test case set of the embodiment of the invention adopts a preset test case template, and the meaning of the test case change can be obviously seen after the code is modified; and a plurality of assertions can be added in a preset test case template according to service requirements, and the assertions can be realized by returning results to the same interface.
The above embodiments do not limit the scope of the present invention. It will be apparent to those skilled in the art that various modifications, combinations, sub-combinations and alternatives can occur depending upon design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the scope of the present invention.

Claims (10)

1. A method of interface testing, comprising:
receiving an acquisition request of a user, wherein the acquisition request indicates a test case set to be executed;
loading the test case set to be executed, and analyzing interface information corresponding to the test case set to be executed from the test case set to be executed, wherein the interface information comprises a protocol type;
and calling an interface corresponding to the protocol type according to the interface information, and executing the test case set to be executed to generate a test report of the interface.
2. The method of claim 1, comprising, prior to loading the test case set to be executed:
and storing the test case set of the interface of any protocol type according to a preset test case template aiming at the interface of any protocol type.
3. The method of claim 1, comprising, prior to loading the test case set to be executed:
and responding to the acquisition request indicating that the test case set to be executed is empty, and taking all the test case sets in the configuration as the test case set to be executed.
4. The method of claim 2, wherein the preset test case template includes one or more fields of an interface method, a routing parameter, a template parameter, an assertion, and an extraction variable, and the interface information further includes one or more of an interface method, a routing parameter, a template parameter, an assertion, and an extraction variable, where the assertion is used to indicate an execution result of the test case in the test case set to be executed;
analyzing interface information corresponding to the test case set to be executed from the test case set to be executed, including:
and verifying the test case set to be executed, and analyzing the protocol type, the interface method, the routing parameters, the template parameters, the assertion and the extraction variables from the test case set to be executed.
5. The method of claim 1, wherein invoking the interface corresponding to the protocol type according to the interface information, before executing the test case set to be executed, comprises:
and in response to the execution mode of the test cases in the test case set to be executed being not sequential execution, splitting the test case set to be executed into a plurality of test case subsets to be executed, so that the plurality of test case subsets to be executed are executed according to the sequential execution mode.
6. The method of claim 4, wherein invoking the interface corresponding to the protocol type according to the interface information, executing the test case set to be executed, comprises:
sequentially selecting the test cases which are not executed in the test case set to be executed;
acquiring an actual value corresponding to the template parameter of the unexecuted test case;
determining the interface according to the routing parameters of the unexecuted test case;
an interface request is constructed according to the actual value and the interface method of the unexecuted test case, and the interface is called to execute the unexecuted test case;
and acquiring an interface return result corresponding to the interface request, and extracting template parameter data from the interface return result according to the extraction variable of the unexecuted test case so as to determine an actual value corresponding to the template parameter of the next unexecuted test case in the test case set to be executed.
7. The method of claim 6, wherein the template parameters include an interface entry; generating a test report of the interface, comprising:
and collecting the interface entry, the interface return result and the assertion result of the interface, and generating a test report of the interface.
8. An apparatus for interface testing, comprising:
the receiving module is used for receiving an acquisition request of a user, wherein the acquisition request indicates a test case set to be executed;
the analysis module is used for loading the test case set to be executed, and analyzing interface information corresponding to the test case set to be executed from the test case set to be executed, wherein the interface information comprises a protocol type;
and the execution module is used for calling an interface corresponding to the protocol type according to the interface information, and executing the test case set to be executed so as to generate a test report of the interface.
9. An electronic device, comprising:
one or more processors;
storage means for storing one or more programs,
when executed by the one or more processors, causes the one or more processors to implement the method of any of claims 1-7.
10. A computer readable medium, on which a computer program is stored, characterized in that the program, when being executed by a processor, implements the method according to any of claims 1-7.
CN202210235939.0A 2022-03-11 2022-03-11 Interface testing method and device Pending CN116775446A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210235939.0A CN116775446A (en) 2022-03-11 2022-03-11 Interface testing method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210235939.0A CN116775446A (en) 2022-03-11 2022-03-11 Interface testing method and device

Publications (1)

Publication Number Publication Date
CN116775446A true CN116775446A (en) 2023-09-19

Family

ID=88008669

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210235939.0A Pending CN116775446A (en) 2022-03-11 2022-03-11 Interface testing method and device

Country Status (1)

Country Link
CN (1) CN116775446A (en)

Similar Documents

Publication Publication Date Title
CN109815107B (en) Method and device for automatic testing
CN109359194B (en) Method and apparatus for predicting information categories
CN110798445B (en) Public gateway interface testing method and device, computer equipment and storage medium
CN110795147A (en) Interface protocol file management method and device
CN111125064B (en) Method and device for generating database schema definition statement
CN113760729A (en) Code detection method and device
CN108694120B (en) Method and device for testing service component
CN111427899A (en) Method, device, equipment and computer readable medium for storing file
CN112947919A (en) Method and device for constructing service model and processing service request
CN112559024A (en) Method and device for generating transaction code change list
CN110825622A (en) Software testing method, device, equipment and computer readable medium
CN113127335A (en) System testing method and device
CN110764769A (en) Method and device for processing user request
CN116204428A (en) Test case generation method and device
CN113515306B (en) System transplanting method and device
CN110806967A (en) Unit testing method and device
CN116775446A (en) Interface testing method and device
CN115291928A (en) Task automatic integration method and device of multiple technology stacks and electronic equipment
CN110909269B (en) Log reporting method and device
CN113779018A (en) Data processing method and device
CN112433752A (en) Page parsing method, device, medium and electronic equipment
CN113268417B (en) Task execution method and device
CN112860538A (en) Method and device for performing interface regression test based on online log
CN112579428A (en) Interface testing method and device, electronic equipment and storage medium
CN110858240A (en) Front-end module loading method and device

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