A method and device for automatically generating test scripts

By generating and traversing the front-wheel binary search tree, the interface test scripts are automatically generated, which solves the time-consuming and labor-intensive problem of manual generation of scripts in the existing technology, and achieves fast and efficient test script generation.

CN111026629BActive Publication Date: 2025-04-18BEIJING JINGDONG SHANGKE INFORMATION TECH CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN201811171370.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2018-10-09
Publication Date
2025-04-18
Estimated Expiration
2038-10-09

AI Technical Summary

Technical Problem

In the prior art, the generation of interface test scripts depends on manual labor, which makes generation time-consuming, labor-intensive and inefficient.

Method used

By obtaining the predecessor binary search tree generated based on the parameters of the interface to be tested, traverse the tree, obtain the incoming parameters of the interface to be tested, and generate its calling statements, and finally generate a test script.

Benefits of technology

It realizes the rapid generation of test scripts, improves testing efficiency, and ensures the correctness of the logic of automated test scripts.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN111026629B_ABST
    Figure CN111026629B_ABST
Patent Text Reader

Abstract

The present invention discloses a method and device for automatically generating a test script, and relates to the field of computer technology. A specific implementation of the method includes: obtaining a predecessor binary search tree generated according to the parameters of the interface under test to traverse the predecessor binary search tree; obtaining the input parameters of the interface under test according to the traversed parameters to generate a call statement of the interface under test; and generating a test script of the interface under test according to the input parameters of the interface under test and the call statement of the interface under test. This implementation can solve the problem that the prior art cannot automatically generate an interface test script.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a method and device for automatically generating a test script. Background Art

[0002] With the continuous development of automated testing technology, interface automation technology has become an indispensable detection method in the testing life cycle of any information system. At present, in various interface testing frameworks, all workflow testers write test scripts, design parameter pools, and run test scripts for testing according to the specifications of the test framework. In the workflow of the above automated interface test scripts, due to the rapid update and iteration of the tested interface, the maintenance of the test scripts has become a constraint that affects the quality of all interface automated testing.

[0003] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art:

[0004] At present, interface test scripts still rely entirely on testers to manually generate them according to the test framework, so the generation of test scripts is time-consuming, labor-intensive and inefficient. Summary of the invention

[0005] In view of this, an embodiment of the present invention provides a method and device for automatically generating a test script, which can solve the problem that the prior art cannot automatically generate an interface test script.

[0006] To achieve the above-mentioned purpose, according to one aspect of an embodiment of the present invention, a method for automatically generating a test script is provided, comprising obtaining a predecessor binary search tree generated according to parameters of the interface under test to traverse the predecessor binary search tree; obtaining input parameters of the interface under test according to the traversed parameters to generate a calling statement of the interface under test; and generating a test script of the interface under test according to the input parameters of the interface under test and the calling statement of the interface under test.

[0007] Optionally, obtaining a predecessor binary search tree generated according to the measured interface parameters includes:

[0008] Define the storage structure of the predecessor binary search tree;

[0009] The parameters of the interface under test are read, and a predecessor binary search tree is generated according to the storage structure.

[0010] Optionally, traversing the predecessor binary search tree includes:

[0011] According to the parameter sequence preset by the interface under test, the predecessor binary search tree is traversed and stored.

[0012] Optionally, according to the traversed parameters, the input parameters of the tested interface are obtained to generate a call statement of the tested interface, including:

[0013] Read the traversed parameters based on the logical rule of initializing basic types first and then initializing complex types;

[0014] Get the input parameters of the interface under test, and then generate the calling statement of the interface under test.

[0015] In addition, according to one aspect of an embodiment of the present invention, a device for automatically generating a test script is provided, including an acquisition module for acquiring a predecessor binary search tree generated according to the parameters of the interface under test to traverse the predecessor binary search tree; a traversal module for obtaining the input parameters of the interface under test according to the traversed parameters to generate a calling statement of the interface under test; and a generation module for generating a test script of the interface under test according to the input parameters of the interface under test and the calling statement of the interface under test.

[0016] Optionally, the acquisition module acquires a predecessor binary search tree generated according to the measured interface parameters, including:

[0017] Define the storage structure of the predecessor binary search tree;

[0018] The parameters of the interface under test are read, and a predecessor binary search tree is generated according to the storage structure.

[0019] Optionally, the traversal module traverses the predecessor binary search tree, including:

[0020] According to the parameter sequence preset by the interface under test, the predecessor binary search tree is traversed and stored.

[0021] Optionally, the generation module obtains input parameters of the tested interface according to the traversed parameters to generate a call statement of the tested interface, including:

[0022] Read the traversed parameters based on the logical rule of initializing basic types first and then initializing complex types;

[0023] Get the input parameters of the tested interface, and then generate the call statement of the tested interface

[0024] According to another aspect of an embodiment of the present invention, there is further provided an electronic device, including:

[0025] one or more processors;

[0026] a storage device for storing one or more programs,

[0027] When the one or more programs are executed by the one or more processors, the one or more processors implement the method described in any of the above embodiments for automatically generating a test script.

[0028] According to another aspect of an embodiment of the present invention, a computer-readable medium is provided, on which a computer program is stored. When the program is executed by a processor, the method described in any of the above embodiments based on automatic generation of test scripts is implemented.

[0029] One embodiment of the above invention has the following advantages or beneficial effects: the present invention obtains a predecessor binary search tree generated according to the parameters of the interface under test to traverse the predecessor binary search tree; obtains the input parameters of the interface under test according to the traversed parameters to generate a call statement of the interface under test; generates a test script of the interface under test according to the input parameters of the interface under test and the call statement of the interface under test. Therefore, the present invention proposes a storage structure based on the predecessor binary search tree and its corresponding traversal algorithm to solve the problem of automatic generation of test scripts, and achieves the purpose of quickly generating scripts and quickly conducting tests.

[0030] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS

[0031] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.

[0032] Figure 1 is a schematic diagram of the main process of the method for automatically generating a test script according to an embodiment of the present invention;

[0033] Figure 2 is a schematic diagram of the main process of a method for automatically generating a test script according to a reference embodiment of the present invention;

[0034] Figure 3 is a schematic diagram of the main process of generating a predecessor binary search tree according to a reference embodiment of the present invention;

[0035] Figure 4 It is a schematic diagram of the main process of generating a predecessor binary search tree subtree according to a reference embodiment of the present invention;

[0036] Figure 5 is a schematic diagram of main modules of an apparatus for automatically generating test scripts according to an embodiment of the present invention;

[0037] Figure 6 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;

[0038] Figure 7 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION

[0039] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.

[0040] Figure 1 is a schematic diagram of the main process of a method for automatically generating a test script according to an embodiment of the present invention. The method for automatically generating a test script may include:

[0041] Step S101, obtaining a predecessor binary search tree generated according to the interface parameters under test, to traverse the predecessor binary search tree.

[0042] In an embodiment, the predecessor binary search tree generated according to the measured interface parameters can be obtained through the following process:

[0043] First, define the storage structure of the predecessor binary search tree, then read the parameters of the interface under test, and generate the predecessor binary search tree according to the storage structure. The binary search tree refers to a tree structure in which each node has at most two subtrees. The predecessor means that each node has a pointer to its parent node.

[0044] In a preferred embodiment, the predecessor binary search tree can be traversed in order to store the traversed parameters in sequence. The in-order traversal of the binary search tree means traversing the left subtree first, then traversing the root node, and finally traversing the right subtree. It is worth noting that no matter whether the in-order traversal, pre-order traversal, post-order traversal or other traversal methods are used, the purpose is to ensure that the order of parameters obtained after the traversal can meet the parameter order specified when the interface under test is developed.

[0045] In addition, the predecessor binary search tree can be traversed in order to store the traversed parameters in the Map class in sequence. The Map class is a container for storing a number of elements, which are composed of key values ​​(Key, Value) and mapped values ​​(Mapped Value) pairs. It is worth noting that by storing the traversed parameters in the Map class with key-value pair rules, the traversed parameters can be sorted more accurately and effectively, and of course they can also be stored in any other form.

[0046] Step S102, obtaining the input parameters of the tested interface according to the traversed parameters to generate a calling statement of the tested interface.

[0047] In an embodiment, the Map class can be traversed based on the logic rule of initializing the basic type first and then the complex type. Then, according to the parameters obtained after traversing the Map class, the input parameters of the tested interface are obtained, and then the call statement of the tested interface is generated.

[0048] Step S103, generating a test script for the interface under test according to the input parameters of the interface under test and the calling statement of the interface under test.

[0049] According to the various embodiments described above, the present invention solves the analysis of the call structure of the tested interface through the storage structure of the predecessor binary search tree, and then completes the automatic generation of the interface automation test script and the test parameter file through the in-order traversal of the binary search tree. In other words, the present invention can quickly complete the automation test script of the tested interface, saving a lot of time. In addition, the present invention is completely modified into a script based on the call relationship tree of the tested interface, thereby ensuring the correctness of the logic of the automation test script.

[0050] Figure 2 1 is a schematic diagram of the main process of a method for automatically generating a test script according to a reference embodiment of the present invention. The method for automatically generating a test script may include:

[0051] Step S201, defining the storage structure of the predecessor binary search tree.

[0052] In an embodiment, the storage structure of the defined predecessor binary search tree may be:

[0053] Name Type Leftchild Rightchild Father

[0054] Among them, if it is the storage of the root node of the predecessor binary search tree, Name indicates that the field stores the interface name of the tested interface; Type indicates that the field stores the return value type; Leftchlid points to the first basic type node of the first tested interface input parameter, if not, it is null; Rightchlid points to the first load type node of the first tested interface, if not, it is null; and Father (parent node) is null.

[0055] Among them, if it is the storage of the basic type parameter of the predecessor binary search tree, Name represents the storage variable name; Type represents the storage traversal type; Leftchild points to the basic type node in the same-level call; Rightchlid is null; Father points to the previous node of the same-level call or to the Node node of its complex type parent node. If it is the second-level node of the binary tree, it points to the root node.

[0056] Among them, if it is the storage of complex object nodes of the predecessor binary search tree, it can include the storage of Java object type parameters, the storage of Map type parameters and the storage of List type parameters, and the specific definitions are:

[0057] To store Java object type parameters, two new type nodes need to be created: Java object node and Java object node. The details are as follows:

[0058] For Java object nodes, Name represents the name of the storage object variable; Type represents the storage Java object; Leftchild points to its corresponding object Node node; Rightchlid points to the complex object node at the same level; Father points to the previous node called at the same level or to the node of the parent node of its complex type. If it is the second-level node of the binary tree, it points to the root node.

[0059] For the object Node, Name is represented by storing null; Type is represented by storing null; Leftchild points to the first basic type node nested in it, or null if there is none; Rightchlid points to the first complex object node nested in it, or null if there is none; Father points to its corresponding Java object node.

[0060] To store Map type parameters, two new nodes are needed: Map type node and Map type node. The details are as follows:

[0061] For Map type nodes, Name represents the name of the storage object variable; Type represents the storage Map tag; Leftchild points to its corresponding Map type Node node; Rightchlid points to the complex object node at the same level; Father points to the previous node called at the same level or to the parent node of its complex type. If the node is the second-level node of the binary tree, it points to the root node.

[0062] For Map type Node nodes, Name is represented by storing null; Type is represented by storing null; Leftchild points to its first key node, and the key is processed according to the specific type; Rightchlid points to the first value node, and the value node is processed according to the specific type; Father points to its corresponding Map type node.

[0063] To store List type parameters, two new nodes are needed: List type node and List type node. The details are as follows:

[0064] For List type nodes, Name represents the name of the storage object variable; Type represents the storage Map tag; Leftchild points to its corresponding List type Node node; Rightchlid points to the complex object node at the same level; Father points to the previous node called at the same level or to the parent node of its complex type. If the node is the second-level node of the binary tree, it points to the root node.

[0065] For List type Node nodes, Name is represented by storing null; Type is represented by storing null; Leftchild is represented by if the List is a basic type, then Leftchlid points to its corresponding basic type node, and Rightchlid is null; Rightchlid is represented by if the List is a complex type, then Rightchlid points to its corresponding complex type node, and Leftchild is null; Father points to its corresponding List type node.

[0066] Step S202, generate a predecessor binary search tree. Figure 3 As shown in the figure, the specific implementation process includes:

[0067] Step S301: Establish a root node.

[0068] Step S302: Set the flag i of the current node.

[0069] Step S303: Determine whether the flag i of the current node is less than the number of parameters. If so, proceed to step S304; otherwise, exit the process.

[0070] Step S304: Obtain the i-th parameter node.

[0071] Step S305: Determine whether the i-th parameter node is a basic type, if so, proceed to step S306, otherwise proceed to step S307.

[0072] Step 306: The left child of the i-th parameter node points to the new node, and i is reassigned to i by incrementing i, and the process returns to step S303.

[0073] Step S307: Generate a subtree according to the i-th parameter node.

[0074] In a further embodiment, Figure 4 As shown, the process of generating a subtree according to the i-th parameter node includes:

[0075] Step S401: Create a node of a complex object according to the flag i of the parameter node.

[0076] Step S402: Determine whether the flag i of the parameter node is less than the number of node attributes. If so, proceed to step S403; otherwise, exit the process.

[0077] Step S403: create a new attribute node of node i.

[0078] Step S404: Determine whether the i-th attribute node is a basic type, if so, proceed to step S405, otherwise return to step S401.

[0079] Step S405: The left child of the i-th attribute node points to the new node, and the value i is incremented and reassigned to i, and the process returns to step S402.

[0080] Step S203, perform an in-order traversal on the predecessor binary search tree, and store the traversal parameters in the Map class in sequence.

[0081] In an embodiment, when the predecessor binary search tree is traversed in order, the left subtree is traversed first, then the root node is traversed, and finally the right subtree is traversed. During the traversal process, the traversed parameters are sequentially stored in the Map class, so that the calling relationship between the parameters can be obtained.

[0082] Step S204, traversing the Map class to obtain the input parameters of the tested interface, and then generating a call statement of the tested interface.

[0083] In the embodiment, when traversing the Map class, the logic rule of initializing the basic type first and then initializing the complex type can be adopted. Further, according to the traversal of the Map class, the input parameters of the tested interface can be obtained, thereby obtaining the call statement of the tested interface.

[0084] Step S205, generating a test script for the interface under test according to the input parameters of the interface under test and the calling statement of the interface under test.

[0085] Figure 5 is a device for automatically generating a test script according to an embodiment of the present invention, such as Figure 5 As shown, the device for automatically generating a test script includes an acquisition module 501, a traversal module 502 and a generation module 503. Among them, the acquisition module 501 acquires a predecessor binary search tree generated according to the parameters of the interface under test to traverse the predecessor binary search tree. The traversal module 502 obtains the input parameters of the interface under test according to the traversed parameters to generate a call statement of the interface under test. The generation module 503 generates a test script of the interface under test according to the input parameters of the interface under test and the call statement of the interface under test.

[0086] Preferably, when acquiring the predecessor binary search tree generated according to the measured interface parameters, the acquisition module 501 may first define a storage structure of the predecessor binary search tree, and then read the parameters of the measured interface to generate the predecessor binary search tree according to the storage structure.

[0087] As another embodiment, when traversing the predecessor binary search tree, the traversal module 502 may use an in-order traversal on the predecessor binary search tree, and store the traversed parameters in the Map class in sequence. Further, the generation module 503 obtains the input parameters of the tested interface according to the parameters obtained after traversing the Map class to generate a call statement of the tested interface.

[0088] Furthermore, the generation module 503 traverses the Map class using a logic rule based on initializing basic types first and then initializing complex types, and then obtains the input parameters of the tested interface based on the parameters obtained after traversing the Map class, and then generates a call statement for the tested interface.

[0089] It should be noted that the specific implementation content of the device for automatically generating test scripts in the present invention has been described in detail in the method for automatically generating test scripts described above, so the repeated content will not be described here.

[0090] Figure 6 An exemplary system architecture 600 is shown to which the method or apparatus for automatically generating a test script according to an embodiment of the present invention may be applied.

[0091] like Figure 6 As shown, system architecture 600 may include terminal devices 601, 602, 603, network 604 and server 605. Network 604 is used to provide a medium for communication links between terminal devices 601, 602, 603 and server 605. Network 604 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.

[0092] Users can use terminal devices 601, 602, and 603 to interact with server 605 through network 604 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 601, 602, and 603, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc. (only examples).

[0093] The terminal devices 601 , 602 , and 603 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers, etc.

[0094] The server 605 may be a server that provides various services, such as a backend management server (only an example) that provides support for shopping websites browsed by users using the terminal devices 601, 602, and 603. The backend management server may analyze and process the received data such as product information query requests, and feed back the processing results (such as target push information, product information - only an example) to the terminal device.

[0095] It should be noted that the method for automatically generating a test script provided in the embodiment of the present invention is generally executed by the server 605 , and accordingly, the device for automatically generating a test script is generally set in the server 605 .

[0096] It should be understood that Figure 6 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to the implementation requirements.

[0097] Reference below Figure 7 , which shows a schematic diagram of the structure of a computer system 700 of a terminal device suitable for implementing an embodiment of the present invention. Figure 7 The terminal device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.

[0098] like Figure 7 As shown, the computer system 700 includes a central processing unit (CPU) 701, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 702 or a program loaded from a storage part 708 into a random access memory (RAM) 703. In the RAM 703, various programs and data required for the operation of the system 700 are also stored. The CPU 701, the ROM 702, and the RAM 703 are connected to each other via a bus 704. An input / output (I / O) interface 705 is also connected to the bus 704.

[0099] The following components are connected to the I / O interface 705: an input section 706 including a keyboard, a mouse, etc.; an output section 707 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 708 including a hard disk, etc.; and a communication section 709 including a network interface card such as a LAN card, a modem, etc. The communication section 709 performs communication processing via a network such as the Internet. A drive 710 is also connected to the I / O interface 705 as needed. A removable medium 711, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 710 as needed, so that a computer program read therefrom is installed into the storage section 708 as needed.

[0100] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 709, and / or installed from the removable medium 711. When the computer program is executed by the central processing unit (CPU) 701, the above-mentioned functions defined in the system of the present invention are executed.

[0101] It should be noted that 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 above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, 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 disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.

[0102] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0103] The modules involved in the embodiments of the present invention may be implemented in software or hardware. The modules described may also be set in a processor, for example, it may be described as: a processor includes an acquisition module, a traversal module and a generation module. The names of these modules do not, in some cases, constitute limitations on the modules themselves.

[0104] As another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiment; or it may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device includes: obtaining a predecessor binary search tree generated according to the parameters of the interface under test to traverse the predecessor binary search tree; obtaining the input parameters of the interface under test according to the traversed parameters to generate a call statement of the interface under test; generating a test script of the interface under test according to the input parameters of the interface under test and the call statement of the interface under test.

[0105] The technical solution according to the embodiment of the present invention can solve the problem that the prior art cannot automatically generate interface test scripts.

[0106] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A method for automatically generating a test script, characterized in that: include: Obtain a predecessor binary search tree generated according to the interface parameters under test to traverse the predecessor binary search tree; wherein the process of generating the predecessor binary search tree includes: establishing a root node; setting a flag i of the current node; judging whether the flag i of the current node is less than the number of parameters, if so, obtaining the i-th parameter node, otherwise exiting the process; judging whether the i-th parameter node is a basic type, if so, the left child of the i-th parameter node points to a new node, and i is reassigned to i by self-increment, and the judgment logic is re-executed; otherwise, generating a subtree according to the i-th parameter node; The process of generating a subtree according to the i-th parameter node includes: creating a node node of a complex object according to the flag i of the parameter node; judging whether the flag i of the parameter node is less than the number of node attributes, if so, creating a new i-th attribute node of the node node, otherwise exiting the process; judging whether the i-th attribute node is a basic type, if so, the left child of the i-th attribute node points to the new node, and reassigns i by incrementing i, and then judging whether the flag i of the parameter node is less than the number of node attributes; According to the traversed parameters, the input parameters of the tested interface are obtained to generate a call statement of the tested interface, including: reading the traversed parameters based on the logical rule of initializing basic types first and then initializing complex types; obtaining the input parameters of the tested interface, and then generating a call statement of the tested interface; wherein the order of parameters obtained after traversal conforms to the order of parameters specified when the tested interface is developed; Generate a test script for the interface under test based on the input parameters of the interface under test and the calling statements of the interface under test.

2. The method according to claim 1, characterized in that: Get the predecessor binary search tree generated according to the parameters of the interface under test, including: Define the storage structure of the predecessor binary search tree; The parameters of the interface under test are read, and a predecessor binary search tree is generated according to the storage structure.

3. The method according to claim 1, characterized in that Traversing the predecessor binary search tree includes: According to the parameter sequence preset by the interface under test, the predecessor binary search tree is traversed and stored.

4. A device for automatically generating test scripts, characterized in that: include: The acquisition module is used to acquire a predecessor binary search tree generated according to the interface parameters under test, so as to traverse the predecessor binary search tree; wherein, the process of generating the predecessor binary search tree includes: establishing a root node; setting a flag i of the current node; judging whether the flag i of the current node is less than the number of parameters, if so, acquiring the i-th parameter node, otherwise exiting the process; judging whether the i-th parameter node is a basic type, if so, the left child of the i-th parameter node points to a new node, and i is reassigned to i by self-increment, and the judgment logic is re-executed; otherwise, a subtree is generated according to the i-th parameter node; The process of generating a subtree according to the i-th parameter node includes: creating a node node of a complex object according to the flag i of the parameter node; judging whether the flag i of the parameter node is less than the number of node attributes, if so, creating a new i-th attribute node of the node node, otherwise exiting the process; judging whether the i-th attribute node is a basic type, if so, the left child of the i-th attribute node points to the new node, and reassigns i by incrementing i, and then judging whether the flag i of the parameter node is less than the number of node attributes; The traversal module is used to obtain the input parameters of the tested interface according to the traversed parameters to generate the call statement of the tested interface, including: reading the traversed parameters based on the logical rule of initializing the basic types first and then the complex types; obtaining the input parameters of the tested interface, and then generating the call statement of the tested interface; wherein the order of the parameters obtained after the traversal conforms to the order of the parameters specified when the tested interface is developed; The generation module is used to generate a test script for the interface under test based on the input parameters of the interface under test and the calling statements of the interface under test.

5. The device according to claim 4, characterized in that The acquisition module acquires a predecessor binary search tree generated according to the measured interface parameters, including: Define the storage structure of the predecessor binary search tree; The parameters of the interface under test are read, and a predecessor binary search tree is generated according to the storage structure.

6. The device according to claim 4, characterized in that The traversal module traverses the predecessor binary search tree, including: According to the parameter sequence preset by the interface under test, the predecessor binary search tree is traversed and stored.

7. An electronic device, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 3.

8. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 3 is implemented.

Citation Information

Patent Citations

  • Method and device for generating test case

    CN106681903A

  • Test script generation method and apparatus, test method and apparatus, device and storage medium

    CN108470004A