Method and apparatus for generating test cases
By combining combinatorial generation algorithms and adaptive random generation algorithms, test cases are generated for different input parameter types, resolving the contradiction between generation time and comprehensiveness, and achieving efficient test case generation.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- DOUYIN VISION CO LTD
- Filing Date
- 2021-07-16
- Publication Date
- 2026-07-14
AI Technical Summary
Existing technologies suffer from problems such as long generation time and poor comprehensiveness when generating test cases, making it difficult to ensure the comprehensiveness of test cases while maintaining the generation time.
A combination of a combined generation algorithm and an adaptive random generation algorithm is used to generate a first parameter combination for input parameters with a small number of possible values, and a second parameter combination for input parameters with a large number of possible values. Test cases are generated by combining these methods.
It enables the generation of comprehensive test cases in a shorter time, ensuring that the test cases cover all possible combinations of input parameters and improving testing efficiency.
Smart Images

Figure CN115617646B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of automated testing technology, and in particular to a method and device for generating test cases. Background Technology
[0002] In the field of automated testing technology, test cases can be pre-generated for a test target. The test target can be a function, interface, etc., and the test cases can include input parameters that need to be entered into the test target. After the development of the test target is completed, the test cases can be used to test the test target. For example, the input parameters from the test cases can be input into the test target so that the interface processes the input parameters and obtains a result. Based on the processing result, it can be determined whether the interface is functioning correctly and whether its logic is correct.
[0003] The aforementioned test cases need to be pre-generated, and different generation algorithms result in varying generation times. Furthermore, different generation algorithms cover different test scenarios, meaning the comprehensiveness of the test cases varies. Typically, to generate test cases that cover more test scenarios—that is, to ensure good comprehensiveness—a longer generation time is required. Therefore, ensuring both short generation time and good comprehensiveness of test cases becomes a pressing issue. Summary of the Invention
[0004] This disclosure provides a method and apparatus for generating test cases, which can ensure that the generation time of test cases is short and the comprehensiveness is good.
[0005] In a first aspect, embodiments of this disclosure provide a method for generating test cases, comprising:
[0006] Determine the possible values for at least two input parameters of the test target;
[0007] For at least one of the at least two input parameters, at least one first parameter combination is generated based on the possible value combinations of the first input parameter. The first input parameter is an input parameter whose number of possible values is less than a first preset number. Each first parameter combination includes one possible value of each first input parameter.
[0008] For at least one of the at least two input parameters, at least one combination of second parameters is randomly generated based on the possible values of the second input parameter. The second input parameter is an input parameter whose number of possible values is greater than or equal to a first preset number. Each combination of second parameters includes one possible value of each second input parameter.
[0009] Test cases for the test target are generated based on each combination of the first parameter and each combination of the second parameter.
[0010] Secondly, embodiments of this disclosure provide a test case generation apparatus, comprising:
[0011] The possible value determination module is used to determine the possible values corresponding to at least two input parameters of the test target.
[0012] The first parameter combination generation module is used to generate at least one first parameter combination based on the possible value combinations of the first input parameter for at least one of the at least two input parameters, wherein the first input parameter is an input parameter whose number of possible values is less than a first preset number, and each first parameter combination includes one possible value of each first input parameter;
[0013] The second parameter combination generation module is used to randomly generate at least one second parameter combination based on the possible values of the second input parameter for at least one of the at least two input parameters. The second input parameter is an input parameter whose number of possible values is greater than or equal to a first preset number. Each second parameter combination includes one possible value of each second input parameter.
[0014] The test case generation module is used to generate test cases for the test target based on each combination of the first parameter and each combination of the second parameter.
[0015] Thirdly, embodiments of this disclosure provide an electronic device, including: at least one processor and a memory;
[0016] The memory stores computer-executed instructions;
[0017] The at least one processor executes computer execution instructions stored in the memory, causing the electronic device to perform the method as described in the first aspect.
[0018] Fourthly, embodiments of this disclosure provide a computer-readable storage medium storing computer-executable instructions that, when executed by a processor, cause a computing device to implement the method described in the first aspect.
[0019] Fifthly, embodiments of this disclosure provide a computer program for implementing the method as described in the first aspect.
[0020] This disclosure provides a method and apparatus for generating test cases. The method includes: determining the possible values corresponding to at least two input parameters of a test target; for at least one first input parameter among the at least two input parameters, generating at least one first parameter combination based on the possible value combinations of the first input parameter, wherein the number of possible values of the first input parameter is less than a first preset number, and each first parameter combination includes one possible value of each first input parameter; for at least one second input parameter among the at least two input parameters, randomly generating at least one second parameter combination based on the possible values of the second input parameter, wherein the number of possible values of the second input parameter is greater than or equal to a first preset number, and each second parameter combination includes one possible value of each second input parameter; and generating test cases for the test target based on each first parameter combination and each second parameter combination. This disclosure can, for first input parameters with a small number of possible values, ensure that the first parameter combination includes various combinations of its possible values by combining them, which helps to ensure the comprehensiveness of the first parameter combination. In addition, since the number of possible values of the first input parameter is small, the number of first parameter combinations is small, and the time to generate the first parameter combination is short. For the second input parameter, which has a large number of possible values, a random approach is used to ensure a short generation time for the second parameter combinations. Furthermore, the generated second parameter combinations are relatively evenly spaced, resulting in a more uniform distribution of the second input parameter and preventing the omission of some values due to concentrated values, thus ensuring the comprehensiveness of the second parameter combinations. In this way, the generation time of test cases is short and the comprehensiveness is good. Attached Figure Description
[0021] To more clearly illustrate the technical solutions in the embodiments of this disclosure 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 some embodiments of this disclosure. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0022] Figure 1 This is a schematic diagram of an automated testing process.
[0023] Figure 2 This is a flowchart illustrating the steps of a test case generation method provided in an embodiment of this disclosure;
[0024] Figure 3 This is a curve showing the number of use cases corresponding to the combined generation algorithm provided in this embodiment;
[0025] Figure 4 This is the generation time curve corresponding to the combined generation algorithm provided in this embodiment of the disclosure;
[0026] Figure 5 This is a structural block diagram of a test case generation device provided in an embodiment of this disclosure;
[0027] Figure 6 This is a structural block diagram of an electronic device provided in an embodiment of this disclosure. Detailed Implementation
[0028] To make the objectives, technical solutions, and advantages of the embodiments of this disclosure clearer, the technical solutions of the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this disclosure, and not all embodiments. Based on the embodiments of this disclosure, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this disclosure.
[0029] The embodiments disclosed herein can be applied to automated testing. Figure 1 This is a schematic diagram of an automated testing process. (Refer to...) Figure 1 As shown, automated testing can mainly include the following steps: software development, generating test cases, and testing using test cases.
[0030] In this context, software development can refer to developing software code to implement a function; this software code can be a function, method, or interface. In this embodiment, the software code can be referred to as the test target, and the test target has input parameters.
[0031] Generating test cases means creating test cases based on the possible values of the input parameters, so that the input parameters included in the test cases can cover as many possible values as possible, ensuring the comprehensiveness of the test cases.
[0032] Testing through test cases involves inputting the input parameters from the test cases into the test target, allowing the test target to process the data and obtain the results. The correctness of the test target's processing logic can then be determined based on the results. For example, if the test target is used to query data, and the input parameters are the conditions for querying the data, these conditions can be input into the test target to obtain the queried data. Whether the queried data matches the expected data can then be used to determine if the test target's processing logic is correct.
[0033] In the existing technology, there are various methods for generating test cases, including both manual generation and machine generation. Machine generation algorithms may include, but are not limited to, combined generation algorithms, random generation algorithms, and adaptive random generation algorithms.
[0034] The aforementioned combinatorial generation algorithm can generate test cases by arranging and combining the possible values of multiple input parameters in various ways. For example, given three input parameters A, B, and C, where input parameter A has two possible values A1 and A2, input parameter B has one possible value B1, and input parameter C has three possible values C1, C2, and C3, the test cases that can be obtained through the combinatorial generation algorithm include: (A1, B1, C1), (A1, B1, C2), (A1, B1, C3), (A2, B1, C1), (A2, B1, C2), and (A2, B1, C3).
[0035] However, since the above-mentioned combination generation algorithm needs to combine the possible values of different input parameters, when the number of possible values is large, a large number of test cases are generated, and the time consumed to generate all test cases is long.
[0036] The random generation algorithm described above can randomly combine multiple input parameters. For example, for the input parameters A, B, and C, their corresponding possible values can be randomly combined. That is, a test case is generated by randomly selecting one possible value from the possible values of input parameters A, B, and C. The first random combination generates (A2, B1, C3), the second random combination generates (A1, B1, C2), the third random combination generates (A2, B1, C1), and so on.
[0037] However, since the above random generation algorithm randomly selects a value from the available values for each combination, after multiple combinations, there may be cases where the randomly selected values are similar or even repeated. This can lead to a large number of similar test cases when generating a large number of test cases, resulting in poor comprehensiveness.
[0038] The aforementioned adaptive randomization algorithm is an improvement upon the adaptive randomization algorithm. Each time a test case needs to be generated, a randomization algorithm generates multiple candidate parameter combinations, from which one that differs significantly from existing test cases is selected as the current test case. This process is repeated continuously to obtain a large number of test cases.
[0039] However, the aforementioned adaptive random generation algorithm also obtains candidate parameter combinations through random combinations, and cannot use various possible combinations of input parameter values as test cases, thus its comprehensiveness is also poor.
[0040] To ensure short test case generation time and comprehensiveness, different algorithms can be used to generate test cases for different input parameters. Therefore, selecting the appropriate algorithm for generating test cases based on different input parameters is the main issue to consider.
[0041] After studying the input parameters, the applicant discovered that the processing logic of the test target may differ depending on the number of possible values of the input parameters.
[0042] For input parameters with a limited number of possible values, the test target typically uses different branch statements to process each possible value separately; that is, the test target uses different processing logic for different possible values. Therefore, for input parameters with few possible values, to ensure that each branch statement is tested (i.e., the comprehensiveness of the test cases), we can ensure that all different values of the input parameter and various combinations of values of different input parameters appear in the test cases. This embodiment uses the combination generation algorithm corresponding to S102 to generate a first parameter combination for input parameters with few possible values, ensuring that all combinations of different values of this input parameter appear in the test cases. Furthermore, for input parameters with few possible values, the number of corresponding test cases is smaller, thus shortening the test case generation time.
[0043] The function of the above branch statements is related to the type of input parameters, and can be mainly divided into the following three scenarios.
[0044] In the first scenario, the input parameter is a numerical value. The branching statement is used to perform different processing in the following different situations: the numerical value is a specific value, it is not a specific value, it is within a specific range, and it is not within a specific range.
[0045] In the second scenario, the input parameter is a string. The branching statement is used to perform different processing in the following different situations: the string is a specific character, it is not a specific character, it includes a specific character, it does not include a specific character, its length is within a specific range, its length is not within a specific range, it is empty, and it is not empty.
[0046] In the third scenario, the input parameter is an array. The branching statement is used to perform different processing in the following different situations: the array includes a specific element, does not include a specific element, the element is within a specific range, the element is not within a specific range, the length is within a specific range, the length is not within a specific range, it is empty, and it is not empty.
[0047] For input parameters with many possible values, the probability of the test target using branching statements to process different possible values is relatively low; the test target usually applies the same processing logic to different possible values. It can be seen that regardless of whether the value of this input parameter is the same in the test cases, the test cases can verify whether the test target's processing of this input parameter is correct. Therefore, the value of this input parameter has a relatively small impact on the comprehensiveness of the test cases. For this type of input parameter, we can use an algorithm with high generation efficiency and short generation time to generate test cases, and ensure that the value of this input parameter is evenly distributed across the domain in different test cases; it is not necessary to use all combinations of different possible values of this input parameter as test cases. This embodiment uses the adaptive random generation algorithm corresponding to S103 to generate a second parameter combination for input parameters with many possible values. Finally, test cases are generated based on the first parameter combination and the second parameter combination.
[0048] The technical solutions of the present disclosure and how the technical solutions of the present disclosure solve the above-mentioned technical problems are described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of the present disclosure will now be described with reference to the accompanying drawings.
[0049] Figure 2 This is a flowchart illustrating the steps of a test case generation method provided in this embodiment of the disclosure. (Refer to...) Figure 2 As shown, the method for generating this test case includes:
[0050] S101: Determine the possible values for at least two input parameters of the test target.
[0051] The test target can be any software object with input parameters, including but not limited to functions, methods, and interfaces. For example, an interface can be an HTTP (Hypertext Transfer Protocol) request or an RPC (Remote Procedure Call) request.
[0052] The aforementioned interfaces can be interfaces within microservices. Each microservice will provide dozens of interfaces for upstream services to call, and each service may include hundreds of such microservices.
[0053] Test cases are used to test the test target. Each test case includes the possible values for each input parameter of the test target.
[0054] The input parameters for the aforementioned test target can have one or more possible values, which are any numerical values within the domain of the input parameter. These values can be continuous or discrete. The possible values of the input parameters can be obtained in two ways.
[0055] The first method involves retrieving the possible values of the input parameters from the call log of the test target. Since the test target can be invoked, the values of the input parameters used when invoking the test target can be recorded in the call log, and these values can then be considered as possible values. Because duplicate values may be used during the call, the possible values retrieved from the online system need to be deduplicated.
[0056] The second method can obtain the possible values based on the defined range of the input parameters, and generate a number of possible values evenly within the range.
[0057] The range of values defined in the above call records and input parameters can be called the preset data source, which is the source used to obtain the possible values.
[0058] Optionally, firstly, the preset data source can be converted from a first form to a key-value pair form, which includes one of the following: structured form or binary form; then, the possible values corresponding to at least two input parameters of the test target can be extracted from the preset data source in key-value pair form.
[0059] In this key-value pair format, the correspondence between input parameters and their possible values is represented using a one-to-one mapping between keywords and values. A commonly used key-value pair format is "key:value", where the key is the keyword, i.e., the input parameter in this embodiment, and the value is the possible value of the input parameter in this embodiment. The key-value pair format is widely used, for example, in HTTP header information.
[0060] Structured representations use predefined structures to represent the correspondence between input parameters and their possible values. Examples include JSON (JavaScript Object Notation) and XML (Extensible Markup Language). Taking JSON as an example, a structured representation can be as follows:
[0061] {
[0062] “a1”:{
[0063] “b1”: 0,
[0064] “c1”: [1, 2, 3]
[0065] “d1”: “e1”
[0066] },
[0067] “a2”:{
[0068] “b2”: 1,
[0069] “c2”: [4, 5, 6],
[0070] “d2”: “e2”
[0071] }
[0072] }
[0073] As can be seen, the above structure is multi-layered and nested. The corresponding value cannot be obtained directly using a single keyword; instead, it requires multiple retrievals based on the nesting relationship. For example, to obtain the value of "a1.b1", one must first obtain the value of a1. Since the value of a1 is a structured representation, it is necessary to retrieve the value of b1 again from the value of a1.
[0074] The process of retrieving values from the structured correspondence described above is quite complex. The structured form can be converted into the following key-value pair format:
[0075] {
[0076] “a1.b1”: 0,
[0077] “a1.c1”: [1, 2, 3],
[0078] “a1.d1”:“e”
[0079] “a2.b2”: 1,
[0080] “a2.c2”: [4, 5, 6],
[0081] “a2.d2”:“e2”
[0082] }
[0083] As can be seen, the above structure is not nested; it has only one level. We can directly obtain the corresponding value using the keyword "a1.b1". Furthermore, the key-value pair representation of the input parameters and their possible values has a one-to-one correspondence, which facilitates the generation of test cases.
[0084] The binary representation uses binary representations to show the correspondence between input parameters and their possible values. Examples include ProtoBuf (protocol buffer) and BSON (binary JSON).
[0085] S102: For at least one first input parameter among at least two input parameters, generate at least one first parameter combination based on the possible value combinations of the first input parameter, wherein the first input parameter is an input parameter whose number of possible values is less than a first preset number, and each first parameter combination includes one possible value of each first input parameter.
[0086] The input parameters may or may not include a first input parameter, may include one first input parameter, or may include at least two first input parameters. The input parameter used in the branch processing of the test objective is determined as the first input parameter. For example, the input parameter on which a conditional statement is based is used as the first input parameter.
[0087] This embodiment employs a combination generation algorithm to generate at least one combination of first parameters based on the possible values of the first input parameter.
[0088] If the first input parameter is not present in the input parameters, S102 is not performed to generate the first parameter combination. The first parameter combination can be empty.
[0089] When the input parameters include only one first input parameter, the combinatorial generation algorithm can use the possible values of that first input parameter as the values of the first parameter combinations. The number of possible values for the first input parameter is equal to the number of first parameter combinations. It can be understood that a combination of input parameters can be called a special combinatorial process.
[0090] When the input parameters include at least two first input parameters, the possible values of different first input parameters can be combined to obtain a first parameter combination. In this embodiment of the disclosure, the first parameter combination can be generated using a pairwise combination algorithm. The pairwise combination algorithm is based on the following two assumptions: D1, any two input parameters are orthogonal; D2, 73% of defects are caused by the interaction of one or two input parameters, and 19% of defects are caused by the interaction of three input parameters. Thus, the pairwise combination algorithm generates test cases based on the interaction of two input parameters.
[0091] Below is an example of the test case generation process for the Pairwise combination algorithm. Assume the test target has three input parameters A, B, and C, where A can take values A1 and A2, B can take values B1, B2, and B3, and C can take values C1, C2, C3, and C4. The Pairwise combination algorithm can generate the following test cases: {A1, B3, C1}, {A1, B1, C4}, {A2, B1, C3}, {A2, B2, C4}, {A1, B2, C3}, {A2, B2, C1}, {A2, B1, C1}, {A2, B3, C2}, {A1, B2, C2}, {A1, B3, C4}, {A2, B3, C3}, {A1, B1, C2}.
[0092] As can be seen, in the above test cases, every possible combination of values for any two input parameters appeared at least once.
[0093] Figure 3 This is a curve showing the number of use cases corresponding to the combined generation algorithm provided in this embodiment. Figure 4 This is the generation time curve corresponding to the combined generation algorithm provided in this embodiment. Figure 3 and Figure 4 Test cases are generated based on the fact that all possible combinations of values for any two input parameters occur at least once.
[0094] Reference Figure 3 As shown, the horizontal axis corresponding to the solid line represents the number of input parameters, the horizontal axis corresponding to the dashed line represents the number of possible values, and the vertical axis represents the number of test cases. It can be seen that as the number of input parameters increases, the number of test cases increases significantly, while as the number of possible values increases, the number of test cases increases only slightly.
[0095] Reference Figure 4 As shown, the horizontal axis corresponding to the solid line represents the number of input parameters, the horizontal axis corresponding to the dashed line represents the number of possible values, and the vertical axis represents the generation time of test cases. It can be seen that as the number of input parameters increases, the generation time required to generate all test cases increases significantly, while as the number of possible values increases, the generation time required to generate all test cases increases only slightly.
[0096] It can be seen that the combinatorial generation algorithm is suitable for input parameters with a small number of possible values.
[0097] S103: For at least one second input parameter among at least two input parameters, at least one combination of second parameters is randomly generated based on the possible values of the second input parameter. The second input parameter is an input parameter whose number of possible values is greater than or equal to a first preset number. Each combination of second parameters includes one possible value of each second input parameter.
[0098] The input parameters may or may not include a second input parameter. Unused input parameters from branch processing within the test objective are designated as the second input parameters.
[0099] This embodiment employs a random generation algorithm to generate the second parameter combination. In other words, the possible values of the second input parameters can be randomly combined to obtain the second parameter combination. For example, if there are N second input parameters, each time a second parameter combination is generated, one possible value can be randomly selected from the possible values of each second input parameter as the value of that second input parameter in the second parameter combination.
[0100] Furthermore, an adaptive random generation algorithm can be used to generate the second parameter combination. This algorithm is based on the assumption that input parameters causing test failures typically have adjacent values; similarly, input parameters causing test success also typically have adjacent values. Thus, when generating a new second parameter combination, the algorithm aims to maximize the distance between the new combination and the combination obtained in the previous iteration.
[0101] When there is no second input parameter, the second parameter combination is not generated through S103, and the second parameter combination is empty.
[0102] When at least one second input parameter exists, at least one combination of second parameters needs to be generated through multiple iterations. In each iteration, at least two candidate parameter combinations are randomly generated based on the possible values of the second input parameter. Each candidate parameter combination includes one possible value for each second input parameter. For each candidate parameter combination, a reference distance is determined between the candidate parameter combination and at least one second parameter combination obtained in the previous iteration. The candidate parameter combination corresponding to the largest reference distance and the second parameter combination obtained in the previous iteration are determined as the second parameter combination obtained in this iteration, and the process proceeds to the next iteration.
[0103] In the process of generating candidate parameter combinations described above, for each second input parameter, a possible value can be randomly selected from its corresponding possible values to form a candidate parameter combination. In this way, multiple candidate parameter combinations can be generated.
[0104] To ensure the uniformity of second input parameter values across different second parameter combinations, during the selection process, the candidate parameter combination with the largest reference distance from at least one second parameter combination obtained in the previous iteration can be chosen as the newly generated second parameter combination. This ensures that the second input parameters included in the second parameter combination take as many possible values as possible, avoiding value duplication and thus guaranteeing the comprehensiveness of the test cases.
[0105] For each candidate parameter combination, its reference distance to at least one second parameter combination obtained in the previous iteration can be determined based on the distance between the values of each second input parameter in the candidate parameter combination and the values in each second parameter combination. Specifically, firstly, the distance between the values of each second input parameter in the candidate parameter combination and the values in each second parameter combination is determined as the first distance between each second input parameter and each second parameter combination; then, for each second input parameter, a second distance is determined based on the first distance between the second input parameter and each second parameter combination; finally, the reference distance between the candidate parameter combination and at least one second parameter combination is determined based on the second distance of each second input parameter.
[0106] Wherein, the aforementioned second distance can be the sum, average, maximum, minimum, weighted sum, or weighted average of the first distances corresponding to the second input parameters and each combination of the second parameters.
[0107] The reference distance mentioned above can be the sum, average, maximum, minimum, weighted sum, or weighted average of the second distances of each of the second input parameters. When the reference distance is the weighted sum of each of the second input parameters, it can be calculated using the following formula:
[0108] (1)
[0109] in, The reference distance between at least one combination of second parameters and candidate combinations of parameters, where I is the number of second input parameters. The second distance is the second distance of the i-th second input parameter. is the weight coefficient of the i-th second input parameter.
[0110] Based on the above formula, adjustments can be made. This allows for flexible adjustment of the influence of different second input parameters on the reference distance. We can set larger weights for second input parameters that are prone to causing testing errors, and smaller weights for those that are less likely to cause errors. This minimizes the number of second parameter combinations while ensuring their comprehensiveness.
[0111] The calculation method for the first distance mentioned above is related to the type of each second input parameter. Each second input parameter can be of any of the following types: numeric type, string type (including character type), an array containing string elements, or an array containing numeric elements.
[0112] When the second input parameter is a string, the Lewinstein distance between the value of the second input parameter in the candidate parameter combination and the value in each second parameter combination is determined as the first distance between the second input parameter and each second parameter combination. Therefore, the aforementioned determination of the second distance based on the first distance, and the determination of the reference distance based on the second distance, that is, determining the reference distance between the candidate parameter combination and at least one second parameter combination based on the Lewinstein distance between the value of each second input parameter in the candidate parameter combination and the value in each second parameter combination.
[0113] When determining the reference distance based on the aforementioned Lewinstein distance, it can be calculated according to formula (1), which is to perform a weighted summation of the Lewinstein distances between the values of different second input parameters in the second parameter combinations and the values in the candidate parameter combinations. Specifically, firstly, the Lewinstein distance between the value of each second input parameter in the candidate parameter combination and the value in each second parameter combination is determined as the first distance between each second input parameter and each second parameter combination; then, for each second input parameter, the second distance of the second input parameter is determined based on the first distance between the second input parameter and each second parameter combination; finally, the second distances of different second input parameters are weighted and summed to obtain the reference distance between the candidate parameter combination and at least one second parameter combination.
[0114] It should be noted that the Lewinstein distance between the value of the second input parameter in a candidate parameter combination and the value in a second parameter combination is the Lewinstein distance between the two strings. One string is the value of the second input parameter in a candidate parameter combination, and the other string is the value of the second input parameter in a second parameter combination. The Lewinstein distance between two strings can be the minimum number of character edits required to modify one string into another. Character edits include, but are not limited to, deletion, insertion, and replacement. For example, the process of modifying the string "kitten" into "sitting" can include: first, replacing "k" with "s" in "kitten" to get "sitten"; then, replacing "i" with "e" in "sitten" to get "sittin"; finally, inserting "g" at the end of "sittin" to get "sitting". It can be seen that the process of modifying "kitten" into "sitting" involves three character edits, so the Lewinstein distance between "kitten" and "sitting" is 3. When the second input parameter is an array containing string-type elements, firstly, the Lewinstein distance between the value of each element in each second parameter combination obtained in the previous iteration and the value in the candidate parameter combination can be determined; then, for each second input parameter, based on the Lewinstein distances corresponding to each element included in the second input parameter, a first distance between the second input parameter and each second parameter combination can be determined. This first distance can be the sum, average, maximum, minimum, weighted sum, or weighted average of the Lewinstein distances between the values of each element included in the second input parameter in each second parameter combination and the values in the candidate parameter combination.
[0115] Based on the first distance mentioned above, the second distance can be determined, and then a reference distance can be determined based on the second distance. Therefore, the process of determining the first distance, determining the second distance based on the first distance, and then determining the reference distance based on the second distance is equivalent to determining the reference distance between the candidate parameter combination and at least one second parameter combination based on the Lewinstein distances corresponding to each element.
[0116] Here, the aforementioned element items are each element item in each of the second input parameters. The Lewinstein distance between the value of an element item in each combination of second parameters and the value in each combination of candidate parameters is the Lewinstein distance between the two strings. One string represents the value of the element item in a combination of second parameters, and the other string represents the value of the element item in a combination of candidate parameters. The Lewinstein distance between the two strings can be explained in detail above, and will not be repeated here.
[0117] Optionally, after obtaining the Lewinstein distances for each element, the Lewinstein distances of all elements can be summed, averaged, weighted averaged, and weighted summed again to obtain the reference distance between the candidate parameter combination and at least one second parameter combination. It is not necessary to determine the first distance, second distance, and reference distance in the order described above.
[0118] When the second input parameter is a numerical value, the first distance between each second input parameter and each second parameter combination can be determined based on the difference between the value of the second input parameter in each second parameter combination obtained in the previous iteration and the value in the candidate parameter combination.
[0119] When the second input parameters are all arrays containing numeric elements, firstly, the difference between the value of each element in each second parameter combination obtained in the previous iteration and the value in the candidate parameter combination can be determined; then, for each second input parameter, based on the difference between the value of each element in each second parameter combination and the value in the candidate parameter combination, a first distance between the value of the second input parameter in each second parameter combination and the value in the candidate parameter combination can be the sum, average, weighted average, weighted sum, maximum, or minimum value of the difference.
[0120] It should be noted that the embodiments of this disclosure generate a second parameter combination from the second input parameter using the aforementioned adaptive random generation algorithm. In the prior art, because the adaptive random generation algorithm can only calculate distances for numeric input parameters, it can only be used to generate test cases for numeric input parameters and cannot generate test cases for string input parameters. Furthermore, since interface input parameters are typically discrete, or even string-based, the adaptive random generation algorithm cannot be applied to the test case generation process for interfaces.
[0121] In this embodiment of the disclosure, the Lewinstein distance can be calculated for the second input parameter of the string in the adaptive random generation algorithm, so that the adaptive random generation algorithm can be applied to the test case generation process of the interface.
[0122] S104: Generate test cases for the test target based on each combination of the first parameter and each combination of the second parameter.
[0123] The first parameter combination includes a first input parameter, and the second parameter combination includes a second input parameter.
[0124] When at least two input parameters include only the first input parameter, the first parameter combination is generated via S102, and the second parameter combination is empty. Therefore, the test case is the first parameter combination.
[0125] When at least two input parameters include only the second input parameter, only the second parameter combination is generated via S103, and the first parameter combination is empty. Therefore, the test case is the second parameter combination.
[0126] When at least two input parameters simultaneously include both the first and second input parameters, a first parameter combination is generated via S102, and a second parameter combination is generated via S103. Therefore, the test case is the Cartesian product of the first and second parameter combinations, also known as the Cartesian product or direct product. For example, there are two first parameter combinations X1 and X2: X1 = {a1, b1}, X2 = {a2, b2}, and three second parameter combinations Y1, Y2, and Y3: Y1 = {c1, d1}, Y2 = {c2, d2}, Y3 = {c3, d3}. Here, a1 and a2 are the values of input parameter a in X1 and X2 respectively, b1 and b2 are the values of input parameter b in X1 and X2 respectively, c1, c2, and c3 are the values of input parameter c in Y1, Y2, and Y3 respectively, and d1, d2, and d3 are the values of input parameter d in Y1, Y2, and Y3 respectively. Therefore, the test cases can include the following six: {X1, Y1}={a1, b1, c1, d1}, {X1, Y2}={a1, b1, c2, d2}, {X1, Y3}={a1, b1, c3, d3}, {X2, Y1}={a2, b2, c1, d1}, {X2, Y2}={a2, b2, c2, d2}, {X2, Y3}={a2, b2, c3, d3}.
[0127] It should be noted that if, after obtaining the possible values of the input parameters, the correspondence between the input parameters and the possible values is converted from the first form to the key-value pair form, then after generating test cases through S104, the correspondence between the input parameters and the possible values in the test cases can be converted from the key-value pair form to the first form first, and then the test target can be tested through the test cases of the test target.
[0128] Understandably, when testing a test target using test cases, the input parameters from the test cases need to be input into the test target. Since the correspondence between input parameters and their possible values that the test target can recognize is in its first form, we convert it to key-value pair format for easier test case generation. Therefore, before testing, the correspondence needs to be converted to a form that the test target can recognize, that is, a predefined form by the test target.
[0129] Corresponding to the test case generation method in the above embodiment, Figure 5 This is a structural block diagram of a test case generation apparatus provided in an embodiment of this disclosure. For ease of explanation, only the parts relevant to the embodiments of this disclosure are shown. (Refer to...) Figure 5 The test case generation device 200 includes: a possible value determination module 201, a first parameter combination generation module 202, a second parameter combination generation module 203, and a test case generation module 204.
[0130] The possible value determination module 201 is used to determine the possible values corresponding to at least two input parameters of the test target.
[0131] The first parameter combination generation module 202 is used to generate at least one first parameter combination based on the possible value combinations of the first input parameter for at least one of the at least two input parameters, wherein the first input parameter is an input parameter whose number of possible values is less than a first preset number, and each first parameter combination includes one possible value of each first input parameter.
[0132] The second parameter combination generation module 203 is used to randomly generate at least one second parameter combination based on the possible values of the second input parameter for at least one of the at least two input parameters. The second input parameter is an input parameter whose number of possible values is greater than or equal to a first preset number. Each second parameter combination includes one possible value of each second input parameter.
[0133] The test case generation module 204 is used to generate test cases for the test target based on each of the first parameter combinations and each of the second parameter combinations.
[0134] Optionally, the second parameter combination generation module 203 is further configured to: in each iteration, randomly generate at least two candidate parameter combinations based on the possible values of the second input parameter, each candidate parameter combination including one possible value of each second input parameter; for each candidate parameter combination, determine a reference distance between the candidate parameter combination and at least one second parameter combination obtained in the previous iteration; and determine the candidate parameter combination corresponding to the largest distance and the second parameter combination obtained in the previous iteration as the second parameter combination obtained in the current iteration, so as to proceed to the next iteration.
[0135] Optionally, the second parameter combination generation module 203 is further configured to, when determining the reference distance between the candidate parameter combination and at least one second parameter combination obtained in the previous iteration, if the second input parameter is of string type, determine the reference distance between the candidate parameter combination and at least one second parameter combination based on the Lewinstein distance between the value of the second input parameter in the second parameter combination obtained in the previous iteration and the value in the candidate parameter combination.
[0136] Optionally, the second parameter combination generation module 203 is further configured to, when determining the reference distance between the candidate parameter combination and at least one second parameter combination based on the Lewinstein distance between the values of different second input parameters in the second parameter combination obtained in the previous iteration and the values in the candidate parameter combination, perform a weighted summation of the Lewinstein distances between the values of different second input parameters in the second parameter combination and the values in the candidate parameter combination to obtain the reference distance between the candidate parameter combination and at least one second parameter combination.
[0137] Optionally, the second parameter combination generation module 203 is further configured to, when determining the reference distance between the candidate parameter combination and at least one second parameter combination obtained in the previous iteration, if the second input parameter is an array including string-type element items, determine the Lewinstein distance between the value of each element item in each second parameter combination obtained in the previous iteration and the value in the candidate parameter combination; and determine the reference distance between the candidate parameter combination and at least one second parameter combination based on the Lewinstein distance corresponding to each element item.
[0138] Optionally, the second parameter combination generation module 203 is further configured to, when determining the reference distance between the candidate parameter combination and at least one second parameter combination based on the Lewinstein distances corresponding to each of the element items, determine, for each second input parameter, a first distance between the second input parameter and the candidate parameter combination based on the Lewinstein distances corresponding to each of the element items included in the second input parameter; determine, for each second input parameter, a second distance between the second input parameter and its value in the candidate parameter combination and its value in the second parameter combination based on the first distance; and perform a weighted summation of the second distances corresponding to different second input parameters to obtain the reference distance between the candidate parameter combination and at least one second parameter combination.
[0139] Optionally, the possible value determination module 201 is further configured to convert the preset data source from a first form to a key-value pair form, the first form including one of the following: structured form, binary form; and extract the possible values corresponding to at least two input parameters of the test target from the preset data source in the key-value pair form.
[0140] Optionally, the above-mentioned device further includes a conversion module and a testing module:
[0141] The conversion module is used to convert the correspondence between input parameters and possible values in the test case from the key-value pair format to the first format.
[0142] The testing module is used to test the test target using test cases of the test target.
[0143] Optionally, the test case generation module 204 is further configured to determine the Cartesian product of each of the first parameter combinations and each of the second parameter combinations as the test case for the test target.
[0144] Optionally, the above-mentioned device further includes a first input parameter determination module and a second input parameter determination module:
[0145] The first input parameter determination module is used to determine the input parameters used in the branch processing of the test target as the first input parameter.
[0146] The second input parameter determination module is used to determine the unused input parameters in the branch processing of the test target as the second input parameters.
[0147] The apparatus provided in this embodiment can be used to perform the above-described... Figure 2 The technical solutions of the method embodiments shown are similar in implementation principle and technical effect, and will not be described again here.
[0148] Figure 6 This is a structural block diagram of an electronic device provided in an embodiment of the present disclosure. The electronic device 600 includes a memory 602 and at least one processor 601;
[0149] Among them, memory 602 stores computer-executed instructions;
[0150] At least one processor 601 executes computer execution instructions stored in memory 602, causing electronic device 600 to perform the aforementioned functions. Figure 2 The method for generating test cases in [the context of the test case].
[0151] In addition, the electronic device may also include a receiver 603 and a transmitter 604, wherein the receiver 603 is used to receive information from other devices or equipment and forward it to the processor 601, and the transmitter 604 is used to send information to other devices or equipment.
[0152] In a first example of the first aspect, embodiments of this disclosure provide a method for generating test cases, including:
[0153] Determine the possible values for at least two input parameters of the test target;
[0154] For at least one of the at least two input parameters, at least one first parameter combination is generated based on the possible value combinations of the first input parameter. The first input parameter is an input parameter whose number of possible values is less than a first preset number. Each first parameter combination includes one possible value of each first input parameter.
[0155] For at least one of the at least two input parameters, at least one combination of second parameters is randomly generated based on the possible values of the second input parameter. The second input parameter is an input parameter whose number of possible values is greater than or equal to a first preset number. Each combination of second parameters includes one possible value of each second input parameter.
[0156] Test cases for the test target are generated based on each combination of the first parameter and each combination of the second parameter.
[0157] Based on the first example of the first aspect, in the second example of the first aspect, the step of randomly generating at least one combination of the second parameter according to the possible values of the second input parameter includes:
[0158] In each iteration, at least two candidate parameter combinations are randomly generated based on the possible values of the second input parameter, and each candidate parameter combination includes one possible value of each of the second input parameters;
[0159] For each candidate parameter combination, a reference distance is determined between the candidate parameter combination and at least one second parameter combination obtained in the previous iteration;
[0160] The candidate parameter combination corresponding to the largest distance and the second parameter combination obtained in the previous iteration are determined as the second parameter combination obtained in this iteration, so as to enter the next iteration.
[0161] Based on the second example of the first aspect, in the third example of the first aspect, determining the reference distance between the candidate parameter combination and at least one second parameter combination obtained in the previous iteration includes:
[0162] If the second input parameter is a string, then the reference distance between the candidate parameter combination and at least one second parameter combination is determined based on the Lewinstein distance between the value of the second input parameter in the second parameter combination obtained in the previous iteration and the value in the candidate parameter combination.
[0163] Based on the third example of the first aspect, in the fourth example of the first aspect, determining the reference distance between the candidate parameter combination and at least one second parameter combination based on the Lewinstein distance between the value of the second input parameter in the second parameter combination obtained in the previous iteration and the value in the candidate parameter combination includes: performing a weighted summation of the Lewinstein distances between the values of different second input parameters in the second parameter combination and the values in the candidate parameter combination to obtain the reference distance between the candidate parameter combination and at least one second parameter combination.
[0164] Based on the second example of the first aspect, in the fifth example of the first aspect, determining the reference distance between the candidate parameter combination and at least one second parameter combination obtained in the previous iteration includes:
[0165] If the second input parameter is an array containing string-type elements, then determine the Lewinstein distance between the value of each element in each combination of the second parameters obtained in the previous iteration and the value in the candidate parameter combination.
[0166] The reference distance between the candidate parameter combination and at least one second parameter combination is determined based on the Lewinstein distance corresponding to each of the aforementioned element items.
[0167] Based on the fifth example of the first aspect, in the sixth example of the first aspect, determining the reference distance between the candidate parameter combination and at least one second parameter combination according to the Lewinstein distance corresponding to each of the said element items includes:
[0168] For each of the second input parameters, a first distance between the second input parameter and the candidate parameter combination is determined based on the Lewinstein distance corresponding to each of the element items included in the second input parameter.
[0169] For each of the second input parameters, a second distance is determined based on a first distance between the value of the second input parameter in the candidate parameter combination and the value in the second parameter combination.
[0170] The second distances corresponding to different second input parameters are weighted and summed to obtain the reference distance between the candidate parameter combination and at least one second parameter combination.
[0171] Based on the first example of the first aspect, in the seventh example of the first aspect, the possible values corresponding to the at least two input parameters for determining the test target include:
[0172] Convert the preset data source from the first form to the key-value pair form, where the first form includes one of the following: structured form or binary form;
[0173] Extract the possible values corresponding to at least two input parameters of the test target from the preset data source in the form of key-value pairs.
[0174] Based on the seventh example of the first aspect, in the eighth example of the first aspect, the method further includes:
[0175] The correspondence between input parameters and possible values in the test cases is converted from the key-value pair format to the first format.
[0176] The test target is tested using test cases for the test target.
[0177] Based on any one of the first to eighth examples of the first aspect, in the ninth example of the first aspect, the step of generating test cases for the test target according to each combination of the first parameters and each combination of the second parameters includes:
[0178] The Cartesian product of each of the first parameter combinations and each of the second parameter combinations is determined as the test case for the test target.
[0179] Based on any one of the first to eighth examples of the first aspect, the tenth example of the first aspect further includes:
[0180] The input parameter used in the branch processing of the test objective is determined as the first input parameter;
[0181] The unused input parameters in the branch processing of the test target are determined as the second input parameters.
[0182] In the first example of the second aspect, a test case generation apparatus is provided, comprising:
[0183] The possible value determination module is used to determine the possible values corresponding to at least two input parameters of the test target.
[0184] The first parameter combination generation module is used to generate at least one first parameter combination based on the possible value combinations of the first input parameter for at least one of the at least two input parameters, wherein the first input parameter is an input parameter whose number of possible values is less than a first preset number, and each first parameter combination includes one possible value of each first input parameter;
[0185] The second parameter combination generation module is used to randomly generate at least one second parameter combination based on the possible values of the second input parameter for at least one of the at least two input parameters. The second input parameter is an input parameter whose number of possible values is greater than or equal to a first preset number. Each second parameter combination includes one possible value of each second input parameter.
[0186] The test case generation module is used to generate test cases for the test target based on each combination of the first parameter and each combination of the second parameter.
[0187] Based on the first example of the second aspect, in the second example of the second aspect, the second parameter combination generation module is further configured to: in each iteration, randomly generate at least two candidate parameter combinations based on the possible values of the second input parameter, each candidate parameter combination including one possible value of each second input parameter; for each candidate parameter combination, determine a reference distance between the candidate parameter combination and at least one second parameter combination obtained in the previous iteration; and determine the candidate parameter combination corresponding to the largest distance and the second parameter combination obtained in the previous iteration as the second parameter combination obtained in the current iteration, so as to proceed to the next iteration.
[0188] Based on the second example of the second aspect, in the third example of the second aspect, the second parameter combination generation module is further configured to, when determining the reference distance between the candidate parameter combination and at least one second parameter combination obtained in the previous iteration, if the second input parameter is of string type, determine the reference distance between the candidate parameter combination and at least one second parameter combination based on the Lewinstein distance between the value of the second input parameter in the second parameter combination obtained in the previous iteration and the value in the candidate parameter combination.
[0189] Based on the third example of the second aspect, in the fourth example of the second aspect, the aforementioned second parameter combination generation module is further configured to, when determining the reference distance between the candidate parameter combination and at least one second parameter combination based on the Lewinstein distance between the values of different second input parameters in the second parameter combination and the values in the candidate parameter combination obtained in the previous iteration, perform a weighted summation of the Lewinstein distances between the values of different second input parameters in the second parameter combination and the values in the candidate parameter combination to obtain the reference distance between the candidate parameter combination and at least one second parameter combination.
[0190] Based on the second example of the second aspect, in the fifth example of the second aspect, the aforementioned second parameter combination generation module is further configured to, when determining the reference distance between the candidate parameter combination and at least one second parameter combination obtained in the previous iteration, if the second input parameter is an array including string-type element items, determine the Lewinstein distance between the value of each element item in each second parameter combination obtained in the previous iteration and the value in the candidate parameter combination; and determine the reference distance between the candidate parameter combination and at least one second parameter combination based on the Lewinstein distance corresponding to each element item.
[0191] Based on the fifth example of the second aspect, in the sixth example of the second aspect, the aforementioned second parameter combination generation module is further configured to, when determining the reference distance between the candidate parameter combination and at least one second parameter combination based on the Lewinstein distance corresponding to each of the element items, for each second input parameter, determine a first distance between the second input parameter and the candidate parameter combination based on the Lewinstein distance corresponding to each of the element items included in the second input parameter; for each second input parameter, determine a second distance between the second input parameter based on the first distance between the value of the second input parameter in the candidate parameter combination and the value in the second parameter combination; and perform a weighted summation of the second distances corresponding to different second input parameters to obtain the reference distance between the candidate parameter combination and at least one second parameter combination.
[0192] Based on the first example of the second aspect, in the seventh example of the second aspect, the possible value determination module is further configured to convert the preset data source from a first form to a key-value pair form, the first form including one of the following: a structured form and a binary form; and extract the possible values corresponding to at least two input parameters of the test target from the preset data source in the key-value pair form.
[0193] Based on the seventh example of the second aspect, in the eighth example of the second aspect, the device further includes:
[0194] The conversion module is used to convert the correspondence between input parameters and possible values in the test cases from the key-value pair format to the first format.
[0195] The testing module is used to test the test target using test cases of the test target.
[0196] Based on any one of the first to eighth examples of the second aspect, in the ninth example of the second aspect, the test case generation module is further configured to determine the Cartesian product of each of the first parameter combinations and each of the second parameter combinations as the test case for the test target.
[0197] Based on any one of the first to eighth examples of the second aspect, in the tenth example of the second aspect, the above-mentioned apparatus further includes:
[0198] The first input parameter determination module is used to determine the input parameters used in the branch processing of the test target as the first input parameter;
[0199] The second input parameter determination module is used to determine the unused input parameters in the branch processing of the test target as the second input parameters.
[0200] Thirdly, according to one or more embodiments of the present disclosure, an electronic device is provided, comprising: at least one processor and a memory;
[0201] The memory stores computer-executed instructions;
[0202] The at least one processor executes computer execution instructions stored in the memory, causing the electronic device to implement the method described in any of the first aspects.
[0203] Fourthly, according to one or more embodiments of the present disclosure, a computer-readable storage medium is provided, the computer-readable storage medium storing computer-executable instructions that, when executed by a processor, cause a computing device to implement the method described in any one of the first aspects.
[0204] Fifthly, according to one or more embodiments of the present disclosure, a computer program is provided for implementing the method described in any of the first aspects.
[0205] The above description is merely a preferred embodiment of this disclosure and an explanation of the technical principles employed. Those skilled in the art should understand that the scope of this disclosure is not limited to technical solutions formed by specific combinations of the above-described technical features, but should also cover other technical solutions formed by arbitrary combinations of the above-described technical features or their equivalents without departing from the above-described concept. For example, technical solutions formed by substituting the above features with (but not limited to) technical features disclosed in this disclosure that have similar functions.
[0206] Furthermore, while the operations are described in a specific order, this should not be construed as requiring these operations to be performed in the specific order shown or in a sequential order. In certain environments, multitasking and parallel processing may be advantageous. Similarly, while several specific implementation details are included in the above discussion, these should not be construed as limiting the scope of this disclosure. Certain features described in the context of individual embodiments may also be implemented in combination in a single embodiment. Conversely, various features described in the context of a single embodiment may also be implemented individually or in any suitable sub-combination in multiple embodiments.
[0207] Although the subject matter has been described using language specific to structural features and / or methodological logic, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. Rather, the specific features and actions described above are merely illustrative examples of implementing the claims.
Claims
1. A method for generating test cases, characterized in that, The method includes: Determine the possible values for at least two input parameters of the test target; For at least one of the at least two input parameters, at least one first parameter combination is generated based on the possible value combinations of the first input parameter. The first input parameter is an input parameter whose number of possible values is less than a first preset number. Each first parameter combination includes one possible value of each first input parameter. The first input parameter is the input parameter used in the branch processing of the test target. For at least one second input parameter among the at least two input parameters, in each iteration, at least two candidate parameter combinations are randomly generated based on the possible values of the second input parameter, each candidate parameter combination including one possible value of each second input parameter; for each candidate parameter combination, a reference distance is determined between the candidate parameter combination and at least one second parameter combination obtained in the previous iteration; the candidate parameter combination corresponding to the largest reference distance and the second parameter combination obtained in the previous iteration are determined as the second parameter combination obtained in this iteration, to proceed to the next iteration, to generate at least one second parameter combination, wherein the second input parameter is an input parameter whose number of possible values is greater than or equal to a first preset number, each second parameter combination including one possible value of each second input parameter; the second input parameter is an input parameter not used in the branch processing of the test target; The Cartesian product of each of the first parameter combinations and each of the second parameter combinations is determined as the test case for the test target.
2. The method according to claim 1, characterized in that, Determining the reference distance between the candidate parameter combination and at least one second parameter combination obtained in the previous iteration includes: If the second input parameter is a string, then the reference distance between the candidate parameter combination and at least one second parameter combination is determined based on the Lewinstein distance between the value of the second input parameter in the second parameter combination obtained in the previous iteration and the value in the candidate parameter combination.
3. The method according to claim 2, characterized in that, The step of determining the reference distance between the candidate parameter combination and at least one second parameter combination based on the Lewinstein distance between the value of the second input parameter in the second parameter combination obtained in the previous iteration and the value of the candidate parameter combination includes: The Lewinstein distances between different values of the second input parameter in the second parameter combination and the values of the candidate parameter combination are weighted and summed to obtain the reference distance between the candidate parameter combination and at least one second parameter combination.
4. The method according to claim 1, characterized in that, Determining the reference distance between the candidate parameter combination and at least one second parameter combination obtained in the previous iteration includes: If the second input parameter is an array containing string-type elements, then determine the Lewinstein distance between the value of each element in each combination of the second parameters obtained in the previous iteration and the value in the candidate parameter combination. The reference distance between the candidate parameter combination and at least one second parameter combination is determined based on the Lewinstein distance corresponding to each of the aforementioned element items.
5. The method according to claim 4, characterized in that, Determining the reference distance between the candidate parameter combination and at least one second parameter combination based on the Lewinstein distance corresponding to each of the element items includes: For each of the second input parameters, a first distance between the second input parameter and the candidate parameter combination is determined based on the Lewinstein distance corresponding to each of the element items included in the second input parameter. For each of the second input parameters, a second distance is determined based on a first distance between the value of the second input parameter in the candidate parameter combination and the value in the second parameter combination. The second distances corresponding to different second input parameters are weighted and summed to obtain the reference distance between the candidate parameter combination and at least one second parameter combination.
6. The method according to claim 1, characterized in that, The possible values corresponding to the at least two input parameters for determining the test target include: Convert the preset data source from the first form to the key-value pair form, where the first form includes one of the following: structured form or binary form; Extract the possible values corresponding to at least two input parameters of the test target from the preset data source in the form of key-value pairs.
7. The method according to claim 6, characterized in that, The method further includes: The correspondence between input parameters and possible values in the test cases is converted from the key-value pair format to the first format. The test target is tested using test cases for the test target.
8. A test case generation device, characterized in that, include: The possible value determination module is used to determine the possible values corresponding to at least two input parameters of the test target. The first parameter combination generation module is used to generate at least one first parameter combination based on the possible value combinations of the first input parameter for at least one of the at least two input parameters, wherein the first input parameter is an input parameter whose number of possible values is less than a first preset number, and each first parameter combination includes one possible value of each first input parameter; the first input parameter is the input parameter used in the branch processing of the test target; The second parameter combination generation module is used to randomly generate at least two candidate parameter combinations in each iteration for at least one of the at least two input parameters, based on the possible values of the second input parameter. Each candidate parameter combination includes one possible value of each second input parameter. For each candidate parameter combination, a reference distance is determined between the candidate parameter combination and at least one second parameter combination obtained in the previous iteration; The candidate parameter combination corresponding to the largest reference distance and the second parameter combination obtained in the previous iteration are determined as the second parameter combination obtained in this iteration, so as to enter the next iteration and generate at least one second parameter combination. The second input parameter is an input parameter whose number of possible values is greater than or equal to a first preset number. Each second parameter combination includes one possible value of each second input parameter. The second input parameter is an input parameter that is not used in the branch processing of the test target. The test case generation module is used to determine the Cartesian product of each combination of the first parameters and each combination of the second parameters as the test cases for the test target.
9. An electronic device, characterized in that, include: At least one processor and memory; The memory stores computer-executed instructions; The at least one processor executes computer execution instructions stored in the memory, causing the electronic device to perform the method as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, cause a computing device to implement the method as described in any one of claims 1 to 7.
11. A computer program product, characterized in that, The computer program product is used to implement the method as described in any one of claims 1 to 7.