Test case set optimization processing method, device, electronic device and storage medium
Through the generating and utilization of the coverage file of the test case, automatic filtering the redundant test case of initial test cases, the problem of low filtration efficiency in the existing technologies, and the optimization of high -efficiency test case sets.
Patent Information
- Application Number
- CN202011080381.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-10-10
- Publication Date
- 2025-01-28
- Estimated Expiration
- 2041-01-28
AI Technical Summary
The prior art is inefficient when filtering test case sets, and relying on manual means that redundant test cases are difficult to automatically remove.
By obtaining the test file, the mapping is performed according to the preset mapping method, the coverage file is determined, the coverage file is used to filter the initial test case set, and the redundant test case is automatically removed to obtain the target test case set.
A redundant testing case of automatic filtering initial test cases is achieved, which improves filtering efficiency and avoids inefficient problems caused by artificial intervention.
Smart Images

Figure CN112148619B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a method, device, electronic device and storage medium for optimizing a test case set. Background Art
[0002] A test case is a description of a test task for a specific software product, and its contents may include test objectives, test environment, input data, test steps, expected results, test scripts, etc. For example, for a certain test service, test cases can be designed in a combined manner, but the test case set generated in this way is relatively large, and many of the test case sets are repeated and invalid test cases, so the test case set needs to be filtered.
[0003] Currently, when filtering out duplicate and invalid test cases in a test case set, filtering is generally performed by manually combing filtering rules or by using a genetic algorithm of parameters.
[0004] However, the existing filtering methods have the problem of low filtering efficiency due to their reliance on manual labor. Summary of the invention
[0005] The purpose of the present application is to provide a method, device, electronic device and storage medium for optimizing the processing of a test case set in response to the above-mentioned deficiencies in the prior art, which can automatically filter out redundant initial test cases in the initial test case set, avoid manual filtering, and effectively improve filtering efficiency.
[0006] To achieve the above purpose, the technical solution adopted in the embodiment of the present application is as follows:
[0007] In a first aspect, an embodiment of the present application provides a method for optimizing a test case set, including:
[0008] Acquire a file to be tested, wherein the file to be tested includes at least one statement to be tested; map the statement to be tested in the file to be tested according to a preset mapping method, and acquire the mapped statement to be tested; determine a coverage file according to an initial test case set and the mapped file to be tested, wherein the coverage file includes a plurality of coverage parameters, and the coverage parameters are used to indicate the files to be tested and the statements to be tested covered by each initial test case; filter the initial test case set according to the coverage file, and determine a target test case set.
[0009] Optionally, mapping the statement to be tested in the file to be tested according to a preset mapping method to obtain the mapped statement to be tested includes:
[0010] According to the first preset mapping method, the file to be tested is mapped to obtain the mapped file to be tested; according to the second preset mapping method and the mapped file to be tested, the statement to be tested in the file to be tested is mapped to obtain the mapped statement to be tested.
[0011] Optionally, filtering the initial test case set according to the coverage file to determine the target test case set includes:
[0012] According to the coverage file, the coverage parameters of any two of the initial test cases in the initial test case set are obtained; according to the coverage parameters of any two of the initial test cases in the initial test case set, the initial test case set is filtered, and the filtered initial test case set is obtained as the target test case set.
[0013] Optionally, filtering the initial test case set according to the coverage parameters of any two of the initial test cases in the initial test case set, and obtaining the filtered initial test case set as the target test case set includes:
[0014] If it is determined that the coverage parameters of any two of the initial test cases in the initial test case set meet the preset conditions, any of the initial test cases are filtered out until the coverage parameters of any two of the initial test cases in the initial test case set do not meet the preset conditions, and the target test case set is obtained.
[0015] Optionally, the determining that coverage parameters of any two of the initial test cases in the initial test case set meet a preset condition comprises:
[0016] Calculate the similarity parameter between the coverage parameters of any two of the initial test cases in the initial test case set; if the similarity parameter meets a preset threshold, determine that the coverage parameters of any two of the initial test cases in the initial test case set meet a preset condition.
[0017] Optionally, the determining that coverage parameters of any two of the initial test cases in the initial test case set meet a preset condition comprises:
[0018] Calculate the difference between the coverage parameters of any two of the initial test cases in the initial test case set; if the difference is an empty set, determine that the coverage parameters of any two of the initial test cases in the initial test case set meet preset conditions.
[0019] Optionally, determining the coverage file according to the initial test case set and the mapped file to be tested includes:
[0020] Based on the mapped file to be tested, each of the initial test cases in the initial test case set is run to obtain a running result; and according to the running result, the coverage file is determined.
[0021] Optionally, the method further comprises:
[0022] If it is determined according to the coverage file that there is at least one statement to be tested that is not covered in the file to be tested, a new test case is added, and the new test case is used to cover the statement to be tested that is not covered by the initial test case set; based on the new test case and the target test case set, the target test case set is updated.
[0023] In a second aspect, an embodiment of the present application provides an optimization processing device for a test case set, including: an acquisition module, a mapping module, a determination module, and a filtering module;
[0024] The acquisition module is used to acquire a file to be tested, wherein the file to be tested includes at least one statement to be tested;
[0025] The mapping module is used to map the statement to be tested in the file to be tested according to a preset mapping method, and obtain the mapped statement to be tested;
[0026] The determination module is used to determine a coverage file according to the initial test case set and the mapped files to be tested, wherein the coverage file includes a plurality of coverage parameters, and the coverage parameters are used to indicate the files to be tested and the statements to be tested covered by each initial test case;
[0027] The filtering module is used to filter the initial test case set according to the coverage file to determine the target test case set.
[0028] Optionally, the mapping module is specifically used to map the file to be tested according to a first preset mapping mode to obtain the mapped file to be tested;
[0029] According to the second preset mapping mode and the mapped file to be tested, the statement to be tested in the file to be tested is mapped to obtain the mapped statement to be tested.
[0030] Optionally, the filtering module is used to obtain coverage parameters of any two initial test cases in the initial test case set according to the coverage file;
[0031] The initial test case set is filtered according to the coverage parameters of any two of the initial test cases in the initial test case set, and the filtered initial test case set is obtained as the target test case set.
[0032] Optionally, the filtering module is specifically used to filter out any of the initial test cases if it is determined that the coverage parameters of any two of the initial test cases in the initial test case set meet preset conditions, until the coverage parameters of any two of the initial test cases in the initial test case set do not meet the preset conditions, thereby obtaining the target test case set.
[0033] Optionally, the filtering module is specifically used to calculate a similarity parameter between coverage parameters of any two of the initial test cases in the initial test case set;
[0034] If the similarity parameter meets a preset threshold, it is determined that the coverage parameters of any two initial test cases in the initial test case set meet a preset condition.
[0035] Optionally, the filtering module is specifically used to calculate the difference between the coverage parameters of any two initial test cases in the initial test case set;
[0036] If the difference set is an empty set, it is determined that the coverage parameters of any two initial test cases in the initial test case set meet preset conditions.
[0037] Optionally, the determination module is specifically configured to run each of the initial test cases in the initial test case set based on the mapped file to be tested, and obtain a running result;
[0038] The coverage file is determined according to the running result.
[0039] Optionally, the device further comprises: an updating module, for adding a new test case if it is determined according to the coverage file that at least one statement to be tested is not covered in the file to be tested, wherein the new test case is used to cover the statement to be tested that is not covered by the initial test case set;
[0040] According to the new test case and the target test case set, the target test case set is updated.
[0041] In a third aspect, an embodiment of the present application provides an electronic device, comprising: a processor, a storage medium and a bus, the storage medium storing machine-readable instructions executable by the processor, when the electronic device is running, the processor and the storage medium communicate through the bus, and the processor executes the machine-readable instructions to perform the steps of the optimization processing method of the test case set of the first aspect mentioned above.
[0042] In a fourth aspect, an embodiment of the present application provides a storage medium having a computer program stored thereon. When the computer program is executed by a processor, the steps of the test case set optimization processing method of the first aspect are executed.
[0043] The beneficial effects of this application are:
[0044] In the test case set optimization processing method, device, electronic device and storage medium provided in the embodiments of the present application, a file to be tested is obtained, and the file to be tested includes at least one statement to be tested; the statement to be tested in the file to be tested is mapped according to a preset mapping method to obtain the mapped statement to be tested; according to the initial test case set and the mapped file to be tested, a coverage file is determined, and the coverage file includes multiple coverage parameters, and the coverage parameters are used to indicate the files to be tested and the statements to be tested covered by each initial test case; the initial test case set is filtered according to the coverage file to determine the target test case set. By applying the embodiments of the present application, since redundant initial test cases in the initial test case set can be automatically filtered out according to the coverage file, manual filtering can be avoided, and the filtering efficiency can be effectively improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0046] Figure 1 A flowchart of a method for optimizing a test case set provided in an embodiment of the present application;
[0047] Figure 2 A flowchart of another test case set optimization processing method provided in an embodiment of the present application;
[0048] Figure 3 A flowchart of another test case set optimization processing method provided in an embodiment of the present application;
[0049] Figure 4 A flowchart of another test case set optimization processing method provided in an embodiment of the present application;
[0050] Figure 5 A flowchart of another test case set optimization processing method provided in an embodiment of the present application;
[0051] Figure 6 A flowchart of another test case set optimization processing method provided in an embodiment of the present application;
[0052] Figure 7A schematic diagram of functional modules of a test case set optimization processing device provided in an embodiment of the present application;
[0053] Figure 8 A schematic diagram of functional modules of another test case set optimization processing device provided in an embodiment of the present application;
[0054] Fig. 9 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0055] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, rather than all the embodiments. The components of the embodiments of the present application described and shown in the drawings here can be arranged and designed in various different configurations.
[0056] Therefore, the following detailed description of the embodiments of the present application provided in the accompanying drawings is not intended to limit the scope of the present application for which protection is sought, but merely represents selected embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without creative work are within the scope of protection of the present application.
[0057] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, further definition and explanation thereof is not required in subsequent drawings.
[0058] Existing, taking the service interface as an example, when designing test cases for the service interface, the service interface can include multiple interface parameters. The combination of different interface parameters will have different business representations. When there are many interface parameters, such as N, and each parameter has 2 options, then the test cases after the combination expands to 2 to the Nth power. It can be seen that the test case set is very large, and many of the test case sets are repeated and invalid test cases, so the test case set needs to be filtered. Existing filtering generally involves manually combing some filtering rules or filtering through genetic algorithms of parameters, but because the existing filtering methods rely on manual labor, especially on the tester's understanding of the business system, there is a problem of low filtering efficiency.
[0059] In view of this, the present application provides a method for optimizing a test case set, which can automatically filter the initial test case set and improve filtering efficiency.
[0060] Figure 1A flowchart of a test case set optimization processing method provided in an embodiment of the present application, the execution subject of the method can be a computer, a server, a processor, a terminal device, etc. Figure 1 As shown, the method may include:
[0061] S101. Obtain a file to be tested, where the file to be tested includes at least one statement to be tested.
[0062] The file to be tested may be a code file to be tested, which may include multiple code statements to be tested, i.e., multiple statements to be tested. Optionally, each line of the code file to be tested may include one or more code statements to be tested, which is not limited here and may vary according to different code syntaxes or the writing habits of code developers.
[0063] Of course, the present application does not limit the type of code language in the file to be tested, and may include but is not limited to a combination of one or more of C, C++, python, Java, PHP, etc.
[0064] S102: Map the statements to be tested in the file to be tested according to a preset mapping method, and obtain the mapped statements to be tested.
[0065] The sentences to be tested in the test file are mapped so that the mapped sentences to be tested can correspond to unique mapping tags. For example, the first line of sentences to be tested in the test file A can be mapped to A_1, and the second line of sentences to be tested in the test file A can be mapped to A_2, but the present invention is not limited thereto.
[0066] S103. Determine a coverage file according to the initial test case set and the mapped files to be tested, where the coverage file includes a plurality of coverage parameters, and the coverage parameters are used to indicate the files to be tested and the statements to be tested covered by each initial test case.
[0067] The initial test case set may include multiple initial test cases. The initial test case set may be generated according to a test case generation tool (eg, ONES TestCase tool), or may be generated based on an orthogonal method, which is not limited here.
[0068] Based on the above mapped files to be tested, a coverage file can be determined according to the initial test case set and the mapped files to be tested, and the coverage file can be used to reflect the proportion and degree of the files to be tested being tested. The coverage file may include multiple coverage parameters, and the coverage parameters may be used to indicate the files to be tested and the statements to be tested covered by each initial test case, that is, the files to be tested and the statements to be tested tested by each initial test case.
[0069] S104: Filter the initial test case set according to the coverage file to determine the target test case set.
[0070] Among them, after obtaining the coverage file, the initial test case set can be automatically filtered according to the coverage file to filter out repeated and invalid initial test cases in the initial test case set, and obtain the target test case set, which is the valid initial test case set. In this process, since the target test case set can be obtained without manual participation for one-by-one verification, the filtering efficiency can be improved.
[0071] In addition, since the initial test case set is deleted, the subsequent related test verification based on the target test case set can improve the test efficiency and avoid other invalid tests.
[0072] To summarize, the optimization processing method of the test case set provided in the embodiment of the present application may include: obtaining a file to be tested, the file to be tested including at least one statement to be tested; mapping the statements to be tested in the file to be tested according to a preset mapping method, and obtaining the mapped statements to be tested; determining a coverage file according to the initial test case set and the mapped file to be tested, the coverage file including multiple coverage parameters, and the coverage parameters are used to indicate the files to be tested and the statements to be tested covered by each initial test case; filtering the initial test case set according to the coverage file to determine the target test case set. By applying the embodiment of the present application, since the repeated and invalid initial test cases in the initial test case set can be automatically filtered out according to the coverage file, manual filtering can be avoided, and therefore the filtering efficiency can be effectively improved.
[0073] Figure 2 A flowchart of another test case set optimization processing method provided in an embodiment of the present application. Optionally, Figure 2 As shown, the above-mentioned mapping of the statements to be tested in the test file according to the preset mapping method to obtain the mapped statements to be tested includes:
[0074] S201. Map a file to be tested according to a first preset mapping method, and obtain the mapped file to be tested.
[0075] S202: Map the statements to be tested in the file to be tested according to the second preset mapping mode and the mapped file to be tested, and obtain the mapped statements to be tested.
[0076] In some embodiments, different mapping methods may be used to map the files to be tested and the statements to be tested, which are not limited here.
[0077] Among them, when mapping, the file to be tested can be mapped according to the first preset mapping method. In some embodiments, the file to be tested can be globally indexed. If there are multiple files to be tested, each file to be tested can be globally mapped to a preset number, letter or combination thereof. After obtaining the mapped file to be tested, the statement to be tested in the file to be tested can be mapped according to the second preset mapping method. In some embodiments, the line mapping can be used as the minimum mapping unit, and each line of the statement to be tested in the file to be tested can be mapped in sequence, and each line of the statement to be tested can be globally mapped to a preset number, letter or combination thereof, but it is not limited to this and can be determined according to a pre-configured mapping relationship. The mapped statement to be tested is obtained so that the mapped statement to be tested can correspond to a unique mapping tag.
[0078] Of course, other minimum mapping units may be selected according to the actual application scenario, for example, segment mapping, basic block mapping, etc., and this application does not limit this.
[0079] For example, in a certain application scenario, including a first file to be tested and a second file to be tested, the first file to be tested and the second file to be tested can be optionally mapped to 1 and 2. For the first line of the test statement of the first file to be tested, it can be mapped to 1_1, and the second line of the test statement of the first file to be tested can be mapped to 1_2, but it is not limited to this. The mapping method can be flexibly selected according to the actual application scenario. For example, for the first line of the test statement of the second file to be tested, it can be mapped to 2_A, and the second line of the test statement of the second file to be tested can be mapped to 2_B, but it is not limited to this.
[0080] Figure 3 A flowchart of another test case set optimization processing method provided in an embodiment of the present application. Optionally, Figure 3 As shown, the initial test case set is filtered according to the coverage file to determine the target test case set, including:
[0081] S301. Obtain coverage parameters of any two initial test cases in an initial test case set according to a coverage file.
[0082] S302: Filter the initial test case set according to the coverage parameters of any two initial test cases in the initial test case set, and obtain the filtered initial test case set as the target test case set.
[0083] Among them, since the coverage file includes multiple coverage parameters, the coverage parameters are used to indicate the files to be tested and the statements to be tested covered by each initial test case. Therefore, when screening, the coverage parameters of any two initial test cases in the initial test case set can be obtained, and the initial test case set is filtered according to the coverage parameters of the any two initial test cases, so as to filter out the repeated and invalid initial test cases in the initial test case set, and obtain the filtered initial test case set, which can be used as the target test case set.
[0084] Optionally, filtering the initial test case set according to the coverage parameters of any two initial test cases in the initial test case set, and obtaining the filtered initial test case set as the target test case set includes:
[0085] If it is determined that the coverage parameters of any two initial test cases in the initial test case set meet the preset conditions, any of the initial test cases are filtered out until the coverage parameters of any two initial test cases in the initial test case set do not meet the preset conditions, and the target test case set is obtained.
[0086] Among them, when filtering, the coverage parameters of any two initial test cases in the initial test case set can be determined to determine whether they meet the preset conditions for filtering. The preset condition can be the condition that any two initial test cases are repeated test cases. It can be understood that if the preset condition is met, any one of the initial test cases can be filtered out and the other initial test case can be retained until the coverage parameters of any two initial test cases in the initial test case set do not meet the preset conditions, that is, there are no repeated and invalid initial test cases in the initial test case set. At this time, the filtered initial test case set obtained is the target test case set.
[0087] Figure 4 A flowchart of another test case set optimization processing method provided in an embodiment of the present application. Optionally, Figure 4 As shown, the above determination that the coverage parameters of any two initial test cases in the initial test case set meet the preset conditions includes:
[0088] S401, calculating the similarity parameter between the coverage parameters of any two initial test cases in the initial test case set.
[0089] S402: If the similarity parameter meets a preset threshold, it is determined that the coverage parameters of any two initial test cases in the initial test case set meet a preset condition.
[0090] The similarity parameter between the coverage parameters of any two initial test cases in the initial test case set can indicate the similarity degree of these two initial test cases, so the similarity parameter can be calculated to filter out any one of the initial test cases. It can be understood that the calculated similarity parameter can be compared with a preset threshold. If the similarity parameter meets the threshold, it can be determined that the coverage parameters of any two initial test cases in the initial test case set reach the preset condition.
[0091] For example, the preset threshold can be X, and the similarity parameter between the coverage parameters of two initial test cases in the initial test case set is x1. Optionally, if x1 < X, it can be considered that the coverage parameters of these two initial test cases reach the preset condition, but the actual judgment method is not limited to this, and it can be flexibly adjusted according to the actual application scenario.
[0092] In some embodiments, optionally, the coverage parameters of any two initial test cases in the initial test case set can be calculated based on the Jaccard similarity coefficient or the Ochiai coefficient.
[0093] Among them, for the calculation of the Jaccard similarity coefficient, the calculation formula can be referred to for calculation. In the formula, A and B can respectively represent the coverage parameters of any two initial test cases in the initial test case set, A ∩ B can represent the intersection of the coverage parameters of any two initial test cases, and A ∪ B can represent the union of the coverage parameters of any two initial test cases. It can be understood that if the J(A, B) value of any two initial test cases is 1, it can be considered that these two initial test cases are the same; if it is not 1, it can be considered that these two initial test cases are different. For the calculation of the Ochiai coefficient, the calculation formula can be referred to for calculation. In the formula, A and B can respectively represent the coverage parameters of any two initial test cases in the initial test case set, n(A ∩ B) can represent the intersection of the coverage parameters of any two initial test cases, can represent the geometric mean of the coverage parameters of any two initial test cases. If the K value of any two initial test cases is 1, it can be considered that these two initial test cases are the same; if it is not 1, it can be considered that these two initial test cases are different. Of course, the calculation method of the similarity parameter is not limited to this.
[0094] Figure 5 It is a flowchart of another method for optimizing a test case set provided by an embodiment of the present application. Optionally, as Figure 5 shown, the above determination that the coverage parameters of any two initial test cases in the initial test case set reach the preset condition includes:
[0095] S501, calculating the difference between the coverage parameters of any two initial test cases in the initial test case set.
[0096] S502: If the difference set is an empty set, determine whether the coverage parameters of any two initial test cases in the initial test case set meet preset conditions.
[0097] Among them, the coverage parameters are used to indicate the files to be tested and the statements to be tested covered by each initial test case. The coverage parameters corresponding to each initial test case can be expressed in the form of a set. For example, the coverage parameters of an initial test case are: {1_1, 1_2, 3_1}, where 1_1 and 1_2 can indicate that the initial test case covers the 1st and 2nd lines of the first file to be tested, and 3_1 can indicate that the initial test case also covers the 1st line of the third file to be tested.
[0098] In some embodiments, the coverage parameters of any two initial test cases in the initial test case set can be determined by calculating the difference between the coverage parameters of any two initial test cases in the initial test case set and judging whether the difference is an empty set. It can be understood that if the difference is an empty set, it means that the two initial test cases are repeated test cases (the same test cases) and their coverage parameters meet the preset conditions. Then, at this time, any one of the initial test cases can be filtered out according to the aforementioned method until the coverage parameters of any two initial test cases in the initial test case set do not meet the preset conditions, and the target test case set is obtained. For details, please refer to the relevant parts mentioned above, and this application will not repeat them here.
[0099] Optionally, the above-mentioned determining the coverage file according to the initial test case set and the mapped to-be-tested file includes:
[0100] Based on the mapped files to be tested, each initial test case in the initial test case set is run to obtain the running results; and the coverage file is determined according to the running results.
[0101] Among them, based on the mapped test file, the coverage file can be obtained with the help of a third-party tool. It is understandable that the test files of different programming languages can be obtained through different third-party tools. For example, the programming language of the test file is Java, Go or Python. Optionally, the coverage file can be obtained through Jacoco, GoCov or Coverage.py third-party tools, but not limited to this.
[0102] In some embodiments, the third-party tool may include multiple functions. Based on the initial test case set and the mapped test file, the multiple functions may be run to obtain the run results, which may indicate the executed test statements and unexecuted test statements in the test file, and the coverage file may be determined based on the run results. Of course, the method for determining the coverage file is not limited to this.
[0103] Figure 6 A flowchart of another test case set optimization processing method provided in an embodiment of the present application. Optionally, Figure 6 As shown, the above method also includes:
[0104] S601. If it is determined according to the coverage file that there is at least one statement to be tested that is not covered in the file to be tested, a new test case is added, and the new test case is used to cover the statement to be tested that is not covered by the initial test case set.
[0105] S602: Update the target test case set according to the new test case and the target test case set.
[0106] It can be understood that, based on the aforementioned embodiment, since the coverage file includes multiple coverage parameters, the coverage parameters are used to indicate the files to be tested and the statements to be tested covered by each initial test case, then the statements to be tested that are not covered in the files to be tested can be determined based on the coverage file. Based on this principle, in order to achieve comprehensive testing and ensure that each test statement in the file to be tested can be covered, a new test case can be added based on the coverage file, and then the target test case set can be updated based on the new test case and the aforementioned target test case set, so that the updated target test case set can cover all the statements to be tested in the file to be tested, thereby ensuring the comprehensiveness of the test.
[0107] Of course, it should be noted that the coverage degree can also be determined based on the coverage file obtained above, and the coverage degree can indicate the degree to which the statements to be tested in the file to be tested are covered. Optionally, if it is determined that the coverage degree does not meet the preset threshold, new test cases can be added. Depending on the actual application scenario, the number of new test cases added may vary, for example, it may include 10, 20 or 50, etc., which is not limited here.
[0108] Based on the above embodiments, the addActivity interface is used as an example for explanation. addActivity is an interface for creating an activity, which may include four parameters: cityid, userids, starttime, and endtime. The cityid parameter represents the city ID, the userids parameter represents the user ID, the starttime parameter represents the start time, and the endtime parameter represents the end time. Optionally, the orthogonal parameters generated by the four parameters are shown in Table 1 below. Optionally, the orthogonal parameters may be generated based on the orthogonal test method.
[0109] Table 1
[0110]
[0111] It can be seen that the initial test case set generated above has a total of 384 initial test cases (4×6×4×4=384). Based on the above embodiment, the files to be tested involved in the addActivity interface can be globally mapped to a number. For example, the addActivity interface includes 3 files to be tested, and their file names are addActivity.ccp, conf.ccp and dao.ccp, respectively. The 3 files to be tested can be mapped to 0, 1 and 2 respectively.
[0112] Based on the description of the above embodiment, when a certain initial test case is run, a coverage file may be generated, through which it can be known which statements to be tested in the file to be tested are covered by the initial test case. For example, if the A test case covers lines 0, 1, and 2 in addActivity.ccp, and lines 5 and 6 in conf.ccp, then the coverage parameter of the A test case can be expressed as AL = {0_0, 0_1, 0_2, 1_5, 1_6}; if the B test case covers lines 2, 3, and 4 in addActivity.ccp, and lines 7 and 8 in dao.ccp, then the coverage parameter of the B test case can be expressed as BL = {0_2, 0_3, 0_4, 2_7, 2_8}. Optionally, the difference between the coverage parameters of use case A and the coverage parameters of use case B can be calculated. If the difference between AL and BL is an empty set, it can be considered that the coverage parameters of use case A and use case B meet the preset conditions, and any test case can be filtered out, for example, test case A or test case B can be filtered out. In this way, the above 384 initial use cases can be streamlined to obtain a minimum test case set, and the minimum test case set contains all valid test cases.
[0113] Figure 7This is a functional module diagram of a test case set optimization processing device provided in an embodiment of the present application. The optimization processing device can be the aforementioned computer, server, processor, terminal device, etc. The basic principle and technical effect of the device are the same as those of the aforementioned corresponding method embodiment. For the sake of brief description, the parts not mentioned in this embodiment can refer to the corresponding content in the method embodiment. Figure 7 As shown, the optimization processing device 100 may include: an acquisition module 110 , a mapping module 120 , a determination module 130 and a filtering module 140 .
[0114] An acquisition module 110 is used to acquire a file to be tested, where the file to be tested includes at least one statement to be tested; a mapping module 120 is used to map the statements to be tested in the file to be tested according to a preset mapping method, and obtain the mapped statements to be tested; a determination module 130 is used to determine a coverage file based on an initial test case set and the mapped file to be tested, where the coverage file includes multiple coverage parameters, and the coverage parameters are used to indicate the files to be tested and the statements to be tested covered by each initial test case; a filtering module 140 is used to filter the initial test case set according to the coverage file, and determine a target test case set.
[0115] Optionally, the mapping module 120 is specifically configured to map the file to be tested according to a first preset mapping method to obtain the mapped file to be tested; and map the statements to be tested in the file to be tested according to a second preset mapping method and the mapped file to be tested to obtain the mapped statements to be tested.
[0116] Optionally, the above-mentioned filtering module 140 is used to obtain the coverage parameters of any two initial test cases in the initial test case set according to the coverage file; filter the initial test case set according to the coverage parameters of any two initial test cases in the initial test case set, and obtain the filtered initial test case set as the target test case set.
[0117] Optionally, the above-mentioned filtering module 140 is specifically used to filter out any initial test case if it is determined that the coverage parameters of any two initial test cases in the initial test case set meet the preset conditions, until the coverage parameters of any two initial test cases in the initial test case set do not meet the preset conditions, thereby obtaining the target test case set.
[0118] Optionally, the above-mentioned filtering module 140 is specifically used to calculate the similarity parameter between the coverage parameters of any two initial test cases in the initial test case set; if the similarity parameter meets a preset threshold, it is determined that the coverage parameters of any two initial test cases in the initial test case set meet the preset conditions.
[0119] Optionally, the filtering module 140 is specifically used to calculate the difference between the coverage parameters of any two initial test cases in the initial test case set; if the difference is an empty set, it is determined that the coverage parameters of any two initial test cases in the initial test case set meet preset conditions.
[0120] Optionally, the determination module 130 is specifically configured to run each of the initial test cases in the initial test case set based on the mapped file to be tested, and obtain the running result; and determine the coverage file according to the running result.
[0121] Figure 8 A functional module diagram of another test case set optimization processing device provided in an embodiment of the present application. Optionally, Figure 8 As shown, the above-mentioned device also includes: an update module 150, which is used to add new test cases if it is determined according to the coverage file that there is at least one statement to be tested that is not covered in the file to be tested, and the new test cases are used to cover the statements to be tested that are not covered by the initial test case set; based on the new test cases and the target test case set, update the target test case set.
[0122] The above-mentioned device is used to execute the method provided by the aforementioned embodiment, and its implementation principle and technical effect are similar, which will not be repeated here.
[0123] The above modules may be one or more integrated circuits configured to implement the above methods, such as one or more application specific integrated circuits (ASIC), or one or more microprocessors (DSP), or one or more field programmable gate arrays (FPGA). For another example, when a module is implemented in the form of a processing element scheduling program code, the processing element may be a general-purpose processor, such as a central processing unit (CPU) or other processor that can call program code. For another example, these modules may be integrated together and implemented in the form of a system-on-a-chip (SOC).
[0124] Fig. 9 The following is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. The electronic device may be a server, computer, terminal device, etc. that implements the idea of the present application. Fig. 9 As shown, the processor can be used on the electronic device 200 and used to execute the functions in the present application.
[0125] The electronic device 200 can be a general-purpose computer or a special-purpose computer, both of which can be used to implement the test case set optimization processing method of the present application. Although only one computer is shown in the present application, for convenience, the functions described in the present application can be implemented in a distributed manner on multiple similar platforms to balance the processing load.
[0126] For example, the electronic device 200 may include a network port 210 connected to a network, one or more processors 220 for executing program instructions, a communication bus 230, and storage media 240 in different forms, such as disks, ROMs, or RAMs, or any combination thereof. Exemplarily, the computer platform may also include program instructions stored in ROMs, RAMs, or other types of non-transitory storage media, or any combination thereof. The method of the present application may be implemented according to these program instructions. The electronic device 200 also includes an input / output (I / O) interface 250 between the computer and other input / output devices (e.g., keyboards, display screens).
[0127] For ease of explanation, only one processor is described in the electronic device 200. However, it should be noted that the electronic device 200 in the present application may also include multiple processors, so the steps performed by one processor described in the present application may also be performed jointly or individually by multiple processors. For example, if the processor of the electronic device 200 performs step A and step B, it should be understood that step A and step B may also be performed jointly by two different processors or individually in one processor. For example, the first processor performs step A, the second processor performs step B, or the first processor and the second processor perform steps A and B together.
[0128] Optionally, the present application further provides a storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the above method embodiment are executed. The specific implementation method and technical effect are similar and will not be repeated here.
[0129] Optionally, the server may be a single server or a server group; the server group may be centralized or distributed (for example, the server may be a distributed system). In some embodiments, the server may be implemented on a cloud platform; as an example only, the cloud platform may include a private cloud, a public cloud, a hybrid cloud, a community cloud, a distributed cloud, an inter-cloud, a multi-cloud, etc., or any combination thereof.
[0130] In some embodiments, the server may include a processor. The processor may process information and / or data related to the service request to perform one or more functions described in the present application. In some embodiments, the processor may include one or more processing cores (e.g., a single-core processor (S) or a multi-core processor (S)). By way of example only, the processor may include a central processing unit (CPU), an application specific integrated circuit (ASIC), an application specific instruction set processor (ASIP), a graphics processing unit (GPU), a physical processing unit (PPU), a digital signal processor (DSP), a field programmable gate array (FPGA), a programmable logic device (PLD), a controller, a microcontroller unit, a reduced instruction set computer (RISC), or a microprocessor, or any combination thereof.
[0131] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0132] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0133] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of hardware plus software functional units.
[0134] The above-mentioned integrated unit implemented in the form of a software functional unit can be stored in a computer-readable storage medium. The above-mentioned software functional unit is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor (English: processor) to perform some steps of the methods of each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (English: Read-Only Memory, abbreviated: ROM), random access memory (English: Random Access Memory, abbreviated: RAM), disk or optical disk and other media that can store program codes.
[0135] It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0136] The above are only preferred embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application shall be included in the scope of protection of the present application. It should be noted that similar numbers and letters represent similar items in the following drawings, so once an item is defined in one drawing, it does not need to be further defined and explained in subsequent drawings. The above are only preferred embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application shall be included in the scope of protection of the present application.
Claims
1. A method for optimizing a test case set, characterized in that: include: Acquire a file to be tested, wherein the file to be tested includes at least one statement to be tested; According to a preset mapping method, the statement to be tested in the file to be tested is mapped to obtain the mapped statement to be tested; wherein the mapped statement to be tested corresponds to a unique mapping tag; Determine a coverage file according to the initial test case set and the mapped files to be tested; the initial test case set includes a plurality of initial test cases; the coverage file includes a plurality of coverage parameters, and the coverage parameters are used to indicate the files to be tested and the statements to be tested covered by each initial test case; The initial test case set is filtered according to the coverage file to determine the target test case set; including: according to the coverage file, obtaining the coverage parameters of any two of the initial test cases in the initial test case set; according to the coverage parameters of any two of the initial test cases in the initial test case set, the initial test case set is filtered to obtain the filtered initial test case set as the target test case set; wherein, based on the Jaccard similarity coefficient or the falling sum coefficient, the coverage parameters of any two of the initial test cases in the initial test case set are calculated; the coverage parameters corresponding to each initial test case are expressed in the form of a set.
2. The method according to claim 1, characterized in that The step of mapping the statement to be tested in the file to be tested according to a preset mapping method to obtain the mapped statement to be tested includes: Mapping the file to be tested according to a first preset mapping method to obtain the mapped file to be tested; According to the second preset mapping mode and the mapped file to be tested, the statement to be tested in the file to be tested is mapped to obtain the mapped statement to be tested.
3. The method according to claim 1, characterized in that The filtering the initial test case set according to the coverage parameters of any two initial test cases in the initial test case set, and obtaining the filtered initial test case set as the target test case set, comprises: If it is determined that the coverage parameters of any two of the initial test cases in the initial test case set meet the preset conditions, any of the initial test cases are filtered out until the coverage parameters of any two of the initial test cases in the initial test case set do not meet the preset conditions, and the target test case set is obtained.
4. The method according to claim 1, characterized in that: The determining that coverage parameters of any two of the initial test cases in the initial test case set meet preset conditions includes: Calculating a similarity parameter between coverage parameters of any two of the initial test cases in the initial test case set; If the similarity parameter meets a preset threshold, it is determined that the coverage parameters of any two initial test cases in the initial test case set meet a preset condition.
5. The method according to claim 3, characterized in that: The determining that coverage parameters of any two of the initial test cases in the initial test case set meet preset conditions includes: Calculate the difference between the coverage parameters of any two of the initial test cases in the initial test case set; If the difference set is an empty set, it is determined that the coverage parameters of any two initial test cases in the initial test case set meet preset conditions.
6. The method according to claim 1, characterized in that Determining the coverage file according to the initial test case set and the mapped to-be-tested file includes: Based on the mapped file to be tested, run each of the initial test cases in the initial test case set to obtain a running result; The coverage file is determined according to the running result.
7. The method according to any one of claims 1 to 6, characterized in that: The method further comprises: If it is determined according to the coverage file that at least one statement to be tested is not covered in the file to be tested, a new test case is added, where the new test case is used to cover the statement to be tested that is not covered by the initial test case set; According to the new test case and the target test case set, the target test case set is updated.
8. The method according to claim 7, characterized in that The method further comprises: Determine the coverage degree according to the coverage file; the coverage degree indicates the degree to which the statements to be tested in the file to be tested are covered; If it is determined that the coverage level does not meet the preset level threshold, a new test case is added.
9. A test case set optimization processing device, characterized in that: include: an acquisition module, a mapping module, a determination module, and a filtering module; The acquisition module is used to acquire a file to be tested, wherein the file to be tested includes at least one statement to be tested; The mapping module is used to map the statement to be tested in the file to be tested according to a preset mapping method, and obtain the mapped statement to be tested; wherein the mapped statement to be tested corresponds to a unique mapping tag; The determination module is used to determine the coverage file according to the initial test case set and the mapped to-be-tested file; the initial test case set includes a plurality of initial test cases; the coverage file includes a plurality of coverage parameters, and the coverage parameters are used to indicate the to-be-tested file and the to-be-tested statement covered by each initial test case; The filtering module is used to filter the initial test case set according to the coverage file to determine the target test case set; specifically, to: obtain the coverage parameters of any two initial test cases in the initial test case set according to the coverage file; filter the initial test case set according to the coverage parameters of any two initial test cases in the initial test case set to obtain the filtered initial test case set as the target test case set; wherein, based on the Jaccard similarity coefficient or the falling sum coefficient, the coverage parameters of any two initial test cases in the initial test case set are calculated; and the coverage parameters corresponding to each initial test case are expressed in the form of a set.
10. An electronic device, characterized in that: include: A processor, a storage medium and a bus, wherein the storage medium stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor and the storage medium communicate via the bus, and the processor executes the machine-readable instructions to perform the steps of the optimization processing method for the test case set as described in any one of claims 1-8.
11. A storage medium, characterized in that: The storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the test case set optimization processing method according to any one of claims 1 to 8 are executed.
Citation Information
Patent Citations
Method for generating server-side test suite, terminal device and storage medium
CN109446060A
Code coverage rate testing method and device
CN110471850A