Test case optimization method and device and storage medium
By calculating the correlation between test cases and optimizing, the problem of repeated tests between test cases is solved, improving testing efficiency and saving costs.
Patent Information
- Application Number
- CN202310678858.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-08
- Publication Date
- 2024-12-10
AI Technical Summary
As test cases increase, the correlation between test cases increases, resulting in repeated tests and increasing unnecessary costs.
By obtaining multiple test cases, determine the probe sequence contained in the code file corresponding to the test case, calculate the correlation between any two test cases, and based on indicators such as edit distance, the longest common subsequence, the correlation degree is greater than that of the corresponding correlation based on indicators such as edit distance and the longest common subsequence. Or equal to the threshold, optimize the test cases.
Optimized test cases can avoid repeated tests, improve test efficiency and save test costs.
Smart Images

Figure CN119105945A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of testing, and in particular to a test case optimization method, device and storage medium. Background Art
[0002] As the number of test cases increases, some test cases become more and more relevant, and even contain each other, leading to repeated testing and unnecessary cost increase. Summary of the invention
[0003] In order to overcome the problems existing in the related art, the present disclosure provides a test case optimization method, device and storage medium.
[0004] According to a first aspect of an embodiment of the present disclosure, a test case optimization method is provided, comprising: obtaining a plurality of test cases; determining a code file corresponding to the test case, the code file comprising at least one probe, the probe being used to indicate whether a code associated with the probe in the code file is executed; generating a probe sequence corresponding to the test case based on the code file; determining a correlation between any two test cases based on the probe sequences corresponding to the test cases; and optimizing the any two test cases in response to the correlation being greater than or equal to a correlation threshold.
[0005] In one embodiment, determining the correlation between any two test cases based on the probe sequences corresponding to any two test cases includes: determining an edit distance between the probe sequences corresponding to any two test cases, wherein the edit distance represents the total number of operation steps required for mutual transformation between the probe sequences corresponding to any two test cases; determining a first similarity between the probe sequences corresponding to any two test cases based on the edit distance and the lengths of the probe sequences corresponding to any two test cases; and determining the first similarity as the correlation.
[0006] In one embodiment, the operation steps include one or more categories, and the method further includes: determining a first ratio of the number of operation steps corresponding to a target category to the total number of operation steps, the target category being at least one of the one or more categories; determining a second similarity between probe sequences corresponding to any two of the test cases based on the first ratio and the weight of the category; determining the first similarity as the correlation includes: determining the correlation based on the first similarity and the second similarity.
[0007] In one embodiment, determining the correlation between any two test cases based on the probe sequences corresponding to any two test cases includes: determining the longest common subsequence between the probe sequences corresponding to any two test cases; determining a third similarity between the probe sequences corresponding to any two test cases based on the longest common subsequence; and determining the third similarity as the correlation.
[0008] In one embodiment, determining the third similarity between the probe sequences corresponding to any two of the test cases based on the longest common subsequence includes: determining the third similarity between the probe sequences corresponding to any two of the test cases based on the length of the longest common subsequence and the length of the probe sequences corresponding to any two of the test cases.
[0009] In one embodiment, determining the third similarity between the probe sequences corresponding to any two of the test cases based on the longest common subsequence includes: determining the third similarity based on a second ratio of the length of the longest common subsequence to the length of the probe sequences corresponding to any two of the test cases.
[0010] According to a second aspect of an embodiment of the present disclosure, a test case optimization device is provided, characterized in that the test case optimization device includes: an acquisition module for acquiring multiple test cases; a determination module for determining a code file corresponding to the test case, the code file including at least one probe, and the probe is used to indicate whether the code associated with the probe in the code file is executed; a processing module for generating a probe sequence corresponding to the test case based on the code file; the determination module is also used to determine the correlation between any two test cases based on any two of the probe sequences; the processing module is also used to optimize the any two test cases in response to the correlation being greater than or equal to a correlation threshold.
[0011] In one embodiment, the determination module also determines the correlation between the test cases that fail in the following manner: determining the edit distance between the probe sequences corresponding to any two of the test cases, wherein the edit distance represents the total number of operation steps required for mutual transformation between the probe sequences corresponding to any two of the test cases; determining the first similarity between the probe sequences corresponding to any two of the test cases based on the edit distance and the lengths of the probe sequences corresponding to any two of the test cases; and determining the first similarity as the correlation.
[0012] In one embodiment, the operation steps include one or more categories; the determination module also determines the correlation between the test cases that fail in the following manner: determine a first ratio of the number of operation steps corresponding to a target category to the total number of operation steps, and the target category is at least one of the one or more categories; based on the first ratio and the weight of the target category, determine the second similarity between the probe sequences corresponding to any two of the test cases; determine the correlation based on the first similarity and the second similarity.
[0013] In one embodiment, the determination module also determines the correlation between the test cases that fail in the following manner: determining the longest common subsequence between the probe sequences corresponding to any two of the test cases; determining the third similarity between the probe sequences corresponding to any two of the test cases based on the longest common subsequence; and determining the third similarity as the correlation.
[0014] In one embodiment, the determination module further determines the third similarity in the following manner: based on the length of the longest common subsequence and the length of the probe sequences corresponding to any two of the test cases, determining the third similarity between the probe sequences corresponding to any two of the test cases.
[0015] In one embodiment, the determination module further determines the third similarity in the following manner: determining the third similarity based on a second ratio of the length of the longest common subsequence to the lengths of probe sequences corresponding to any two of the test cases.
[0016] According to a third aspect of an embodiment of the present disclosure, an electronic device is provided, comprising: a memory for storing instructions; and a processor for calling the instructions stored in the memory to execute the test case optimization method in the first aspect or any one of the implementations of the first aspect.
[0017] According to a fourth aspect of an embodiment of the present disclosure, a non-transitory readable storage medium is provided, in which instructions are stored. When the instructions are executed by a processor, the test case optimization method in the first aspect or any one of the implementations of the first aspect is executed.
[0018] The technical solution provided by the embodiments of the present disclosure may include the following beneficial effects: by obtaining multiple test cases, determining the code file corresponding to the test case, the code file includes at least one probe, generating a probe sequence based on the code file, determining the correlation between the test cases corresponding to the probe sequences based on any two probe sequences, and optimizing the test case in response to the correlation being greater than or equal to a correlation threshold. The optimized test case can avoid repeated testing, improve test efficiency, and save test costs.
[0019] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.
[0021] Figure 1 The present invention is a flowchart of a test case optimization method according to an exemplary embodiment.
[0022] Figure 2 It is a schematic diagram of the conversion between Java code and bytecode.
[0023] Figure 3a It is a schematic diagram of the bytecode execution process.
[0024] Figure 3b It is a schematic diagram of the bytecode execution flow after the probe is inserted.
[0025] Figure 4 The present invention is a flowchart of another test case optimization method according to an exemplary embodiment.
[0026] Figure 5 The present invention is a flowchart of another test case optimization method according to an exemplary embodiment.
[0027] Figure 6 The present invention is a flowchart of another test case optimization method according to an exemplary embodiment.
[0028] Figure 7 The present invention is a flowchart of another test case optimization method according to an exemplary embodiment.
[0029] Figure 8 The present invention is a flowchart of another test case optimization method according to an exemplary embodiment.
[0030] Fig. 9 The invention is a block diagram of a test case optimization device according to an exemplary embodiment.
[0031] Fig.10 It is a block diagram of another test case optimization device according to an exemplary embodiment. DETAILED DESCRIPTION
[0032] Here, exemplary embodiments will be described in detail, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present disclosure.
[0033] At present, with the increasing number of test cases, the correlation between test cases is getting higher and higher, and even inclusion relationships appear, which leads to repeated testing and increases unnecessary costs.
[0034] Among them, a test case refers to a description of a test task for a specific software product, including test objectives, test environment, input data, test steps, expected results, test scripts, etc. It can be considered that a test case is used to test a certain function of a software product.
[0035] There may be an inclusion relationship between test cases. Specifically, for example, one test case is used to test the camera's photo-taking function, and another test case is used to test the camera's photo-taking function with the flash turned on. The latter includes the former, so these two test cases need to be optimized.
[0036] Therefore, the present disclosure provides a test case optimization method, which is applied to a terminal, and obtains multiple test cases to determine the code file corresponding to the test case, where the code file includes at least one probe, generates a probe sequence based on the code file, and determines the correlation between the test cases corresponding to the probe sequences based on any two probe sequences. In response to the correlation being greater than or equal to a correlation threshold, the test case is optimized. The optimized test case can avoid repeated testing, improve test efficiency, and save test costs.
[0037] Among them, the terminal can also be called terminal equipment, mobile station (MS), mobile terminal (MT), etc., which is a device that provides voice and / or data connectivity to users. For example, the terminal can be a handheld device with wireless connection function, a vehicle-mounted device, etc. At present, some examples of terminals are: smart phones (mobile phones), pocket personal computers (pocket personal computers, PPCs), handheld computers, personal digital assistants (personal digital assistants, PDAs), laptops, tablet computers, wearable devices, or vehicle-mounted devices, etc. In addition, when it is a vehicle-to-everything (V2X) communication system, the terminal device can also be a vehicle-mounted device. It should be understood that the embodiments of the present disclosure do not limit the specific technology and specific device form adopted by the terminal.
[0038] Figure 1 is a flow chart of a test case optimization method according to an exemplary embodiment. Figure 1 As shown, the test case optimization method includes the following steps.
[0039] In step S11, multiple test cases are obtained.
[0040] In one implementation, the terminal obtains a plurality of test cases, wherein the test cases are used to test the functions of the software product.
[0041] In step S12, the code file corresponding to the test case is determined.
[0042] In one embodiment, the terminal can determine the code files corresponding to the multiple test cases based on the obtained multiple test cases. When testing a function of a software product, the testing tool often needs to execute the part of the code corresponding to the function in the source code of the software product, and verify the execution result to achieve the purpose of the test. It can be considered that the test case has a corresponding relationship with the part of the code in the source code of the software product. Therefore, the terminal can determine the code file corresponding to the test case based on the part of the code corresponding to the test case.
[0043] The code file includes at least one probe. The probe is also called a detector, which is a code segment for information collection and is used to indicate whether the code associated with the probe in the code file is executed. Exemplarily, the code associated with the probe may be the code before the probe.
[0044] For example, the code file includes probes such as probe 1, probe 2, and probe 3. The code between probe 1 and probe 2 can be considered as code associated with probe 2; the code between probe 2 and probe 3 can be considered as code associated with probe 3.
[0045] For another example, if no other probes are included before probe 1 in the code file, the code before probe 1 can be considered to be code associated with probe 1.
[0046] The probe can be a Boolean value, which is either true or false. The probe's initial value is assigned to false. When the code executes to the probe position, it is assigned to true. The code before the probe that is assigned to true is considered to have been executed. After the test is completed, the code before the probe that is still false is considered to have not been executed.
[0047] For example, the initial values of probe 1, probe 2, and probe 3 in the code file are all false. When the code is executed to the position of probe 2, probe 2 is assigned a value of true. It can be considered that the code between probe 1 and probe 2 has been executed.
[0048] For another example, after the test is completed, if probe 3 is still false, it can be considered that the code between probe 2 and probe 3 has not been executed.
[0049] In one embodiment, the code file may be, for example, a computer programming language (Java) file. The terminal may convert the Java file to obtain a binary file, that is, convert the Java code into bytecode. Figure 2 It is a schematic diagram of the conversion between Java code and bytecode. Figure 2 As shown, Figure 2 The left side is Java code. The first line of code indicates calling the main function, the second line of code indicates executing statement a, the third and fourth lines of code indicate judging based on the judgment condition cond(), and if the judgment condition is met, statement b is executed, the fifth, sixth and seventh lines of code indicate executing statement c if the judgment condition is not met, and the eighth line of code indicates continuing to execute statement d after executing statement b or statement c. Figure 2 The right side is the bytecode corresponding to the Java code on the left. Among them, the first line of bytecode indicates calling the main function, the second line of bytecode indicates executing statement a, the third line of bytecode and the fifth line of bytecode indicate judging based on the judgment condition cond(), if the judgment condition is met, statement b is executed, the fourth line of bytecode indicates jumping to L1 if the judgment condition is not met, the sixth line indicates jumping to L1 or jumping to L2 after executing statement b, the seventh line of code interprets L1, L1 indicates executing statement c, the eighth line of code interprets L2, L2 indicates executing statement d. That is, code and bytecode can express the same meaning in different forms. The terminal can insert at least one probe into the binary file after the code file is converted.
[0050] In step S13, a probe sequence corresponding to the test case is generated based on the code file.
[0051] In one implementation, the terminal may generate a probe sequence uniquely corresponding to the code file based on the position of the probe in the code file, that is, there is a one-to-one correspondence between the probe sequence and the test case.
[0052] In step S14, the correlation between any two test cases is determined based on the probe sequences corresponding to the any two test cases.
[0053] In one embodiment, if there is a correlation between any two probe sequences, there is also a correlation between the test cases corresponding to the probe sequences. The terminal determines the correlation between the test cases corresponding to the probe sequences based on the any two probe sequences. The terminal can determine the correlation between the test cases based on the probe sequences.
[0054] In step S15, in response to the correlation being greater than or equal to the correlation threshold, any two test cases are optimized.
[0055] In one embodiment, if the correlation between different test cases is greater than or equal to the correlation threshold, they need to be optimized. Specifically, the terminal can mark the test cases whose correlation is greater than or equal to the correlation threshold to prompt the tester to optimize them. The terminal can also optimize the test cases whose correlation is greater than or equal to the correlation threshold according to preset rules, which is not limited in this disclosure.
[0056] The present invention obtains multiple test cases, determines the code files corresponding to the test cases, the code files include at least one probe, generates a probe sequence based on the code file, determines the correlation between the test cases corresponding to the probe sequences based on any two probe sequences, and optimizes the test cases in response to the correlation being greater than or equal to a correlation threshold. The optimized test cases can avoid repeated testing, improve test efficiency, and save test costs.
[0057] In one implementation, the coverage detection tool may be a computer programming language code coverage (java code coverage, jacoco) tool. Figure 3a It is a schematic diagram of the bytecode execution process. Figure 3a As shown, in step S21, statement a is executed. In step S22, judgment is made based on the judgment condition cond(). In step S23, if the judgment condition is met, the process jumps to step S24, and if the judgment condition is not met, the process jumps to step S26. In step S24, statement b is executed. In step S25, the process jumps to step S27. In step S26, statement c is executed. In step S27, statement d is executed. Figure 3b It is the execution process of the bytecode after the probe is inserted. Figure 3b As shown, a probe is inserted after each statement in the bytecode. In step S31, statement a is executed. In step S32, a judgment is made based on the judgment condition cond(). In step S33, in response to satisfying the judgment condition, the procedure jumps to step S34, and if the judgment condition is not satisfied, the procedure jumps to step S37. In step S34, statement b is executed. In step S35, if probe 1 is executed, probe 1 is set to true. It can be considered that if probe 1 is true, statement b has been executed. Assuming that statement c is executed directly after statement a is executed, or statement c is executed directly in the middle of executing statement b, probe 1 cannot be executed, and probe 1 is false, then it can be considered that statement b has not been executed. In step S36, the procedure jumps to step S39. In step S37, statement c is executed. In step S38, if probe 2 is executed, probe 2 is set to true. In step S39, statement d is executed. In step S310, if probe 3 is executed, probe 3 is set to true.
[0058] It can be understood that the execution process of steps S31 to S34 is similar to the execution process of the above-mentioned steps S21 to S24, and the execution process of steps S36, S37 and S39 is similar to the execution process of the above-mentioned steps S25 to S27, which will not be described in detail in this disclosure.
[0059] In some implementations, the terminal may determine the similarity between any two probe sequences, thereby determining the relevance between the test cases corresponding to the any two probe sequences. Figure 4 As shown, the present disclosure provides a test case optimization method, which includes the following steps.
[0060] In step S41, the edit distance between probe sequences corresponding to any two test cases is determined.
[0061] In one embodiment, the terminal can determine the first similarity between any two probe sequences based on the edit distance between any two probe sequences. For ease of understanding, the present disclosure refers to the similarity between any two probes determined based on the edit distance as the first similarity. The edit distance is used to indicate the total number of operation steps required at least when converting one of the two strings to another string. The smaller the edit distance, the fewer the total number of operation steps required for string conversion.
[0062] For example, converting one string into another string can be achieved through operations such as replacement, addition, and deletion. For example, if string AB is converted into string ABC, character C needs to be added to the end of the string. Therefore, the edit distance can be 1, indicating that the total number of operation steps required to convert string AB into string ABC is at least 1.
[0063] For another example, if the string DEF is converted into the string DEGH, it can be achieved through the following operation steps: replace the last character of the string DEF from character F to character G to obtain the string DEG; add character H to the end of the string DEG to obtain the string DEGH. In this case, the total number of operation steps is 2. Of course, the string DEF can also be converted into the string DEGH through the following operation steps: delete the character F in the string DEF; add character G; add character H. In this case, the total number of operation steps is 3. Therefore, the total number of operation steps required to convert the string DEF into the string DEGH is at least 2, that is, the edit distance between the string DEF and the string DEGH is 2.
[0064] In this embodiment, the edit distance between the probe sequences can be used to determine the first similarity between the probe sequences. For example, the smaller the edit distance, the greater the similarity; the larger the edit distance, the smaller the similarity.
[0065] In step S42, a first similarity between the probe sequences corresponding to any two test cases is determined based on the edit distance and the lengths of the probe sequences corresponding to any two test cases.
[0066] In one implementation, the terminal may determine the first similarity according to a preset formula 1.
[0067]
[0068] Wherein, Similarity1 represents the first similarity. len1 and len2 represent the lengths of any two probe sequences respectively. max(len1,len2) represents the maximum value of the lengths of the two probe sequences. Levenshtein represents the edit distance of the two probe sequences.
[0069] In this implementation manner, the terminal can determine the lengths and edit distances of any two probe sequences, and use Formula 1 to calculate the first similarity of the two probe sequences.
[0070] In step S43, the first similarity is determined as the correlation.
[0071] In one embodiment, the higher the first similarity between any two probe sequences, the higher the correlation between the test cases corresponding to the probe sequences. The terminal may determine the first similarity as the correlation between any two test cases. If the correlation between any two test cases is greater than or equal to the correlation threshold, the test case is optimized.
[0072] The present invention determines the first similarity between probe sequences based on the edit distance between the probe sequences corresponding to any two test cases, and determines the first similarity as the correlation between any two test cases, so that the correlation between any two test cases can be accurately obtained when the probe sequences are short, and the test cases are optimized based on the correlation.
[0073] In some implementations, the first similarity may have a certain error. In some cases, the correlation determined based on the first similarity is greater than or equal to the correlation threshold, but the corresponding test case does not need to be optimized. Alternatively, in other cases, the test case needs to be optimized, but the correlation determined based on the first similarity is less than the correlation threshold. The present disclosure takes the above situation into consideration and provides a test case optimization method, such as Figure 5 , including the following steps.
[0074] In step S51, a first ratio of the number of operation steps corresponding to the target category to the total number of operation steps is determined.
[0075] In step S52, based on the first ratio and the weight of the target category, a second similarity between the probe sequences corresponding to any two test cases is determined.
[0076] In step S53 , the correlation is determined based on the first similarity and the second similarity.
[0077] In one embodiment, for any two probe sequences, the terminal transforms one of them to obtain the other. The total number of transformation operation steps is the edit distance. The terminal can determine the category of these operation steps. The category of operation steps includes at least one of the following: add; delete; replace. When determining the similarity between probe sequences, the importance of each category in the above three categories of operation steps is different. For example, assuming that the importance of "replacement" is greater, in the process of mutual transformation of any two probe sequences by the terminal, an operation step such as "replacement" appears, and the similarity between the determined probe sequences is greater than that of operation steps of other categories. The terminal can determine the weight of the category based on the importance of the category. For example, if the weight of "addition" is determined to be A, the weight of "deletion" is determined to be B, and the weight of "replacement" is determined to be C, then A+B+C=1.
[0078] In one embodiment, when the terminal transforms any two probe sequences, it can determine the category of the operation steps. At least one of the categories is determined as the target category. Determine the proportion of the number of operation steps corresponding to the target category to the total number of operation steps. The terminal can determine the second similarity based on the proportion and weight corresponding to at least one category of operation steps. For example, the terminal can multiply the proportion and weight corresponding to each category of operation steps, and then add the products corresponding to each category of operation steps to obtain the second similarity. Specifically, if it is determined that the proportion corresponding to "addition" is x, the proportion corresponding to "deletion" is y, and the proportion corresponding to "replacement" is z, then the second similarity can be A*x+B*y+C*z. Among them, x+y+z=1. Among them, in order to distinguish the first similarity, the present disclosure refers to the similarity between the probe sequences determined based on the proportion and weight corresponding to each category of operation steps as the second similarity.
[0079] In one embodiment, the terminal may determine the correlation based on the first similarity and the second similarity. For example, the terminal may calculate the average of the first similarity and the second similarity, and determine the average as the correlation. Alternatively, the terminal may also use the second similarity to perform weighted adjustment on the first similarity according to actual needs. This disclosure is not limited thereto.
[0080] The present disclosure determines the proportion of the number of operation steps corresponding to at least one category to the total number of operation steps, combines the weight of the category, determines the second similarity, and determines the relevance based on the first similarity and the second similarity, so as to determine the relevance more accurately.
[0081] In some embodiments, Figure 6 As shown, the present disclosure provides a test case optimization method, which includes the following steps.
[0082] In step S61, the longest common subsequence (LCS) between probe sequences corresponding to any two test cases is determined.
[0083] In step S62, a third similarity between probe sequences corresponding to any two test cases is determined based on the longest common subsequence.
[0084] In step S63, the third similarity is determined as the correlation.
[0085] In one embodiment, the terminal can determine the longest common subsequence between any two probe sequences, and the similarity between the probe sequences can be determined based on the longest common subsequence. For example, if there is no longest common subsequence between the probe sequences, it can be considered that the similarity between the probe sequences is very low, or approximately 0. If the length of the longest common subsequence accounts for a large proportion of the length of the probe sequences, it can be considered that the similarity between the probe sequences is large. If the longest common subsequence is continuous, then relative to the discontinuous longest common subsequence, the similarity between the corresponding probe sequences is greater. This disclosure does not list them one by one.
[0086] In order to distinguish between the first similarity and the second similarity, the present disclosure refers to the similarity between any two probe sequences determined according to the longest common subsequence as the third similarity. It can be understood that the first similarity, the second similarity and the third similarity mentioned above are all similarities between any two probe sequences, the difference is that the determination method is different, the numerical value is slightly different, but the function is the same, and they are all used to determine the correlation between the test cases corresponding to the probe sequences.
[0087] In one implementation, the terminal determines the third similarity as the correlation between the test cases corresponding to the probe sequences.
[0088] The present invention determines the longest common subsequence of any two probe sequences, determines the third similarity between any two probe sequences, and determines the third similarity as the correlation between test cases corresponding to the probe sequences, so as to accurately obtain the correlation between any two test cases and optimize the test cases based on the correlation.
[0089] It can be understood that in the test case optimization method provided by the present disclosure, the terminal can determine the similarity between probe sequences based on the edit distance or the longest common subsequence between the probe sequences, or can determine the similarity between probe sequences based on the edit distance and the longest common subsequence between the probe sequences, and the present disclosure is not limited thereto.
[0090] In some embodiments, Figure 7 As shown, the present disclosure provides a test case optimization method, which includes the following steps.
[0091] In step S71, a third similarity between the probe sequences corresponding to any two test cases is determined based on the length of the longest common subsequence and the lengths of the probe sequences corresponding to any two test cases.
[0092] In step S72, the third similarity is determined as the correlation.
[0093] In one implementation, the terminal may determine the third similarity according to preset formula 2.
[0094]
[0095] Wherein, Similarity3 represents the third similarity, str1 and str2 represent any two probe sequences, LCS(str1, str2) represents the length of the longest common subsequence of the two probe sequences, and len1 and len2 represent the lengths of the two probe sequences respectively.
[0096] In this implementation manner, the terminal can determine the lengths of any two probe sequences and the length of their longest common subsequence for the two probe sequences. Formula 1 is used to calculate the first similarity of the two probe sequences.
[0097] The execution process of step S72 is similar to that of step S63 and will not be described in detail here.
[0098] The present invention determines the longest common subsequence of any two probe sequences, determines the third similarity based on a preset formula between the length of the longest common subsequence and the length of the probe sequences, and determines the third similarity as the correlation of the test cases corresponding to the probe sequences, so as to accurately determine the correlation between the test cases.
[0099] In some embodiments, Figure 8 As shown, the present disclosure provides a test case optimization method, which includes the following steps.
[0100] In step S81, a third similarity is determined based on a second ratio of the length of the longest common subsequence to the lengths of the probe sequences corresponding to any two test cases.
[0101] In step S82, the third similarity is determined as the correlation.
[0102] In one embodiment, the terminal may determine the second ratio of the length of the longest common subsequence to the length of any two probe sequences. The larger the second ratio, the greater the similarity, and the smaller the second ratio, the smaller the similarity. The third similarity is determined according to the second ratio of the length of the longest common subsequence to the length of any two probe sequences. For example, several intervals of the second ratio and the similarities corresponding to the intervals may be pre-set. In response to the ratio of the length of the longest common subsequence to the length of any two probe sequences conforming to a certain interval, the third similarity is determined as the similarity corresponding to the interval.
[0103] The execution process of step S82 is similar to the execution process of step S63 and step S72, and will not be described in detail here.
[0104] The present disclosure determines the third similarity based on the ratio of the length of the longest common subsequence to the length of the probe sequences corresponding to any two test cases, so as to determine the third similarity more quickly.
[0105] It is understandable that in the test case optimization method provided by the present disclosure, the terminal can determine the third similarity based on a preset formula between the length of the longest common subsequence and the length of the probe sequence. The terminal can also determine the third similarity based on the ratio of the length of the longest common subsequence to the length of the probe sequence corresponding to any two test cases. Alternatively, the terminal can also combine the above two methods to obtain the third similarity, which is not limited by the present disclosure.
[0106] It should be noted that those skilled in the art can understand that the various implementation methods / embodiments involved in the embodiments of the present disclosure can be used in conjunction with the aforementioned embodiments or can be used independently. Whether used alone or in conjunction with the aforementioned embodiments, the implementation principle is similar. In the implementation of the present disclosure, some embodiments are described in terms of implementation methods used together. Of course, those skilled in the art can understand that such examples are not limitations of the embodiments of the present disclosure.
[0107] Based on the same concept, the embodiment of the present disclosure also provides a test case optimization device.
[0108] It is understandable that the test case optimization device provided by the embodiment of the present disclosure includes hardware structures and / or software modules corresponding to the execution of each function in order to realize the above functions. In combination with the units and algorithm steps of each example disclosed in the embodiment of the present disclosure, the embodiment of the present disclosure can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the technical solution of the embodiment of the present disclosure.
[0109] Fig. 9 is a block diagram of a test case optimization device according to an exemplary embodiment. Fig. 9 The device 100 includes: an acquisition module 101, a determination module 102 and a processing module 103.
[0110] The acquisition module 101 is used to acquire multiple test cases. The determination module 102 is used to determine the code files corresponding to the test cases. The processing module 103 is used to generate probe sequences corresponding to the test cases based on the code files. The determination module 102 is also used to determine the correlation between any two test cases based on any two probe sequences. The processing module 103 is also used to optimize any two test cases in response to the correlation being greater than or equal to the correlation threshold.
[0111] In one embodiment, the determination module 102 further determines the correlation between the failed test cases in the following manner: determining the edit distance between the probe sequences corresponding to any two test cases, wherein the edit distance represents the total number of operation steps required for mutual transformation between the probe sequences corresponding to any two test cases. Based on the edit distance and the lengths of the probe sequences corresponding to different test cases, determining the first similarity between the probe sequences corresponding to any two test cases. Determining the first similarity as the correlation.
[0112] In one embodiment, the operation steps include one or more categories. The determination module 102 further determines the correlation between the failed test cases in the following manner: determining a first ratio of the number of operation steps corresponding to the target category to the total number of operation steps. The target category is at least one of the operation steps of the one or more categories. Based on the first ratio and the weight of the target category, determining a second similarity between the probe sequences corresponding to any two test cases. Determining the correlation based on the first similarity and the second similarity.
[0113] In one embodiment, the determination module 102 further determines the correlation between the failed test cases in the following manner: determining the longest common subsequence between the probe sequences corresponding to any two test cases, determining a third similarity between the probe sequences corresponding to any two test cases based on the longest common subsequence, and determining the third similarity as the correlation.
[0114] In one embodiment, the determination module 102 further determines the third similarity in the following manner: based on the length of the longest common subsequence and the length of the probe sequences corresponding to any two test cases, determine the third similarity between the probe sequences corresponding to any two test cases.
[0115] In one embodiment, the determination module 102 further determines the third similarity in the following manner: determining the third similarity based on a second ratio of the length of the longest common subsequence to the lengths of the probe sequences corresponding to any two test cases.
[0116] Fig.10 The present invention is a block diagram of a test case optimization device according to an exemplary embodiment.
[0117] like Fig.10 As shown, apparatus 200 may include one or more of the following components: a processing component 202 , a memory 204 , a power component 206 , a multimedia component 208 , an audio component 210 , an input / output (I / O) interface 212 , a sensor component 214 , and a communication component 216 .
[0118] The processing component 202 generally controls the overall operation of the device 200, such as operations associated with display, phone calls, data communications, camera operations, and recording operations. The processing component 202 may include one or more processors 220 to execute instructions to perform all or part of the steps of the above-described method. In addition, the processing component 202 may include one or more modules to facilitate interaction between the processing component 202 and other components. For example, the processing component 202 may include a multimedia module to facilitate interaction between the multimedia component 208 and the processing component 202.
[0119] The memory 204 is configured to store various types of data to support operations on the device 200. Examples of such data include instructions for any application or method operating on the device 200, contact data, phone book data, messages, pictures, videos, etc. The memory 204 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
[0120] The power component 206 provides power to the various components of the device 200. The power component 206 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power for the device 200.
[0121] The multimedia component 208 includes a screen that provides an output interface between the device 200 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundaries of the touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 208 includes a front camera and / or a rear camera. When the device 200 is in an operating mode, such as a shooting mode or a video mode, the front camera and / or the rear camera may receive external multimedia data. Each front camera and rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.
[0122] The audio component 210 is configured to output and / or input audio signals. For example, the audio component 210 includes a microphone (MIC), and when the device 200 is in an operation mode, such as a call mode, a recording mode, and a speech recognition mode, the microphone is configured to receive an external audio signal. The received audio signal can be further stored in the memory 204 or sent via the communication component 216. In some embodiments, the audio component 210 also includes a speaker for outputting audio signals.
[0123] I / O interface 212 provides an interface between processing component 202 and peripheral interface modules, such as keyboards, click wheels, buttons, etc. These buttons may include but are not limited to: a home button, a volume button, a start button, and a lock button.
[0124] The sensor assembly 214 includes one or more sensors for providing various aspects of the status assessment of the device 200. For example, the sensor assembly 214 can detect the open / closed state of the device 200, the relative positioning of components, such as the display and keypad of the device 200, the sensor assembly 214 can also detect the position change of the device 200 or a component of the device 200, the presence or absence of user contact with the device 200, the orientation or acceleration / deceleration of the device 200 and the temperature change of the device 200. The sensor assembly 214 can include a proximity sensor configured to detect the presence of a nearby object without any physical contact. The sensor assembly 214 can also include an optical sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 214 can also include an accelerometer, a gyroscope sensor, a magnetic sensor, a pressure sensor or a temperature sensor.
[0125] The communication component 216 is configured to facilitate wired or wireless communication between the device 200 and other devices. The device 200 can access a wireless network based on a communication standard, such as WiFi, 2G or 3G, or a combination thereof. In an exemplary embodiment, the communication component 216 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 216 also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.
[0126] In an exemplary embodiment, the apparatus 200 may be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors or other electronic components to perform the above method.
[0127] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 204 including instructions, and the instructions can be executed by the processor 220 of the device 200 to perform the above method. For example, the non-transitory computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.
[0128] The present invention obtains multiple test cases, determines the code files corresponding to the test cases, the code files include at least one probe, generates a probe sequence based on the code file, determines the correlation between the test cases corresponding to the probe sequences based on any two probe sequences, and optimizes the test cases in response to the correlation being greater than or equal to a correlation threshold. The optimized test cases can avoid repeated testing, improve test efficiency, and save test costs.
[0129] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. This application is intended to cover any modifications, uses or adaptations of the present disclosure, which follow the general principles of the present disclosure and include common knowledge or customary technical means in the art that are not disclosed in the present disclosure.
[0130] It should be understood that the present disclosure is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the scope of the appended claims.
Claims
1. A test case optimization method, characterized in that: The test case optimization method comprises: Get multiple test cases; Determine a code file corresponding to the test case, wherein the code file includes at least one probe, and the probe is used to indicate whether the code associated with the probe in the code file is executed; Generate a probe sequence corresponding to the test case based on the code file; Determining the correlation between any two test cases based on the probe sequences corresponding to the any two test cases; In response to the correlation being greater than or equal to a correlation threshold, optimizing the any two test cases.
2. The method according to claim 1, characterized in that The determining the correlation between any two test cases based on the probe sequences corresponding to any two test cases includes: Determine an edit distance between any two probe sequences corresponding to the test cases, wherein the edit distance represents the total number of operation steps required to mutually transform between any two probe sequences corresponding to the test cases; Determine a first similarity between the probe sequences corresponding to any two of the test cases based on the edit distance and the lengths of the probe sequences corresponding to any two of the test cases; The first similarity is determined as the correlation.
3. The method according to claim 2, characterized in that The operation steps include one or more categories; The method further comprises: Determine a first ratio of the number of operation steps corresponding to a target category to the total number of the operation steps, the target category being at least one of the one or more categories; Determining a second similarity between probe sequences corresponding to any two of the test cases based on the first ratio and the weight of the target category; The step of determining the first similarity as the correlation comprises: The degree of relevance is determined based on the first degree of similarity and the second degree of similarity.
4. The method according to claim 1, characterized in that: The determining the correlation between different test cases based on the probe sequences corresponding to any two test cases includes: Determine the longest common subsequence between any two probe sequences corresponding to the test cases; Determine a third similarity between probe sequences corresponding to any two of the test cases based on the longest common subsequence; The third similarity is determined as the correlation.
5. The method according to claim 4, characterized in that The determining, based on the longest common subsequence, a third similarity between probe sequences corresponding to any two of the test cases comprises: Based on the length of the longest common subsequence and the lengths of the probe sequences corresponding to any two of the test cases, a third similarity between the probe sequences corresponding to any two of the test cases is determined.
6. The method according to claim 5, characterized in that The determining, based on the longest common subsequence, a third similarity between probe sequences corresponding to different test cases comprises: A third similarity is determined based on a second ratio of the length of the longest common subsequence to the lengths of the probe sequences corresponding to any two of the test cases.
7. A test case optimization device, characterized in that: The test case optimization device comprises: Acquisition module, used to obtain multiple test cases; A determination module, used to determine a code file corresponding to the test case, wherein the code file includes at least one probe, and the probe is used to indicate whether the code associated with the probe in the code file is executed; A processing module, used for generating a probe sequence corresponding to the test case based on the code file; The determination module is further configured to determine the correlation between any two test cases based on the probe sequences corresponding to the any two test cases; The processing module is further configured to optimize the arbitrary two test cases in response to the correlation being greater than or equal to a correlation threshold.
8. The device according to claim 7, characterized in that The determination module also determines the correlation between any two test cases in the following manner: Determine an edit distance between any two probe sequences corresponding to the test cases, wherein the edit distance represents the total number of operation steps required to mutually transform between any two probe sequences corresponding to the test cases; Determine a first similarity between the probe sequences corresponding to any two of the test cases based on the edit distance and the lengths of the probe sequences corresponding to any two of the test cases; The first similarity is determined as the correlation.
9. The device according to claim 8, characterized in that The operation steps include one or more categories; The determination module also determines the correlation between the test cases that fail in the following manner: Determine a first ratio of the number of operation steps corresponding to a target category to the total number of the operation steps, the target category being at least one of the one or more categories; Determining a second similarity between probe sequences corresponding to any two of the test cases based on the first ratio and the weight of the target category; The degree of relevance is determined based on the first degree of similarity and the second degree of similarity.
10. The device according to claim 7, characterized in that The determination module also determines the correlation between the test cases that fail in the following manner: Determine the longest common subsequence between any two probe sequences corresponding to the test cases; Determine a third similarity between probe sequences corresponding to any two of the test cases based on the longest common subsequence; The third similarity is determined as the correlation.
11. The device according to claim 10, characterized in that The determination module further determines the third similarity in the following manner: Based on the length of the longest common subsequence and the length of the probe sequences corresponding to any two of the test cases, a third similarity between the probe sequences corresponding to any two of the test cases is determined.
12. The device according to claim 10, characterized in that The determination module further determines the third similarity in the following manner: A third similarity is determined based on a second ratio of the length of the longest common subsequence to the lengths of the probe sequences corresponding to any two of the test cases.
13. An electronic device, characterized in that: include: A memory for storing instructions; as well as A processor, configured to call the instructions stored in the memory to execute the test case optimization method according to any one of claims 1 to 6.
14. A non-transitory readable storage medium, characterized in that: The storage medium stores instructions, and when the instructions are executed by the processor, the test case optimization method according to any one of claims 1 to 6 is executed.
