Method and device for generating interface automated test cases

Automatically updating interface automation test cases through code scanning and JAVA reflection mechanism solves the problem of untimely test case updates caused by changes in interface input parameters, and improves test efficiency and accuracy.

CN113760745BActive Publication Date: 2025-09-19BEIJING WODONG TIANJUN INFORMATION TECH CO LTD +1
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202110548400.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-05-19
Publication Date
2025-09-19
Estimated Expiration
2041-05-19

AI Technical Summary

Technical Problem

Existing interface automated test cases require manual maintenance after input parameters are modified, resulting in untimely use case updates and the risk of incomplete coverage.

Method used

The target interface of the interface code change is determined through code scanning, and the JAVA reflection mechanism is used to analyze the input parameter change type and automatically update the test case.

Benefits of technology

It realizes timely and automatic updating of test cases when interface input parameters change, reduces the risk of manual maintenance, and improves the efficiency of test case generation and interface testing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113760745B_ABST
    Figure CN113760745B_ABST
Patent Text Reader

Abstract

The embodiment of the present invention discloses a method and device for generating automated test cases for interfaces, which relate to the field of computer technology. A specific implementation of the method includes: determining the target interface whose interface code has changed by means of code scanning; determining the input parameter change type of the target interface based on the JAVA reflection mechanism; and updating the test cases of the target interface according to the input parameter change type. The method provided by the embodiment of the present invention determines the interface whose code has changed by scanning the interface code, and determines the input parameter change type by using the JAVA reflection mechanism, thereby updating the test cases. The method can automatically and timely update the automated test cases of the interface when the input parameters of the interface change, thereby reducing the risk of incomplete coverage of manually maintained test cases, improving the generation efficiency of interface automated test cases, and thus improving the testing efficiency of the interface.
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 generating interface automated test cases. Background Art

[0002] During the interface automation testing process, when the interface input parameters are modified, the interface automation test cases also need to be modified or updated accordingly to ensure the correctness of the interface test.

[0003] Currently, the modification or update of interface automation use cases is generally maintained manually. For example, a message that the interface input parameters have been modified is obtained through the interface automation use case execution failure report, and relevant personnel need to investigate the cause of the interface automation use case support failure; or relevant personnel notify the person who maintains the interface automation use case that the interface input parameters have been modified and the interface automation use case maintenance is required.

[0004] However, manual maintenance of interface automation use cases will result in untimely use case updates and the risk of incomplete use case coverage. Summary of the Invention

[0005] In view of this, an embodiment of the present invention provides a method and apparatus for generating interface automation test cases, which can automatically and timely update interface automation test cases when interface input parameters change.

[0006] To achieve the above object, according to one aspect of an embodiment of the present invention, a method for generating an interface automated test case is provided, comprising:

[0007] Determine the target interface whose interface code has changed by code scanning;

[0008] Determine the input parameter change type of the target interface based on the JAVA reflection mechanism;

[0009] Update the test case of the target interface according to the input parameter change type.

[0010] Optionally, the input parameter change type includes at least one of the following: adding a new parameter, deleting a parameter, and changing a parameter.

[0011] Optionally, determining the target interface whose interface code has changed by code scanning includes:

[0012] Scan the interfaces within the range of the interfaces to be scanned, and obtain the codes of the interfaces at the current moment;

[0013] Determine whether the code of the interface at the current moment has changed relative to the code of the interface at the previous moment;

[0014] If so, it is determined that the interface whose code has been changed is the target interface.

[0015] Optionally, determining the input parameter change type of the target interface based on a JAVA reflection mechanism includes:

[0016] Traverse the business method names in the code of the target interface at the current moment:

[0017] Obtain each first input parameter in the code of the business method at the current moment;

[0018] Determine whether the input parameters of the business method in the code at the previous moment include the first input parameter; if so, obtain the first parameter value of the first input parameter in the code at the current moment and the second parameter value in the code at the previous moment, and determine whether the first parameter value and the second parameter value are the same; if they are the same, determine that the first input parameter has not changed; if they are different, determine that the input parameter change type of the first input parameter is a modified parameter; otherwise, determine that the input parameter change type of the first input parameter is a newly added parameter;

[0019] Obtain each second input parameter of the business method in the code at the previous moment, and determine whether the input parameters of the business method in the code at the current moment include the second input parameter; if not, determine that the input parameter change type of the second input parameter is a deletion parameter.

[0020] Optionally, the method further includes:

[0021] Before determining whether the input parameters of the business method in the code at the previous moment include the first input parameter, determining that the first input parameter is an input parameter of a basic type; if the first input parameter is not an input parameter of a basic type, splitting the first input parameter into multiple input parameters of the basic type;

[0022] Before determining whether the input parameters of the business method in the code at the current moment include the second input parameter, determine whether the second input parameter is an input parameter of the basic type; if the second input parameter is not an input parameter of the basic type, split the second input parameter into multiple input parameters of the basic type.

[0023] Optionally, updating the test case of the target interface according to the input parameter change type includes:

[0024] Traverse each business method of the target interface, and for each input parameter in the business method, update the test case of the target interface in the following way:

[0025] When the input parameter change type is a new parameter, the input parameter is added to each test case of the target interface, and / or a test case corresponding to the input parameter is added to the test case set of the target interface;

[0026] When the input parameter change type is parameter deletion, delete the input parameter in each test case of the target interface;

[0027] When the input parameter change type is parameter change, the value of the input parameter in each test case of the target interface is changed.

[0028] Optionally, when the input parameter change type is parameter deletion, after deleting the input parameter in each test case of the target interface, the method further includes:

[0029] Determine whether there are duplicate test cases in the updated test case set;

[0030] If so, delete the duplicate test cases in the updated test case set.

[0031] The embodiment of the present invention further provides an interface automated test case generation device, comprising:

[0032] A first determination module determines the target interface whose interface code has changed by code scanning;

[0033] A second determination module determines the input parameter change type of the target interface based on a JAVA reflection mechanism;

[0034] The use case update module updates the test case of the target interface according to the input parameter change type.

[0035] An embodiment of the present invention further provides an electronic device, including:

[0036] one or more processors;

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

[0038] When the one or more programs are executed by the one or more processors, the one or more processors implement the interface automation test case generation method according to the embodiment of the present invention.

[0039] An embodiment of the present invention further provides a computer-readable medium having a computer program stored thereon, which, when executed by a processor, implements the method for generating an interface automated test case according to an embodiment of the present invention.

[0040] One embodiment of the above invention has the following advantages or beneficial effects: determining the target interface whose code has changed by code scanning, analyzing the code of the target interface based on the JAVA reflection mechanism, determining the input parameter change type of the target interface, and updating the test case of the target interface according to the input parameter change type. The embodiment of the present invention can automatically update the test case of the interface in a timely manner when the interface input parameter changes to ensure the correctness of the interface test. This method can reduce the risk of incomplete coverage of manually maintained test cases, improve the efficiency of generating interface automated test cases, and thus improve the testing efficiency of the interface.

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

[0042] The accompanying drawings are provided for a better understanding of the present invention and are not intended to limit the present invention.

[0043] Figure 1 Schematic diagram of the main process of a method for generating interface automated test cases according to an embodiment of the present invention;

[0044] Figure 2 1 is a schematic diagram of the main process of another method for generating interface automated test cases according to an embodiment of the present invention;

[0045] Figure 3 1 is a schematic diagram of the main process of another method for generating interface automated test cases according to an embodiment of the present invention;

[0046] Figure 4 1 is a schematic diagram of the main process of another method for generating interface automated test cases according to an embodiment of the present invention;

[0047] Figure 5 Schematic diagram of main modules of an interface automated test case generation device according to an embodiment of the present invention;

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

[0049] 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

[0050] The following description of exemplary embodiments of the present invention is made in conjunction with the accompanying drawings, in which various details of the embodiments of the present invention are included to facilitate understanding. These details should be considered as merely exemplary. Therefore, it should be appreciated by those skilled 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 the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.

[0051] Currently, interface automation is primarily implemented and maintained using technologies such as TestNG (Test Next Generation, an open-source automated testing framework) and Jenkins (a Java-based continuous integration tool). When interface input parameters change, the interface automation test cases cannot be automatically updated to verify the correctness of the interface. Therefore, a method for generating interface automation test cases is needed to ensure that these test cases are updated automatically and in a timely manner when interface input parameters change.

[0052] Figure 1 A method for generating interface automated test cases according to an embodiment of the present invention is provided. Figure 1 As shown, the method includes the following steps:

[0053] Step S101: determining the target interface whose interface code has changed by code scanning.

[0054] In the embodiment of the present invention, the code scanning method may be to scan the interface code within a preset time interval, that is, to periodically scan the interface code, thereby determining the target interface whose interface code has changed.

[0055] In an optional embodiment, as Figure 2 As shown, step S101 includes the following steps:

[0056] Step S201: Scan the interfaces within the range of the interface to be scanned and obtain the interface code at the current moment;

[0057] Step S202: Determine whether the code of the interface at the current moment has changed relative to the code of the interface at the previous moment. If so, execute step S203; if not, execute step S204;

[0058] Step S203: Determine the interface whose code has changed as the target interface;

[0059] Step S204: Determine whether there is no interface with changed code.

[0060] In an embodiment of the present invention, the target interface is determined by the change of the interface code between the current moment and the previous moment, wherein the time interval between the current moment and the previous moment can be preset, and the time interval can be the interval of the timed scanning of the interface code. For example, the preset time interval can be 1 millisecond, 1 second, 10 seconds, etc., so that the interface automation test case can be updated in time, and the test case can be verified and feedback problems in time.

[0061] In an embodiment of the present invention, the interface range to be scanned can be an interface within the interface automation test range, or an interface with a customized scanning rule within the interface automation test range. When scanning the interface within the interface range to be scanned, the code of the interface at the current moment can be obtained by scanning the file corresponding to the interface (such as a class file, etc.). Then, the code of the interface at the current moment is compared with the code at the previous moment. If the code is different, it means that the code of the interface has changed, and the interface with the changed code is determined as the target interface. In order to ensure the correctness of the target interface test, the interface automation test case needs to be updated. If they are the same, it is determined that there is no interface with a changed code, and there is no need to update the interface automation test case.

[0062] In an optional implementation, when scanning the interface code within the range of the interface to be scanned, the code of the scanned interface is saved. The interface code and the scanning time can be saved according to the interface identifier, and the codes of the two adjacent moments, the current moment and the previous moment, can be compared to determine whether the interface code has changed to determine whether it is the target interface. If so, the test case of the target interface is updated, and the code of the target interface saved at the previous moment is deleted, and only the code of the current moment after the test case is updated is saved.

[0063] After determining the target interface where the code has changed, in order to automatically update the test cases of the target interface to verify the correctness of the target interface, it is necessary to determine the changes in the input parameters corresponding to the code changes.

[0064] Step S102: Determine the input parameter change type of the target interface based on the JAVA reflection mechanism.

[0065] In an embodiment of the present invention, the input parameter change type includes at least one of the following: adding a new parameter, deleting a parameter, and changing a parameter.

[0066] In an alternative embodiment, Figure 3 As shown, step S102 includes the following steps:

[0067] Step S301: traverse the business method names in the code of the target interface at the current moment;

[0068] Step S302: Obtain each first input parameter in the code of the business method at the current moment;

[0069] Step S303: Determine whether the input parameters of the business method in the code at the previous moment include the first input parameter; if not, execute step S304; if so, execute step S305;

[0070] Step S304: Determine whether the input parameter change type of the first input parameter is a new parameter;

[0071] Step S305: Obtain a first parameter value of the first input parameter in the code at the current moment, and a second parameter value in the code at the previous moment;

[0072] Step S306: Determine whether the first parameter value and the second parameter value are the same. If so, execute step S307; if not, execute step S308.

[0073] Step S307: Determine whether the input parameter change type of the first input parameter is not a parameter change;

[0074] Step S308: Determine whether the input parameter change type of the first input parameter is a modified parameter.

[0075] In an optional implementation manner, before step S303, the following steps are included:

[0076] Determine whether the first input parameter is a basic type input parameter; if the first input parameter is not a basic type input parameter, split the first input parameter into multiple basic type input parameters. Among them, the basic type input parameter can be a parameter with a single value, and the non-basic type input parameter can be a parameter with multiple values. Basic types include data types such as java.lang.Integer, java.lang.String, java.lang.Boolean, int, classjava.lang.Long, Long, etc. Non-basic types include data types such as java.lang.Object, java.util.List<java.lang.Integer> , java.util.List<java.lang.String> wait.

[0077] In an embodiment of the present invention, when determining the input parameter change type of the target interface, it is necessary to traverse the business method name of the target interface in the code at the current moment, such as getting the menu (getMenu), and obtain each first input parameter of the business method in the code at the current moment according to the business method name. When determining the basic type of the first input parameter, make another judgment. If the first input parameter is not a basic type, it is necessary to split the first input parameter into input parameters of multiple basic types, and then make another judgment. When making a judgment, determine whether the input parameter of the business method in the code at the previous moment includes the first input parameter. Suppose the first input parameters of the business method named getMenu at the current moment are A, B, and C. If the input parameters of the business method of getMenu at the previous moment include A and B, it can be seen that the input parameters of the business method at the previous moment do not include C, then the input parameter change type of the input parameter C is determined to be a new parameter. If the input parameters of the business method of getMenu at the previous moment include A, B, C, and D, that is, the input parameters of the business method of getMenu at the previous moment include the current moment. For input parameters A, B and C, the first parameter values ​​and second parameter values ​​corresponding to the first input parameters A, B and C at the current moment and the previous moment are further obtained. For example, at the current moment, the first parameter values ​​corresponding to the input parameters A, B and C are 9, 10 and 11 respectively. If the second parameter values ​​corresponding to the input parameters A, B and C at the previous moment are the same as the first parameter values, it is determined that the input parameter change type of the first input parameter is not a parameter change. If the second parameter values ​​corresponding to the input parameters A, B and C at the previous moment are 9, 12 and 11 respectively, which are different from the first parameter values, it is determined that the input parameter change type of the first input parameter is a parameter change.

[0078] In an alternative embodiment, Figure 4 As shown, step S102 further includes the following steps:

[0079] Step S401: Obtain each second input parameter in the code of the business method at the previous moment;

[0080] Step S402: Determine whether the input parameters of the business method in the current code include the second input parameter; if not, execute step S403; if so, execute step S404;

[0081] Step S403: Determine whether the input parameter change type of the second input parameter is a deletion parameter;

[0082] Step S404: Determine whether the input parameter change type of the second input parameter is a deletion parameter.

[0083] In the embodiment of the present invention, the following steps are further included before step S402:

[0084] Determine whether the second input parameter is an input parameter of the base type; if the second input parameter is not an input parameter of the base type, split the second input parameter into multiple input parameters of the base type.

[0085] After traversing the business method names in the code of the target interface at the current moment, it also includes obtaining each second input parameter of the business method at the previous moment. Before judging the input parameter change type of the second input parameter, it is necessary to confirm whether each second input parameter is a basic type. If the second input parameter is not a basic type, the second input parameter is split into multiple basic types before judging. For example, if the second input parameters of the getMenu business method at the previous moment are A, B, C, and D, if the input parameters of the getMenu business method at the current moment are A, B, and C, excluding input parameter D, then the input parameter change type of the second input parameter is determined to be a deletion parameter, that is, the input parameter D is deleted from the input parameters of the business method at the current moment. If the input parameters of the getMenu business method at the current moment are A, B, C, D, and E, then the input parameter change type of the second input parameter is determined not to be a deletion parameter.

[0086] When judging the input parameter change type of the target interface based on the JAVA reflection mechanism algorithm, by comparing each first input parameter in the current moment's code with the input parameter at the previous moment, it can be judged whether the input parameter change type of the first input parameter is a new parameter or a changed parameter. By comparing each second input parameter in the previous moment's code with the input parameter at the current moment, it can be judged whether the input parameter change type of the second input parameter is a deleted parameter. When making a judgment, the above judgment process is performed for each first input parameter and each second input parameter, so that the input parameter change type of the target interface can be determined more accurately.

[0087] Step S103: Update the test case of the target interface according to the input parameter change type.

[0088] In an optional implementation, step S103 includes:

[0089] Traverse each business method of the target interface and update the test case of the target interface in the following way for each input parameter in the business method:

[0090] When the input parameter change type is a new parameter, the input parameter is added to each test case of the target interface, and / or a test case corresponding to the input parameter is added to the test case set of the target interface;

[0091] When the input parameter change type is to delete the parameter, delete the input parameter in each test case of the target interface;

[0092] When the input parameter change type is parameter change, the value of the input parameter in each test case of the target interface is changed.

[0093] In an embodiment of the present invention, the test cases of the target interface are updated according to the different input parameter change types. If the input parameter change type is a newly added parameter, the test cases are updated according to the type of the newly added parameter. If the newly added parameter is a basic type, the input parameter can be added to the test case and a default value can be assigned to the input parameter. The corresponding test case can also be added at the same time. If the newly added parameter is not a basic type, the input parameter and test case are added to the test case set according to the business logic. If the input parameter change type is to delete a parameter, the input parameter in the test case is deleted, and the test case corresponding to the input parameter can also be deleted at the same time. If the input parameter change type is to change a parameter, the test case is changed according to the value of the input parameter.

[0094] For example, after determining the target interface whose code has changed, the JAVA reflection mechanism algorithm is used to analyze the input parameter change type of the target interface, and newly added parameters A and B are obtained, as shown in Table 1. Parameters A and B are judged, and it is determined that parameter A is a basic type and parameter B is a non-basic type. Therefore, for parameter A, parameter A is automatically added to the target interface automated test case set, and a default value of parameter A is assigned (for example, if the type of parameter A is String, the default value is empty); business logic analysis is performed based on parameter B, and parameter B is automatically added to the target interface automated test case, and a corresponding test case is added. The business method is named getMenu. Parameters A and B are new parameters. In each test case, parameter A (childrens!) is added as the basic type String and assigned a value of empty (""). Parameter B is not a basic type. The values ​​of B are 9, 10, and 11, respectively, which can be divided into three basic types. According to the business logic, three test cases are added to the test case set, thereby adding three test cases to the test case set of the business method getMenu. Each test case includes parameters A and B, and the updated test case set is obtained, as shown in Table 1.

[0095] Table 1

[0096]

[0097] In an optional implementation, when the input parameter change type is parameter deletion, after deleting the input parameter in each test case of the target interface, the following steps are further included:

[0098] Determine whether there are duplicate test cases in the updated test case set;

[0099] If so, delete the duplicate test cases in the updated test case set.

[0100] In a test case set, after deleting one or more input parameters, one or more duplicate test cases may exist. In this case, the duplicate test cases need to be deleted. For example, in the test case set of the target interface, there are parameters A, B, and C. If only the value of parameter C is different in two test cases, and the other contents are the same, that is, in one test case, the corresponding values ​​of parameters A, B, and C are 9, 10, and 11, respectively, and in the other test case, the corresponding values ​​of parameters A, B, and C are 9, 10, and 12, respectively. If the input change type of parameter C is parameter deletion, then after deleting parameter C in both test cases, the two test cases are the same. Therefore, it is necessary to remove the identical test cases and perform deduplication to improve the accuracy and efficiency of the test.

[0101] In one implementation of an embodiment of the present invention, in step S101, when determining the target interface whose interface code has changed by code scanning, the first number of the target interfaces is determined. After executing the test case for updating the target interface in step S103, the second number of the target interfaces for which the test case has been updated is obtained, and it is determined whether the second number is less than the first number. If the second number is less than the first number, the process returns to step S101 to redetermine the first number of the target interfaces, and continues to execute steps S102 and S103 until the second number is equal to the first number, thereby confirming that the test cases for all target interfaces have been updated to ensure the correctness of the interface test. For example, when executing step S101, the first number of the target interfaces is 10, and when executing step S103, the second number of the target interfaces for which the test case has been updated is 8. If the second number is less than the first number, the process returns to redetermine the first number of the target interfaces as 2, and continues to execute steps S102 and S103.

[0102] The interface automation test case generation method provided by the embodiment of the present invention determines the target interface whose code has changed by means of code scanning, analyzes the code of the target interface based on the JAVA reflection mechanism, and traverses the business methods of the target interface to analyze and judge each input parameter in the business method in the code at the current moment and the previous moment to determine the input parameter change type of the target interface, and automatically updates the test case of the target interface according to the input parameter change type. This method can automatically update the test case of the interface in a data-driven manner in a timely manner when the interface input parameter changes, so as to ensure the correctness of the interface test. The embodiment of the present invention reduces the time required for manual maintenance of test cases, while reducing the risk of online problems caused by incomplete coverage of manually maintained test cases, improving the generation efficiency of interface automation test cases, and thereby improving the testing efficiency of the interface.

[0103] According to another aspect of the embodiment of the present invention, Figure 5 As shown, an interface automation test case generation device 500 is provided, comprising:

[0104] The first determining module 501 determines the target interface whose interface code has changed by code scanning;

[0105] The second determining module 502 determines the input parameter change type of the target interface based on the JAVA reflection mechanism;

[0106] The use case update module 503 updates the test case of the target interface according to the input parameter change type.

[0107] In an embodiment of the present invention, the first determination module 501 is also used to: scan the interfaces within the range of the scanned interfaces to obtain the code of the interfaces at the current moment; determine whether the code of the interface at the current moment has changed relative to the code of the interface at the previous moment; if so, determine that the interface whose code has changed is the target interface.

[0108] In this embodiment of the present invention, the second determining module 502 is further configured to:

[0109] Traverse the business method names in the target interface's code at the current moment;

[0110] Obtain each first input parameter of the business method in the code at the current moment; determine whether the input parameter of the business method in the code at the previous moment includes the first input parameter; if so, obtain the first parameter value of the first input parameter in the code at the current moment and the second parameter value in the code at the previous moment, and determine whether the first parameter value and the second parameter value are the same; if they are the same, determine that the first input parameter has not changed; if they are different, determine that the input parameter change type of the first input parameter is a modified parameter; otherwise, determine that the input parameter change type of the first input parameter is a newly added parameter;

[0111] Obtain each second input parameter in the code of the business method at the previous moment, and determine whether the input parameters of the business method in the code at the current moment include the second input parameter; if not, determine that the input parameter change type of the second input parameter is a deletion parameter.

[0112] In an embodiment of the present invention, the second determining module 502 is further configured to: before determining whether the input parameters of the business method in the code at the previous moment include the first input parameter, determine whether the first input parameter is an input parameter of a basic type; if the first input parameter is not an input parameter of a basic type, split the first input parameter into multiple input parameters of the basic type;

[0113] Before determining whether the input parameters of the business method in the code at the current moment include the second input parameter, determine whether the second input parameter is an input parameter of the basic type; if the second input parameter is not an input parameter of the basic type, split the second input parameter into multiple input parameters of the basic type.

[0114] In this embodiment of the present invention, the use case update module 503 is further configured to: traverse each business method of the target interface, and for each input parameter in the business method, update the test case of the target interface in the following manner:

[0115] When the input parameter change type is a new parameter, add the input parameter to each test case of the target interface, and / or add a test case corresponding to the input parameter to the test case set of the target interface;

[0116] When the input parameter change type is to delete the parameter, delete the input parameter in each test case of the target interface;

[0117] When the input parameter change type is parameter change, the value of the input parameter in each test case of the target interface is changed.

[0118] In an embodiment of the present invention, the use case update module 503 is further configured to: when the input parameter change type is parameter deletion, after deleting the input parameter in each test case of the target interface, further include:

[0119] Determine whether there are duplicate test cases in the updated test case set;

[0120] If so, delete the duplicate test cases in the updated test case set.

[0121] The interface automatic test case generation device provided by the embodiment of the present invention can automatically update the test cases corresponding to the interface in a timely manner when the interface input parameters change, without the need for manual maintenance, thus avoiding the online risk of incomplete coverage caused by manual maintenance of test cases.

[0122] To achieve the above-mentioned purpose, according to another aspect of an embodiment of the present invention, an electronic device is provided, which includes: one or more processors; a storage device for storing one or more programs, and when the one or more programs are executed by one or more processors, the one or more processors implement the interface automation test case generation method of an embodiment of the present invention.

[0123] To achieve the above object, 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 interface automation test case generation method of the embodiment of the present invention is implemented.

[0124] Figure 6An exemplary system architecture 600 is shown to which the interface automation test case generation method or interface automation test case generation apparatus according to an embodiment of the present invention may be applied.

[0125] like Figure 6 As shown, system architecture 600 may include terminal devices 601, 602, 603, a network 604, and a 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 or wireless communication links or fiber optic cables.

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

[0127] 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.

[0128] Server 605 may be a server that provides various services, such as a testing server (for example only) that supports software testing applications operated by users using terminal devices 601, 602, and 603. The testing server may analyze and process data such as received test case update requests, and feed back processing results (for example, updated test cases—for example only) to the terminal device.

[0129] It should be noted that the interface automation test case generation method provided in the embodiment of the present invention is generally executed by the server 605 , and accordingly, the interface automation test case generation device is generally set in the server 605 .

[0130] It should be understood that Figure 6 The number of terminal devices, networks and servers in the embodiment is merely illustrative. Any number of terminal devices, networks and servers may be provided as required.

[0131] Reference below Figure 7 , which shows a schematic structural diagram 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.

[0132] like Figure 7As 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 unit 708 into a random access memory (RAM) 703. Various programs and data required for the operation of the system 700 are also stored in the RAM 703. The CPU 701, ROM 702, and 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.

[0133] The following components are connected to the I / O interface 705: an input section 706 including a keyboard, a mouse, and the like; an output section 707 including devices such as a cathode ray tube (CRT), a liquid crystal display (LCD), and a speaker; a storage section 708 including a hard disk; and a communication section 709 including a network interface card such as a LAN card or a modem. 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, or a semiconductor memory, is installed in the drive 710 as needed, so that computer programs read therefrom can be installed into the storage section 708 as needed.

[0134] In particular, according to the embodiments disclosed in the present invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, the embodiments disclosed in the present invention include a computer program product comprising a computer program carried on a computer-readable medium, the computer program comprising program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network via the communication section 709, and / or installed from a 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.

[0135] It should be noted that the computer-readable medium described in the present invention can be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of computer-readable storage media can include, but are not limited to, an electrical connection having one or more conductors, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In the present invention, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In the present invention, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. This propagated data signal can take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transport a program for use by or in conjunction with an instruction execution system, apparatus, or device. Program code embodied on a computer-readable medium may be transmitted using any suitable medium, including but not limited to wireless, wireline, optical fiber cable, RF, or any suitable combination thereof.

[0136] The flowcharts and block diagrams in the accompanying drawings illustrate the possible implementation architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present invention. In this regard, each box in the flowchart or block diagram can represent a module, program segment, or a part of code, and the above-mentioned module, program segment, or a part of code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in an order different from that 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 flowchart, and the combination of boxes in the block diagram or flowchart, can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0137] The modules involved in the embodiments of the present invention may be implemented in software or in hardware. The modules described may also be provided in a processor. For example, they may be described as follows: a processor includes a first determination module, a second determination module, and a use case update module. The names of these modules do not, in some cases, constitute a limitation on the modules themselves. For example, the first determination module may also be described as a "module for determining the target interface whose interface code has changed by code scanning."

[0138] As another aspect, the present invention further provides a computer-readable medium, which may be included in the device described in the above embodiment, or may exist independently and not be incorporated into the device. The computer-readable medium carries one or more programs, and when the one or more programs are executed by the device, the device is caused to: determine the target interface whose interface code has changed by code scanning; determine the input parameter change type of the target interface based on the Java reflection mechanism; and update the test case of the target interface based on the input parameter change type.

[0139] According to the technical solution of the embodiment of the present invention, the target interface whose code has changed is determined by code scanning, the code of the target interface is analyzed based on the JAVA reflection mechanism, the input parameter change type of the target interface is determined, and the test case of the target interface is updated according to the input parameter change type. The embodiment of the present invention can automatically update the test case of the interface in a timely manner when the interface input parameter changes to ensure the correctness of the interface test. The embodiment of the present invention can reduce the risk of incomplete coverage of manually maintained test cases, improve the efficiency of generating interface automated test cases, and thus improve the testing efficiency of the interface.

[0140] The above specific embodiments do not limit the scope of protection of the present invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions may occur depending on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention are intended to be included within the scope of protection of the present invention.

Claims

1. A method for generating interface automated test cases, characterized in that: include: Determine the target interface whose interface code has changed by code scanning; Determine the input parameter change type of the target interface based on the JAVA reflection mechanism; The input parameter change type includes at least one of the following: adding a parameter, deleting a parameter, and changing a parameter; Determining the input parameter change type of the target interface based on the JAVA reflection mechanism includes: traversing the business method of the target interface, analyzing and judging each input parameter in the business method in the code at the current moment and the previous moment, and determining the input parameter change type of the target interface; determining the input parameter change type of the target interface based on the JAVA reflection mechanism includes: traversing the business method name in the code of the target interface at the current moment: obtaining each first input parameter of the business method in the code at the current moment; judging whether the input parameter of the business method in the code at the previous moment includes the first input parameter; if so, obtaining the first parameter value of the first input parameter in the code at the current moment and the second parameter value in the code at the previous moment, and judging Determine whether the first parameter value and the second parameter value are the same. If they are the same, determine that the first input parameter has not changed. If they are different, determine that the input parameter change type of the first input parameter is a modified parameter; otherwise, determine that the input parameter change type of the first input parameter is a newly added parameter; obtain each second input parameter in the code of the business method at the previous moment, and determine whether the input parameters of the business method in the code at the current moment include the second input parameter; if not, determine that the input parameter change type of the second input parameter is a deleted parameter; before determining whether the input parameters of the business method in the code at the previous moment include the first input parameter or the second input parameter, further comprising: determining that the first input parameter or the second input parameter is an input parameter of the basic type; Update the test case of the target interface according to the input parameter change type.

2. The method according to claim 1, characterized in that Determine the target interface whose interface code has changed by code scanning, including: Scan the interfaces within the range of the interfaces to be scanned, and obtain the codes of the interfaces at the current moment; Determine whether the code of the interface at the current moment has changed relative to the code of the interface at the previous moment; If so, it is determined that the interface whose code has been changed is the target interface.

3. The method according to claim 1, characterized in that The method further comprises: If the first input parameter is not an input parameter of a basic type, split the first input parameter into multiple input parameters of the basic type; If the second input parameter is not an input parameter of a basic type, the second input parameter is split into multiple input parameters of the basic type.

4. The method according to claim 1, wherein According to the input parameter change type, update the test case of the target interface, including: Traverse each business method of the target interface, and for each input parameter in the business method, update the test case of the target interface in the following way: When the input parameter change type is a new parameter, the input parameter is added to each test case of the target interface, and / or a test case corresponding to the input parameter is added to the test case set of the target interface; When the input parameter change type is parameter deletion, delete the input parameter in each test case of the target interface; When the input parameter change type is parameter change, the value of the input parameter in each test case of the target interface is changed.

5. The method according to claim 4, characterized in that When the input parameter change type is parameter deletion, after deleting the input parameter in each test case of the target interface, the method further includes: Determine whether there are duplicate test cases in the updated test case set; If so, delete the duplicate test cases in the updated test case set.

6. An interface automated test case generation device, characterized in that: include: A first determination module determines the target interface whose interface code has changed by code scanning; A second determination module determines the input parameter change type of the target interface based on a JAVA reflection mechanism; The input parameter change type includes at least one of the following: adding a parameter, deleting a parameter, and changing a parameter; Determining the input parameter change type of the target interface based on the JAVA reflection mechanism includes: traversing the business method of the target interface, analyzing and judging each input parameter in the business method in the code at the current moment and the previous moment, and determining the input parameter change type of the target interface; the second determination module is also used to: traverse the business method name of the target interface in the code at the current moment; obtain each first input parameter of the business method in the code at the current moment; determine whether the input parameter of the business method in the code at the previous moment includes the first input parameter; if so, obtain the first parameter value of the first input parameter in the code at the current moment, and the second parameter value in the code at the previous moment, and determine whether the first parameter value and the second parameter value are the same. Whether the two parameter values ​​are the same, if they are the same, it is determined that the first input parameter has not changed; if they are different, it is determined that the input parameter change type of the first input parameter is a modified parameter; otherwise, it is determined that the input parameter change type of the first input parameter is a newly added parameter; obtain each second input parameter in the code of the business method at the previous moment, and determine whether the input parameters of the business method in the code at the current moment include the second input parameter; if not, it is determined that the input parameter change type of the second input parameter is a deleted parameter; before determining whether the input parameters of the business method in the code at the previous moment include the first input parameter or the second input parameter, it also includes: determining that the first input parameter or the second input parameter is an input parameter of the basic type; The use case update module updates the test case of the target interface according to the input parameter change type.

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 5.

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 5 is implemented.

Citation Information

Patent Citations

  • Unit test method and device

    CN108595342A

  • Interface testing method and device

    CN111198813A

  • Code generation method and device

    CN111240967A