A method and apparatus for generating interface test cases
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-08
- Publication Date
- 2026-08-14
AI Technical Summary
[0003]有鉴于此,本发明实施例提供一种生成接口测试用例的方法和装置,以解决场景遗漏、大量冗余和无效的测试用例的技术问题
[0062] One embodiment of the above invention has the following advantages or beneficial effects: By clustering defects corresponding to each plugin class, determining defect combinations based on the clustering results, and injecting each defect and defect combination into the baseline test cases to generate variant test cases, the technical problems of scenario omissions, excessive redundancy, and invalid test cases in the prior art are overcome. In scenarios where defects are deeply hidden, this embodiment of the invention can deeply mine related defects through clustering algorithms, using combined defects to mutate the baseline test cases, thereby quickly writing test cases for detectable defects and providing them to testers for reference, which helps improve software testing efficiency and quality. Especially when users' test case scenario analysis is incomplete, the test scope is unclear, and full testing is required, this embodiment of the invention can significantly improve the quality of test case writing.
Smart Images

Figure CN116760755B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of interface testing technology, and in particular to a method and apparatus for generating interface test cases. Background Technology
[0002] For business gateways, different gateways are implemented using different plugins. As the entry point for all traffic, the gateway requires very high testing quality. Currently, automated test cases for gateways are mainly written using scenario analysis. However, test cases written using scenario analysis may have issues such as missing scenarios or a large number of redundant and invalid test cases. Moreover, some hidden defects are difficult to discover through scenario combinations. Summary of the Invention
[0003] In view of this, embodiments of the present invention provide a method and apparatus for generating interface test cases to solve the technical problems of missing scenarios, a large number of redundant and invalid test cases.
[0004] To achieve the above objectives, according to one aspect of the present invention, a method for generating interface test cases is provided, comprising:
[0005] Pull the gateway code to be tested from the gateway testing platform;
[0006] Identify the various plugin classes in the gateway code and assign the baseline test cases to each of the plugin classes;
[0007] Cluster the defects corresponding to each of the plugin classes, and determine the combination of defects based on the clustering results of each defect;
[0008] Each defect and each combination of defects is injected into the baseline test case to generate variant test cases.
[0009] Optionally, the defects corresponding to each of the plugin classes are clustered, and based on the clustering results of each defect, combinations of defects are determined, including:
[0010] Obtain the defects corresponding to each of the aforementioned plugin classes;
[0011] Cluster the defects using any one of the defects as the cluster center;
[0012] Each defect within the cluster containing the cluster center is combined to obtain various defect combinations.
[0013] Optionally, the defects are clustered using any one defect as a cluster center; the defects within the cluster of the cluster center are then combined to obtain defect combinations, including:
[0014] Step a: Sort the defects in descending order of importance;
[0015] Step b: Cluster the defects in the ranking with the highest importance as the cluster center;
[0016] Step c: Combine the defects within the cluster where the cluster center is located to obtain the various defect combinations;
[0017] Step d: Remove the most important defects from the sorting.
[0018] Repeat steps b through d until the number of defects in the sorting is less than or equal to two.
[0019] Optionally, the individual defects and combinations of the individual defects are injected into the baseline test cases to generate variant test cases, including:
[0020] For each defect under each plugin class, the defect is injected into the baseline test case assigned to the plugin class, thereby generating a first variant test case.
[0021] For each defect combination, the defect combination is injected into the baseline test cases that are assigned to the corresponding plugin classes of the defect combination, thereby generating a second variant test case.
[0022] Optionally, after injecting the individual defects and combinations of defects into the baseline test cases to generate variant test cases, the method further includes:
[0023] A branch coverage algorithm is used to determine whether the mutated test case can cover the gateway code; if not, defects are injected into the baseline test case.
[0024] Optionally, a branch coverage algorithm is used to determine whether the mutated test case can cover the gateway code; if not, defects are injected into the baseline test case, including:
[0025] The gateway code, the baseline test cases, and the variant test cases are input into the branch coverage algorithm to output the coverage of the gateway code and the uncovered branch statements.
[0026] If the coverage is less than the coverage threshold, a new defect is constructed based on the plugin class to which the uncovered branch statement belongs, and the defect continues to be injected into the baseline test case.
[0027] Optionally, defects may be injected into the baseline test cases, including:
[0028] Cluster the defects corresponding to each of the plugin classes, and determine the combination of defects based on the clustering results of each defect;
[0029] Each defect and each combination of defects is injected into the baseline test case to generate variant test cases.
[0030] Furthermore, according to another aspect of the present invention, an apparatus for generating interface test cases is provided, comprising:
[0031] The pull module is used to pull the gateway code that needs to be tested from the gateway testing platform;
[0032] The classification module is used to identify the various plugin classes in the gateway code and classify the baseline test cases into the various plugin classes;
[0033] The combination module is used to cluster the defects corresponding to each of the various plug-in classes, and determine the combination of each defect based on the clustering results of each defect;
[0034] The mutation module is used to inject the individual defects and combinations of the individual defects into the baseline test cases, thereby generating mutated test cases.
[0035] Optionally, the combined module is further configured to:
[0036] Obtain the defects corresponding to each of the aforementioned plugin classes;
[0037] Cluster the defects using any one of the defects as the cluster center;
[0038] Each defect within the cluster containing the cluster center is combined to obtain various defect combinations.
[0039] Optionally, the combined module is further configured to:
[0040] Step a: Sort the defects in descending order of importance;
[0041] Step b: Cluster the defects in the ranking with the highest importance as the cluster center;
[0042] Step c: Combine the defects within the cluster where the cluster center is located to obtain the various defect combinations;
[0043] Step d: Remove the most important defects from the sorting.
[0044] Repeat steps b through d until the number of defects in the sorting is less than or equal to two.
[0045] Optionally, the mutation module is further configured to:
[0046] For each defect under each plugin class, the defect is injected into the baseline test case assigned to the plugin class, thereby generating a first variant test case.
[0047] For each defect combination, the defect combination is injected into the baseline test cases that are assigned to the corresponding plugin classes of the defect combination, thereby generating a second variant test case.
[0048] Optionally, the mutation module is further configured to:
[0049] A branch coverage algorithm is used to determine whether the mutated test case can cover the gateway code; if not, defects are injected into the baseline test case.
[0050] Optionally, the mutation module is further configured to:
[0051] The gateway code, the baseline test cases, and the variant test cases are input into the branch coverage algorithm to output the coverage of the gateway code and the uncovered branch statements.
[0052] If the coverage is less than the coverage threshold, a new defect is constructed based on the plugin class to which the uncovered branch statement belongs, and the defect continues to be injected into the baseline test case.
[0053] Optionally, the mutation module is further configured to:
[0054] Cluster the defects corresponding to each of the plugin classes, and determine the combination of defects based on the clustering results of each defect;
[0055] Each defect and each combination of defects is injected into the baseline test case to generate variant test cases.
[0056] According to another aspect of the present invention, an electronic device is also provided, comprising:
[0057] One or more processors;
[0058] Storage device for storing one or more programs.
[0059] 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.
[0060] According to another aspect of the present invention, a computer-readable medium is also provided, on which a computer program is stored, which, when executed by a processor, implements the methods described in any of the above embodiments.
[0061] According to another aspect of the present invention, a computer program product is also provided, including a computer program that, when executed by a processor, implements the methods described in any of the above embodiments.
[0062] One embodiment of the above invention has the following advantages or beneficial effects: By clustering defects corresponding to each plugin class, determining defect combinations based on the clustering results, and injecting each defect and defect combination into the baseline test cases to generate variant test cases, the technical problems of scenario omissions, excessive redundancy, and invalid test cases in the prior art are overcome. In scenarios where defects are deeply hidden, this embodiment of the invention can deeply mine related defects through clustering algorithms, using combined defects to mutate the baseline test cases, thereby quickly writing test cases for detectable defects and providing them to testers for reference, which helps improve software testing efficiency and quality. Especially when users' test case scenario analysis is incomplete, the test scope is unclear, and full testing is required, this embodiment of the invention can significantly improve the quality of test case writing.
[0063] The further effects of the aforementioned unconventional alternative methods will be explained below in conjunction with specific implementation methods. Attached Figure Description
[0064] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort. Wherein:
[0065] Figure 1 This is a flowchart of a method for generating interface test cases according to an embodiment of the present invention;
[0066] Figure 2 This is a flowchart of a method for generating interface test cases according to a possible embodiment of the present invention;
[0067] Figure 3 This is a flowchart of a method for generating interface test cases according to another applicable embodiment of the present invention;
[0068] Figure 4 This is a flowchart of a method for generating interface test cases according to another possible embodiment of the present invention;
[0069] Figure 5 This is a schematic diagram of an apparatus for generating interface test cases according to an embodiment of the present invention;
[0070] Figure 6 This is an exemplary system architecture diagram in which embodiments of the present invention can be applied;
[0071] Figure 7 This is a schematic diagram of the structure of a computer system suitable for implementing terminal devices or servers of the present invention. Detailed Implementation
[0072] The following description, in conjunction with the accompanying drawings, illustrates exemplary embodiments of the present invention, including various details to aid understanding. These details should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the invention. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.
[0073] It should be noted that the collection, gathering, updating, analysis, processing, use, transmission, and storage of user personal information involved in this disclosed technical solution all comply with relevant laws and regulations, are used for legitimate purposes, and do not violate public order and good morals. Necessary measures are taken to prevent unauthorized access to user personal information data and to safeguard user personal information security, network security, and national security.
[0074] Figure 1 This is a flowchart of a method for generating interface test cases according to an embodiment of the present invention. As one embodiment of the present invention, such as... Figure 1 As shown, the method for generating interface test cases may include:
[0075] Step 101: Pull the gateway code to be tested from the gateway testing platform.
[0076] First, enter the coding address in the gateway testing platform, and then pull the gateway code to be tested through the coding address. For example, pull the branch code on the master branch as the gateway code to be tested.
[0077] Step 102: Identify each plugin class in the gateway code and assign the baseline test cases to each plugin class.
[0078] In this step, the various plugin classes in the gateway code, i.e., ".plugins", are identified, and the pre-entered baseline test cases are then assigned to the corresponding plugin classes. Typically, each baseline test case will only be assigned to one plugin class.
[0079] It should be noted that baseline test cases are a preliminary testing task. Before step 101, baseline scenario test cases for different test plugins need to be entered.
[0080] For example, if a business gateway has 12 business plugins, then the gateway code can be identified as having 12 plugin classes, represented as an ordered set. These 12 plugins are: info plugin, mock plugin, qps plugin, cross-domain plugin, blacklist / whitelist plugin, signature plugin, identity authentication plugin, permission plugin, JSF plugin, resource plugin, grayscale plugin, and PIN restriction plugin. The pre-entered baseline test cases are then assigned to the corresponding plugin classes, as shown in Table 1.
[0081] Table 1. Plugin Classes and Their Corresponding Baseline Test Cases
[0082]
[0083]
[0084] To facilitate the management of test cases under various plugin classes, baseline test cases can be mapped to corresponding numerical values, represented as follows: Among them, the test cases corresponding to the info plugin must be executed first (highest priority). To distinguish them from the test cases of other plugins, the mapped values start from 1.
[0085] Step 103: Cluster the defects corresponding to each plugin class, and determine the defect combinations based on the clustering results of each defect.
[0086] First, obtain the defects corresponding to each plugin class. Each plugin class has one or more defects. Then, cluster the defects corresponding to each plugin class, and randomly combine defects within the same cluster to obtain various defect combinations. It should be noted that the defects corresponding to each plugin class can be obtained based on the developers' experience.
[0087] Optionally, step 103 may include: obtaining each defect corresponding to each plugin class; clustering each defect using any one defect as a cluster center; and combining each defect within the cluster containing the cluster center to obtain a combination of defects. First, clustering each defect using a certain defect as a cluster center yields a cluster centered on that defect. Then, randomly combining the defects within that cluster—for example, combining any two defects, any three defects, or any four defects—until all possible combinations are exhausted, thus obtaining a combination of defects.
[0088] Optionally, clustering the defects using any one defect as a cluster center; combining the defects within the cluster of the cluster center to obtain defect combinations, including: step a, sorting the defects in descending order of importance; step b, clustering the defects in the sorted order using the defect with the highest importance as the cluster center; step c, combining the defects within the cluster of the cluster center to obtain defect combinations; step d, deleting the defect with the highest importance from the sorted order; repeating steps b to d until the number of defects in the sorted order is less than or equal to two. To improve the efficiency of test case writing, firstly, all defects are sorted in descending order of importance. The defect with the highest importance in the sorted order is used as the cluster center to form a cluster. Then, the defects in the cluster are randomly combined, such as combining any two defects, any three defects, or any four defects, until all possible combinations are exhausted, thus obtaining various defect combinations. Next, the defect is removed from the sorted order. The above steps are repeated until the number of defects in the sorted order is less than or equal to two, indicating that no new defect combinations are generated, and then clustering stops.
[0089] Step 104: Inject each defect and each combination of defects into the baseline test case to generate variant test cases.
[0090] For each plugin class, the individual defect corresponding to that plugin class and the combined defect containing that individual defect are injected into the baseline test case corresponding to that plugin class, thereby generating variant test cases. Since the defects in the combined defects may belong to different plugin classes, after completing the defect injection for all baseline test cases, it is also necessary to deduplicate all variant test cases.
[0091] Optionally, step 104 may include: for each defect under each plugin class, injecting the defect into the baseline test cases assigned to that plugin class to generate a first variant test case; for each defect combination, injecting the defect combination into the baseline test cases assigned to each plugin class corresponding to the defect combination to generate a second variant test case. In embodiments of the present invention, both individual defects and combined defects are injected into the baseline test cases to ensure coverage of all scenarios. For each plugin class, each defect corresponding to that plugin class is injected into the baseline test case corresponding to that plugin class to generate a first variant test case; for each plugin class, combined defects containing the defects corresponding to that plugin class are injected into the baseline test cases corresponding to that plugin class to generate a second variant test case. The first variant test case and the second variant test case constitute a variant test case set.
[0092] Based on the various embodiments described above, it can be seen that the embodiments of the present invention solve the technical problems of scenario omission, excessive redundancy, and invalid test cases in the prior art by clustering the defects corresponding to each plugin class, determining the defect combinations based on the clustering results, and injecting each defect and defect combination into the baseline test cases. In scenarios where defects are deeply hidden, the embodiments of the present invention can deeply explore related defects through clustering algorithms, and use combined defects to mutate the baseline test cases, thereby quickly writing test cases for detectable defects and providing them to testers for reference, which helps improve software testing efficiency and quality. Especially when users' test case scenario analysis is incomplete, the test scope is unclear, and full testing is required, the embodiments of the present invention can significantly improve the quality of test case writing.
[0093] Figure 2 This is a flowchart of a method for generating interface test cases according to a possible embodiment of the present invention. As another embodiment of the present invention, such as... Figure 2 As shown, the method for generating interface test cases may include:
[0094] Step 201: Pull the gateway code to be tested from the gateway testing platform.
[0095] Step 202: Identify each plugin class in the gateway code and assign the baseline test cases to each plugin class.
[0096] Step 203: Obtain the defects corresponding to each of the plugin classes.
[0097] Step 204: Sort the defects in descending order of importance.
[0098] Step 205: Is the number of defects in the sorting less than or equal to two? If yes, proceed to step 206; otherwise, proceed to step 209.
[0099] Step 206: Cluster the defects in the ranking with the defects that have the highest importance in the ranking as the cluster center.
[0100] Step 207: Combine the defects within the cluster where the cluster center is located to obtain the defect combinations.
[0101] Step 208: Remove the most important defect from the sorting.
[0102] Step 209: Inject each defect and each combination of defects into the baseline test case to generate variant test cases.
[0103] For example, using a blacklist / whitelist plugin, if a user's accountId is added to the blacklist, the user should be able to call an API (authentication API) that should fail, but instead, the call succeeds. This indicates a flaw. Flaw description: When a user's accountId is added to the blacklist, the API call requires login status verification; therefore, the call should fail, but instead, it succeeds.
[0104] Therefore, after injecting the defect, the following variant test cases are generated:
[0105] 1. The identity authentication interface adds a user's accountId to a blacklist. When calling the interface, the cookie information corresponding to the accountId is passed in the header. The expected result is that the call fails.
[0106] 2. The identity authentication interface adds a user's accountId to a blacklist. When calling the interface, the cookie information corresponding to the accountId that is not in the blacklist is passed in the header. The expected result is a successful call.
[0107] 3. For non-authentication interfaces, add a user's accountId to a blacklist, and pass the cookie information corresponding to the accountId in the header when calling the interface. The expected result is a successful call.
[0108] 4. For non-authentication interfaces, add a user's accountId to a blacklist. When calling the interface, pass the cookie information corresponding to the accountId that is not in the blacklist in the header. The expected result is a successful call.
[0109] 5. For the identity authentication interface, if a user's accountId is added to the blacklist and the corresponding cookie information is passed in the header when calling the interface, the expected result is that the call will fail. If the user's accountId is removed from the blacklist and the corresponding cookie information is passed in the header when calling the interface, the expected result is that the call will succeed.
[0110] Furthermore, the specific implementation details of the method for generating interface test cases in one of the reference embodiments of the present invention have been described in detail in the above-described method for generating interface test cases, so the details will not be repeated here.
[0111] Figure 3 This is a flowchart of a method for generating interface test cases according to another possible embodiment of the present invention. As another embodiment of the present invention, such as... Figure 3 As shown, the method for generating interface test cases may include:
[0112] Step 301: Retrieve the gateway code to be tested from the gateway testing platform.
[0113] Step 302: Identify each plugin class in the gateway code and assign the baseline test cases to each plugin class.
[0114] Step 303: Cluster the defects corresponding to each plugin class, and determine the defect combinations based on the clustering results of each defect.
[0115] Step 304: Inject each defect and each combination of defects into the baseline test case to generate variant test cases.
[0116] Step 305: Use the branch coverage algorithm to determine whether the mutated test case can cover the gateway code; if yes, then end; if no, then proceed to step 306.
[0117] Step 306: Continue to inject defects into the baseline test cases.
[0118] To detect whether the test cases obtained from the current mutation can cover the gateway code, a score coverage algorithm can be used to calculate it. If the test cases obtained from the current mutation can cover the gateway code, the mutation ends. If the test cases obtained from the current mutation cannot cover the gateway code, the baseline test cases continue to be mutated.
[0119] In addition, the specific implementation details of the method for generating interface test cases in another reference embodiment of the present invention have been described in detail in the above-described method for generating interface test cases, so the details will not be repeated here.
[0120] Figure 4 This is a flowchart of a method for generating interface test cases according to another possible embodiment of the present invention. As another embodiment of the present invention, such as... Figure 4 As shown, the method for generating interface test cases may include:
[0121] Step 401: Pull the gateway code to be tested from the gateway testing platform.
[0122] Step 402: Identify each plugin class in the gateway code and assign the baseline test cases to each plugin class.
[0123] Step 403: Cluster the defects corresponding to each plugin class, and determine the defect combinations based on the clustering results of each defect.
[0124] Step 404: Inject each defect and each combination of defects into the baseline test case to generate variant test cases.
[0125] Step 405: Input the gateway code, the baseline test cases, and the variant test cases into the branch coverage algorithm to output the coverage of the gateway code and the uncovered branch statements.
[0126] Step 406: Determine whether the coverage of the gateway code is less than the coverage threshold; if not, end; if yes, proceed to step 407.
[0127] Step 407: Construct a new defect based on the plugin class to which the uncovered branch statement belongs.
[0128] After step 407, repeat steps 403-406 until the coverage of the gateway code is greater than or equal to the coverage threshold.
[0129] Branch coverage algorithm is a coverage criterion used in software testing to evaluate the extent to which test cases cover all branches (if statements, loops, etc.) in the code. The input to this algorithm includes gateway code and a test case set (including baseline and variant test cases). The output includes: the coverage percentage of the gateway code and uncovered branch statements (branch statements not covered by test cases, used to guide the supplementation and improvement of test cases). It should be noted that the branch conditions of the branch coverage algorithm can be pre-configured, such as if statements, for loops, and while loops.
[0130] The coverage threshold can be set according to business needs or development requirements, such as 80%, 85% or 92%, etc., and this embodiment of the invention does not limit it.
[0131] If the coverage of the gateway code is less than the coverage threshold, then based on the plugin class to which the uncovered branch statement belongs, and combined with the current defects and combined defects, the missing defects are analyzed, and a new defect is created. The new defect is then assigned to the plugin class, and steps 403-406 are repeated until the coverage of the gateway code is greater than or equal to the coverage threshold.
[0132] Furthermore, the specific implementation details of the method for generating interface test cases in another reference embodiment of the present invention have been described in detail in the above-described method for generating interface test cases, so the details will not be repeated here.
[0133] Figure 5 This is a schematic diagram of an apparatus for generating interface test cases according to an embodiment of the present invention. Figure 5As shown, the apparatus 500 for generating interface test cases includes a pull module 501, a classification module 502, a combination module 503, and a mutation module 504. The pull module 501 pulls the gateway code to be tested from the gateway testing platform. The classification module 502 identifies each plugin class in the gateway code and assigns baseline test cases to each plugin class. The combination module 503 clusters the defects corresponding to each plugin class and determines defect combinations based on the clustering results. The mutation module 504 injects each defect and each defect combination into the baseline test cases to generate mutated test cases.
[0134] Optionally, the combination module 503 is further configured to:
[0135] Obtain the defects corresponding to each of the aforementioned plugin classes;
[0136] Cluster the defects using any one of the defects as the cluster center;
[0137] Each defect within the cluster containing the cluster center is combined to obtain various defect combinations.
[0138] Optionally, the combination module 503 is further configured to:
[0139] Step a: Sort the defects in descending order of importance;
[0140] Step b: Cluster the defects in the ranking with the highest importance as the cluster center;
[0141] Step c: Combine the defects within the cluster where the cluster center is located to obtain the various defect combinations;
[0142] Step d: Remove the most important defects from the sorting.
[0143] Repeat steps b through d until the number of defects in the sorting is less than or equal to two.
[0144] Optionally, the mutation module 504 is further configured to:
[0145] For each defect under each plugin class, the defect is injected into the baseline test case assigned to the plugin class, thereby generating a first variant test case.
[0146] For each defect combination, the defect combination is injected into the baseline test cases that are assigned to the corresponding plugin classes of the defect combination, thereby generating a second variant test case.
[0147] Optionally, the mutation module 504 is further configured to:
[0148] A branch coverage algorithm is used to determine whether the mutated test case can cover the gateway code; if not, defects are injected into the baseline test case.
[0149] Optionally, the mutation module 504 is further configured to:
[0150] The gateway code, the baseline test cases, and the variant test cases are input into the branch coverage algorithm to output the coverage of the gateway code and the uncovered branch statements.
[0151] If the coverage is less than the coverage threshold, a new defect is constructed based on the plugin class to which the uncovered branch statement belongs, and the defect continues to be injected into the baseline test case.
[0152] Optionally, the mutation module 504 is further configured to:
[0153] Cluster the defects corresponding to each of the plugin classes, and determine the combination of defects based on the clustering results of each defect;
[0154] Each defect and each combination of defects is injected into the baseline test case to generate variant test cases.
[0155] It should be noted that the specific implementation details of the apparatus for generating interface test cases described in this invention have been described in detail in the method for generating interface test cases described above, so the details will not be repeated here.
[0156] Figure 6 An exemplary system architecture 600 is shown, in which the method or apparatus for generating interface test cases according to embodiments of the present invention can be applied.
[0157] like Figure 6 As shown, system architecture 600 may include terminal devices 601, 602, and 603, a network 604, and a server 605. Network 604 serves as the medium for providing communication links between terminal devices 601, 602, and 603 and server 605. Network 604 may include various connection types, such as wired or wireless communication links or fiber optic cables, etc.
[0158] 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 shopping applications, web browser applications, search applications, instant messaging tools, email clients, social media platform software, etc. (for example only).
[0159] Terminal devices 601, 602, and 603 can be various electronic devices with displays and web browsing capabilities, including but not limited to smartphones, tablets, laptops, and desktop computers.
[0160] Server 605 can be a server that provides various services, such as a backend management server that supports shopping websites browsed by users using terminal devices 601, 602, and 603 (this is just an example). The backend management server can analyze and process data such as received item information query requests, and then feed the processing results back to the terminal devices.
[0161] It should be noted that the method for generating interface test cases provided in this embodiment of the invention is generally executed by server 605, and correspondingly, the device for generating interface test cases is generally located in server 605. The method for generating interface test cases provided in this embodiment of the invention can also be executed by terminal devices 601, 602, and 603, and correspondingly, the device for generating interface test cases can be located in terminal devices 601, 602, and 603.
[0162] It should be understood that Figure 6 The number of terminal devices, networks, and servers shown is merely illustrative. Depending on implementation needs, any number of terminal devices, networks, and servers can be included.
[0163] The following is for reference. Figure 7 It shows a schematic diagram of the structure of a computer system 700 suitable for implementing a terminal device of the present invention. Figure 7 The terminal device shown is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of the present invention.
[0164] like Figure 7 As shown, the computer system 700 includes a central processing unit (CPU) 701, which can perform various appropriate actions and processes based on programs stored in read-only memory (ROM) 702 or programs loaded from storage section 708 into random access memory (RAM) 703. The RAM 703 also stores various programs and data required for the operation of the system 700. The CPU 701, ROM 702, and RAM 703 are interconnected via a bus 704. An input / output (I / O) interface 705 is also connected to the bus 704.
[0165] The following components are connected to the I / O interface 705: an input section 706 including a keyboard, mouse, etc.; an output section 707 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and speakers, 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, 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 disk, optical disk, magneto-optical disk, semiconductor memory, etc., is installed on the drive 710 as needed so that computer programs read from it can be installed into the storage section 708 as needed.
[0166] In particular, according to the embodiments disclosed in this invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments disclosed in this invention include a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication section 709, and / or installed from removable medium 711. When the computer program is executed by central processing unit (CPU) 701, it performs the functions defined above in the system of this invention.
[0167] It should be noted that the computer-readable medium shown in this 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 a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, 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, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this 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 this 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. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media can also be any computer-readable medium other than computer-readable storage media, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wireless, wire, optical fiber, RF, etc., or any suitable combination thereof.
[0168] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer programs according to various embodiments of the present invention. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram or flowchart, and combinations of blocks in a block diagram or flowchart, may be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0169] The modules described in the embodiments of the present invention can be implemented in software or hardware. The described modules can also be housed in a processor; for example, a processor can be described as including a pull module, a classification module, a combination module, and a mutation module, wherein the names of these modules do not necessarily limit the module itself.
[0170] In another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiments; or it may exist independently and not assembled 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 implements the following method: pulling gateway code to be tested from a gateway testing platform; identifying each plugin class in the gateway code and assigning baseline test cases to each plugin class; clustering each defect corresponding to each plugin class, and determining each defect combination based on the clustering results of each defect; and injecting each defect and each defect combination into the baseline test cases respectively, thereby generating variant test cases.
[0171] In another aspect, embodiments of the present invention also provide a computer program product, including a computer program that, when executed by a processor, implements the methods described in any of the above embodiments.
[0172] According to the technical solution of this invention, by clustering the defects corresponding to each plugin class, determining the defect combinations based on the clustering results, and injecting each defect and defect combinations into the baseline test cases to generate mutated test cases, this invention overcomes the technical problems of scenario omission, excessive redundancy, and invalid test cases in the prior art. In scenarios where defects are deeply hidden, this invention can deeply uncover related defects through clustering algorithms, using combined defects to mutate the baseline test cases, thereby quickly writing test cases for detectable defects and providing them to testers for reference, which helps improve software testing efficiency and quality. Especially when users' test case scenario analysis is incomplete, the test scope is unclear, or full-scale testing is required, this invention can significantly improve the quality of test case writing.
[0173] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can occur depending on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.
Claims
1. A method for generating interface test cases, characterized in that, include: Pull the gateway code to be tested from the gateway testing platform; Identify the various plugin classes in the gateway code and assign the baseline test cases to each of the plugin classes; Cluster the defects corresponding to each of the plugin classes, and determine the combination of defects based on the clustering results of each defect; Each defect and combination of defects is injected into the baseline test case to generate variant test cases; Specifically, the defects corresponding to each plugin class are clustered, and based on the clustering results of each defect, combinations of defects are determined, including: Obtain the defects corresponding to each of the aforementioned plugin classes; Cluster the defects using any one of the defects as the cluster center; Each defect within the cluster containing the cluster center is randomly combined until all possible combinations are exhausted, thus obtaining the various defect combinations; Each defect and combination of defects is injected into the baseline test cases to generate variant test cases, including: For each defect under each plugin class, the defect is injected into the baseline test case assigned to the plugin class, thereby generating a first variant test case. For each defect combination, the defect combination is injected into the baseline test cases that are assigned to the corresponding plugin classes of the defect combination, thereby generating a second variant test case.
2. The method according to claim 1, characterized in that, After injecting each defect and each combination of defects into the baseline test cases to generate variant test cases, the process further includes: A branch coverage algorithm is used to determine whether the mutated test case can cover the gateway code; if not, defects are injected into the baseline test case.
3. The method according to claim 2, characterized in that, A branch coverage algorithm is used to determine whether the mutated test cases can cover the gateway code; If not, then continue to inject defects into the baseline test cases, including: The gateway code, the baseline test cases, and the variant test cases are input into the branch coverage algorithm to output the coverage of the gateway code and the uncovered branch statements. If the coverage is less than the coverage threshold, a new defect is constructed based on the plugin class to which the uncovered branch statement belongs, and the defect continues to be injected into the baseline test case.
4. The method according to claim 3, characterized in that, Continue to inject defects into the baseline test cases, including: Cluster the defects corresponding to each of the plugin classes, and determine the combination of defects based on the clustering results of each defect; Each defect and each combination of defects is injected into the baseline test case to generate variant test cases.
5. An apparatus for generating interface test cases, characterized in that, include: The pull module is used to pull the gateway code that needs to be tested from the gateway testing platform; The classification module is used to identify the various plugin classes in the gateway code and classify the baseline test cases into the various plugin classes; The combination module is used to cluster the defects corresponding to each of the various plug-in classes, and determine the combination of each defect based on the clustering results of each defect; The mutation module is used to inject the individual defects and combinations of the individual defects into the baseline test cases, thereby generating mutated test cases; The combined module is also used for: Obtain the defects corresponding to each of the aforementioned plugin classes; Cluster the defects using any one of the defects as the cluster center; Each defect within the cluster containing the cluster center is randomly combined until all possible combinations are exhausted, thus obtaining the various defect combinations; The mutation module is also used for: For each defect under each plugin class, the defect is injected into the baseline test case assigned to the plugin class, thereby generating a first variant test case. For each defect combination, the defect combination is injected into the baseline test cases that are assigned to the corresponding plugin classes of the defect combination, thereby generating a second variant test case.
6. An electronic device, characterized in that, include: One or more processors; 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 as described in any one of claims 1-4.
7. A computer-readable medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the method as described in any one of claims 1-4.
8. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the method as described in any one of claims 1-4.
Citation Information
Patent Citations
Program code variation testing method and device
CN114238150A
Test case generation method, test case generation device and storage medium
CN115757188A