A test case screening method, device, computer device, and storage medium

By calculating the code of the test case to cover the data similarity and filtering similar test cases, the duplication and redundancy problems caused by the large number of test cases are solved, and the testing efficiency is improved.

CN112559365BActive Publication Date: 2025-07-22SHANGHAI PINWEI INFORMATION TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202011537961.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-12-23
Publication Date
2025-07-22
Estimated Expiration
2040-12-23

AI Technical Summary

Technical Problem

In the prior art, the large number of test cases leads to repeated and redundant testing work and low testing efficiency.

Method used

By obtaining test cases for the target service, using the test case execution engine to execute test cases, obtain code coverage data, calculate the similarity between code coverage data, and filter the test cases corresponding to similar code coverage data.

Benefits of technology

Effectively reduce the number of software test cases, avoid redundant test cases execution, and improve testing efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112559365B_ABST
    Figure CN112559365B_ABST
Patent Text Reader

Abstract

The present application relates to a test case screening method, apparatus, computer device, and storage medium, belonging to the technical field of software testing. The method includes: obtaining a plurality of test cases for a target service; executing the plurality of test cases through a test case execution engine to obtain code coverage data corresponding to each test case; obtaining the similarity between the code coverage data corresponding to each test case, and determining code coverage data that are similar to each other based on each similarity; screening the test cases corresponding to the code coverage data that are similar to each other. Since the test cases corresponding to the code coverage data that are similar to each other are screened in the present application, the screened test cases are not only highly targeted, but also can effectively reduce the number of test cases of the software, avoid the execution of a large number of redundant test cases, save test time, and improve the test efficiency of the software system.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the technical field of software testing, and particularly to a test case screening method, apparatus, computer device, and storage medium. Background Art

[0002] With the development of software testing technology, in the testing process, to measure a certain special target, test cases are usually written for the special target for automated testing.

[0003] In the prior art, since the software system may undergo multiple modifications or upgrades, after each modification or upgrade, all test cases are used to test the software system multiple times. This method does not screen the test cases, and the pertinence of the test cases is not strong, which may lead to repetitive and redundant work in the testing process, resulting in low testing efficiency. Summary of the Invention

[0004] In view of this, the present invention provides a test case screening method, apparatus, computer device, and storage medium to solve the problem in the prior art that the large number of test cases leads to repetitive and redundant testing work and low testing efficiency.

[0005] In a first aspect, a test case screening method is provided, and the method includes:

[0006] Obtain a plurality of test cases for a target service;

[0007] Execute the plurality of test cases through a test case execution engine to obtain code coverage data corresponding to each of the test cases;

[0008] Obtain the similarity between the code coverage data corresponding to each of the test cases, and determine the code coverage data that are similar to each other according to the similarities;

[0009] Screen the test cases corresponding to the code coverage data that are similar to each other.

[0010] Further, the obtaining of the plurality of test cases for the target service includes:

[0011] Obtain the interface parameter information of the target service, where the interface parameter information includes the actual parameter values of all interface parameters obtained by parsing the actual traffic data of the target service;

[0012] Perform machine learning on all the interface parameters according to the actual parameter values of each interface parameter and the characteristic information of the target service to obtain the parameter value rules of each interface parameter;

[0013] Assign values to each of the interface parameters according to the parameter value rules of each of the interface parameters, and generate multiple test cases for the target service.

[0014] Further, before assigning values to each of the interface parameters according to the parameter value rules of each of the interface parameters and generating multiple test cases for the target service, the method further includes:

[0015] For each of the interface parameters, determine whether the interface parameter has a preset parameter value rule. If so, push the preset parameter value rule of the interface parameter and the parameter value rule obtained through machine learning to the user side for the user to select;

[0016] Receive the selection information of the parameter value rule of the interface parameter from the user side, and determine the parameter value rule indicated by the selection information as the parameter value rule of the interface parameter.

[0017] Further, assigning values to each of the interface parameters according to the parameter value rules of each of the interface parameters and generating multiple test cases for the target service includes:

[0018] Assign values to each of the interface parameters according to the parameter value rules of each of the interface parameters, and in combination with equivalence class partitioning or / and boundary value method, generate multiple test cases for the target service.

[0019] Further, obtaining the similarity between the code coverage data corresponding to each of the test cases, and determining the code coverage data that are similar to each other according to each of the similarities includes:

[0020] Bind each of the test cases to the program code segments covered by each of the test cases according to the code coverage data corresponding to each of the test cases;

[0021] For each target test case among all the test cases, calculate the degree of similarity between the program code segment bound to the target test case and the program code segments bound to the other test cases among all the test cases, and obtain the similarity between the code coverage data corresponding to the target test case and the code coverage data corresponding to the other test cases according to the calculation result;

[0022] Determine whether the similarity meets the preset similarity condition. If so, determine that the code coverage data corresponding to the target test case and the code coverage data corresponding to the other test cases are similar to each other.

[0023] Further, screening the test cases corresponding to the code coverage data that are similar to each other includes:

[0024] Classify the test cases corresponding to the mutually similar code coverage data into the same test case subset;

[0025] Determine the code coverage rate corresponding to each test case in each test case subset;

[0026] Screen each test case subset according to the code coverage rate corresponding to each test case in each test case subset.

[0027] Further, the screening of each test case subset according to the code coverage rate corresponding to each test case in each test case subset includes:

[0028] For each test case subset, sort each test case in the test case subset in descending order according to the code coverage rate to obtain a sorting result; and

[0029] Select the top N test cases in the sorting result as the optimal test cases, where N is greater than or equal to 1.

[0030] In a second aspect, a test case screening device is provided, and the device includes:

[0031] A use case acquisition module for acquiring a plurality of test cases of a target service;

[0032] A use case execution module for executing a plurality of the test cases through a test case execution engine to obtain code coverage data corresponding to each of the test cases;

[0033] A similarity determination module for obtaining the similarity between the code coverage data corresponding to each test case and determining mutually similar code coverage data according to each similarity;

[0034] A use case screening module for screening the test cases corresponding to the mutually similar code coverage data respectively.

[0035] Further, the use case acquisition module includes:

[0036] A parameter acquisition unit for acquiring interface parameter information of the target service, where the interface parameter information includes the actual parameter values of all interface parameters obtained by analyzing the actual traffic data of the target service;

[0037] A machine learning unit for performing machine learning on all the interface parameters according to the actual parameter values of each interface parameter and the feature information of the target service to obtain the parameter value rules of each interface parameter;

[0038] A use case generation unit, configured to assign values to each of the interface parameters according to the parameter value rules of each of the interface parameters, and generate multiple test cases for the target service.

[0039] Further, the apparatus further includes a parameter rule processing module, and the parameter rule processing module is configured to:

[0040] For each of the interface parameters, determine whether there is a preset parameter value rule for the interface parameter. If so, push the preset parameter value rule of the interface parameter and the parameter value rule obtained by machine learning to the user side for the user to select;

[0041] Receive the selection information of the parameter value rule of the interface parameter from the user side, and determine the parameter value rule indicated by the selection information as the parameter value rule of the interface parameter.

[0042] Further, the use case generation unit is specifically configured to:

[0043] Assign values to each of the interface parameters according to the parameter value rules of each of the interface parameters, and combine equivalent class partitioning or / and boundary value method to generate multiple test cases for the target service.

[0044] Further, the similarity determination module is specifically configured to:

[0045] Bind each of the test cases to the program code segments covered by each of the test cases according to the code coverage data corresponding to each of the test cases;

[0046] For each target test case among all the test cases, calculate the degree of similarity between the program code segment bound to the target test case and the program code segments bound to other test cases among all the test cases, and obtain the similarity between the code coverage data corresponding to the target test case and the code coverage data corresponding to the other test cases according to the calculation result;

[0047] Determine whether the similarity meets a preset similarity condition. If so, determine that the code coverage data corresponding to the target test case and the code coverage data corresponding to the other test cases are similar to each other.

[0048] Further, the use case screening module includes:

[0049] A use case classification unit, configured to classify the test cases corresponding to the code coverage data that are similar to each other into the same test case subset;

[0050] A code coverage determination unit for determining the code coverage corresponding to each of the test cases in each of the test case subsets;

[0051] A test case screening unit for screening each of the test case subsets according to the code coverage corresponding to each of the test cases in each of the test case subsets.

[0052] Further, the test case screening unit is specifically configured to:

[0053] For each of the test case subsets, sort each of the test cases in the test case subset in descending order of code coverage to obtain a sorting result; and

[0054] Screen out the top N test cases in the sorting result as the optimal test cases, where N is greater than or equal to 1.

[0055] In a third aspect, a computer device is provided, including a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the computer program, the following operation steps are implemented:

[0056] Obtain a plurality of test cases for a target service;

[0057] Execute the plurality of test cases through a test case execution engine to obtain code coverage data corresponding to each of the test cases;

[0058] Obtain the similarity between the code coverage data corresponding to each of the test cases, and determine the code coverage data that are similar to each other according to the similarities;

[0059] Screen the test cases corresponding to the code coverage data that are similar to each other.

[0060] In a fourth aspect, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the following operation steps are implemented:

[0061] Obtain a plurality of test cases for a target service;

[0062] Execute the plurality of test cases through a test case execution engine to obtain code coverage data corresponding to each of the test cases;

[0063] Obtain the similarity between the code coverage data corresponding to each of the test cases, and determine the code coverage data that are similar to each other according to the similarities;

[0064] Screen the test cases corresponding to the code coverage data that are similar to each other.

[0065] The test case screening method, device, computer device and storage medium provided by the present invention obtain a plurality of test cases for a target service; execute the plurality of test cases through a test case execution engine to obtain code coverage data corresponding to each test case; obtain the similarity between the code coverage data corresponding to each test case, and determine the code coverage data that are similar to each other according to each similarity; screen the test cases corresponding to the code coverage data that are similar to each other. Since the test cases corresponding to the code coverage data that are similar to each other are screened, the screened test cases not only have strong pertinence, but also can effectively reduce the number of test cases of the software, avoid the execution of a large number of redundant test cases, save test time, and improve the test efficiency of the software system. Description of the Drawings

[0066] Figure 1 It is a schematic flowchart of the test case screening method in an embodiment;

[0067] Figure 2 is Figure 1 a schematic flowchart of step 101 in the method shown;

[0068] Figure 3 is Figure 1 a schematic flowchart of step 103 in the method shown;

[0069] Figure 4 is Figure 1 a schematic flowchart of step 104 in the method shown;

[0070] Figure 5 It is a structural block diagram of a test case screening device in an embodiment;

[0071] Figure 6 It is an internal structure diagram of a computer device in an embodiment. Detailed Embodiments

[0072] In order to make the objectives, technical solutions and advantages of the present application clearer, the present application will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0073] It should be noted that unless otherwise clearly required by the context, the words such as "including" and "comprising" in the whole specification and claims should be interpreted as the meaning of including rather than exclusive or exhaustive; that is, the meaning of "including but not limited to".

[0074] In addition, in the description of the present invention, it should be understood that terms such as "first", "second", etc. are only used for descriptive purposes and cannot be construed as indicating or implying relative importance. In addition, in the description of the present invention, unless otherwise specified, the meaning of "a plurality of" is two or more.

[0075] As described in the foregoing background art, currently, since the software system may undergo multiple modifications or upgrades, after each modification or upgrade, all test cases are used to test the software system multiple times. This method does not screen the test cases, and the pertinence of the test cases is not strong, which may lead to repeated and redundant work during the testing process, resulting in low testing efficiency. For this reason, the present application provides a test case screening method. Since this method screens the test cases corresponding to each code coverage data and its similar code coverage data, the screened test cases are not only highly targeted, but also can avoid the execution of a large number of redundant test cases, saving testing time and improving the testing efficiency of the software system.

[0076] In one embodiment, a test case screening method is provided. This method can be applied to a computer device, and the computer device can be implemented by an independent server or a server cluster composed of multiple servers. As Figure 1 shown, this method may include the following steps:

[0077] 101. Obtain a plurality of test cases for the target service.

[0078] Among them, the target service can be any type of service. The target service usually has one or more interfaces. The use case data refers to the test data used for interface testing in the test case, which may include interface request data and expected interface response data.

[0079] Specifically, the present invention does not limit the process of obtaining test cases.

[0080] 102. Execute a plurality of test cases through a test case execution engine to obtain the code coverage data corresponding to each test case.

[0081] Among them, the service program code corresponding to the target service is stored in a preset service code. The service program code includes multiple program code segments, and different program code segments have different program functions.

[0082] Specifically, multiple test cases are executed in a test environment by a test case execution engine to obtain a coverage report of the service code of the target service, and code coverage data is extracted from the coverage report. The code coverage data includes: code information covered by tests, code information not covered by tests, and code coverage rate. The code information can specifically be code features, and the code features include but are not limited to: business line, service name, class name, method name, and line number of the code, etc. The code coverage rate can be calculated based on the code information covered by tests and the code information not covered by tests. For example, calculate the ratio of the number of lines of code covered by a certain test case to the total number of lines of the program code of the target service to obtain the code coverage rate of this test case. Here, the test environment refers to an environment that simulates a near-real production environment. For example, it can be a staging test environment.

[0083] 103. Obtain the similarity between the code coverage data corresponding to each test case, and determine the code coverage data that are similar to each other based on each similarity.

[0084] Specifically, the similarity between the code coverage data corresponding to each test case can be obtained by analyzing the code information covered by tests, the code information not covered by tests, and the code coverage rate included in the code coverage data. According to the similarity between the code coverage data corresponding to each test case and a preset similarity condition, determine whether there are at least two pieces of code coverage data whose similarity meets the preset similarity condition. If so, determine that these at least two pieces of code coverage data are code coverage data that are similar to each other.

[0085] Among them, the preset similarity condition can be set according to actual needs. For example, when the similarity between two pieces of code coverage data exceeds a preset similarity value, determine that these two pieces of code coverage data are similar to each other.

[0086] 104. Screen the test cases corresponding to the code coverage data that are similar to each other.

[0087] Specifically, screen out the test cases that meet the preset conditions from the test cases corresponding to the code coverage data that are similar to each other as the optimal test cases.

[0088] The use case screening method provided by the embodiments of the present invention, by obtaining the similarity between the code coverage data corresponding to each test case, determining the code coverage data that are similar to each other based on each similarity, and screening the test cases corresponding to the code coverage data that are similar to each other, the screened test cases are not only highly targeted, but also can effectively reduce the number of test cases of the software, avoid the execution of a large number of redundant test cases, save test time, and improve the test efficiency of the software system.

[0089] In one embodiment, as Figure 2 shown, the implementation process of obtaining multiple test cases for the target service in step 101 may include the steps:

[0090] 1011. Obtain the interface parameter information of the target service, where the interface parameter information includes the actual parameter values of all interface parameters obtained by parsing the actual traffic data of the target service.

[0091] Among them, the actual traffic data of the target service includes the actual traffic data of each interface of the target service, and the actual traffic data includes request messages and response messages.

[0092] Specifically, the actual traffic data of the target service in the production environment can be pre-recorded and stored in the database. When the server receives a test case generation instruction, the selected target service is determined according to the test case generation instruction, the actual traffic data of the target service is pulled from the database, and after the actual traffic data is desensitized, the actual traffic data is parsed according to the interface input and output parameter structures corresponding to each interface of the target service to obtain information such as interface names, interface parameter field names, and field attributes corresponding to interface parameters. In addition, other information of the interface parameters can also be parsed, such as interface uniform resource locators, interface method types, interface input parameter types, and interface output parameter types.

[0093] Among them, the field types of the interface parameters include input parameter fields and output parameter fields, and each parameter field has a corresponding parameter field name, field attribute information corresponding to the parameter field name, and field type. The preset parameter value rules corresponding to each parameter field are pre-stored in the server's database, and the parameter value rules include parameter value ranges and / or regular expressions. The parameter value ranges include, for example, security values, upper boundary values, lower boundary values, null values, and parameter values of non-this field type.

[0094] 1012. Perform machine learning on all interface parameters according to the actual parameter values of each interface parameter and the characteristic information of the target service to obtain the parameter value rules of each interface parameter.

[0095] Among them, the characteristic information of the target service includes information such as service name, domain name, and business function points of the target service.

[0096] Specifically, perform machine learning on the parameter field names of the interface parameters, the actual parameter values corresponding to the parameter field names, the service name of the target service, the domain name, and the business function points of the target service, etc., and analyze the parameter value rules of each interface parameter, that is, find the rules of the parameter value rules.

[0097] Among them, machine learning can adopt algorithms such as clustering algorithms, neural networks, Bayesian, regression analysis, etc. to analyze the parameter value-taking rules of each interface parameter, and generate regular results of the parameter value-taking rules (such as clustering or classification results, etc.).

[0098] It should be understood that the embodiments of the present invention do not limit the specific machine learning process.

[0099] 1013. According to the parameter value-taking rules of each interface parameter, assign values to each interface parameter to generate multiple test cases for the target service.

[0100] Among them, the implementation process of step 103 may include:

[0101] According to the parameter value-taking rules of each interface parameter, and in combination with the equivalence class partitioning or / and boundary value method, assign values to each interface parameter to generate multiple test cases for the target service.

[0102] Among them, the equivalence class partitioning method divides the test data into valid equivalence class data and invalid equivalence class data. The valid equivalence class data is a reasonable and meaningful data set that conforms to the defined rules, and the invalid equivalence class data is an unreasonable and meaningless data set; the boundary value analysis method tests the boundaries of the input or output by selecting the upper points, inner points, and off points of the specified data domain.

[0103] In addition, other test case design methods can also be considered, such as scenario method, orthogonal table, etc. The embodiments of the present invention do not limit the specific test case generation process.

[0104] In this embodiment, since the interface parameter information of the target service includes the actual parameter values of each of the multiple interface parameters obtained by parsing the actual traffic data of the target service, machine learning is performed on all interface parameters according to the actual parameter values of each interface parameter and the characteristic information of the target service to obtain the parameter value-taking rules of each interface parameter, and according to the parameter value-taking rules of each interface parameter, assign values to each interface parameter to generate multiple test cases for the target service, which can make the test cases closer to the actual traffic in the production environment, thereby effectively improving the accuracy of the test cases. In addition, using this method can also quickly and efficiently generate test cases for the target service, improve the generation efficiency of test cases, and thus reduce the workload of testers in writing automated test cases.

[0105] In one embodiment, before the above step 1013 is executed, the method further includes:

[0106] For each interface parameter, determine whether there is a preset parameter value-taking rule for the interface parameter. If so, push the preset parameter value-taking rule of the interface parameter and the parameter value-taking rule obtained by machine learning to the user side for the user to select; and

[0107] Receive the selection information of the parameter value rule for the interface parameter from the user side, and determine the parameter value rule indicated by the selection information as the parameter value rule of the interface parameter.

[0108] Among them, the preset parameter value rules corresponding to the parameter fields of each interface parameter are pre-stored in the database of the server. Among them, a visual configuration interface can be provided to the user side to receive the parameter value rules for the user to configure the interface parameters through the visual configuration interface, and store the parameter value rules configured for the interface parameter fields and the corresponding ones in the form of key-value pairs in the database.

[0109] In this embodiment, by pushing the preset parameter value rules of the interface parameter and the parameter value rules obtained through machine learning to the user side for the user to select, and receiving the selection information of the parameter value rule for the interface parameter from the user side, and determining the parameter value rule indicated by the selection information as the parameter value rule of the interface parameter, the parameter value rule of the interface parameter can be made more accurate, thereby improving the accuracy of subsequent test case generation.

[0110] In one embodiment, pushing the preset parameter value rules of the interface parameter and the parameter value rules obtained through machine learning to the user side for the user to select, this process may include:

[0111] Calculate the similarity between the preset parameter value rules of the interface parameter and the parameter value rules obtained through machine learning, determine the target interface parameters whose similarity results exceed the preset similarity threshold, and push the preset parameter value rules of the target interface parameters and the parameter value rules obtained through machine learning to the user side.

[0112] Among them, the preset similarity threshold can be preset according to actual needs. The similarity calculation method can refer to the prior art, such as using Euclidean distance, Hamming distance, cosine distance, etc.

[0113] In this embodiment, by pushing the preset parameter value rules of the target interface parameters whose similarity results exceed the preset similarity threshold and the parameter value rules obtained through machine learning to the user side, and determining the parameter value rule indicated by the received selection information as the parameter value rule of the interface parameter, the workload of the user's selection operation for the parameter value rule can be reduced, and the generation efficiency of subsequent test cases can be further improved.

[0114] In one embodiment, as Figure 3 shown, obtaining the similarity between the code coverage data corresponding to each test case in the above step 103, and determining the code coverage data that are similar to each other according to each similarity, this process may include the steps:

[0115] 1031. Bind each test case to the program code segments covered by that test case according to the code coverage data corresponding to each test case.

[0116] Specifically, based on the code coverage information in the code coverage data corresponding to each test case, determine the program code segments covered by each test case, and establish a binding relationship between each test case and the program code segments covered by that test case. When establishing the "test case - code segment" binding relationship, it is used to indicate which code lines are covered by each test case, that is, each test case is bound to the code segments it covers.

[0117] It can be understood that a test case can be bound to one or more program code segments, and a program code segment contains at least one code line.

[0118] 1032. For each target test case among all test cases, calculate the degree of similarity between the program code segments bound to the target test case and the program code segments bound to other test cases among all test cases, and based on the calculation result, obtain the similarity between the code coverage data corresponding to the target test case and the code coverage data corresponding to other test cases.

[0119] Among them, the target test case can be a test case randomly selected from all test cases, and other test cases are the test cases other than the target test case among all test cases.

[0120] For the sake of convenience of description, the program code segments bound to the target test case are regarded as the first program code lines, and the program code segments bound to other test cases are regarded as the second program code segments.

[0121] Specifically, the implementation process of step 1032 can include:

[0122] For the target test case, traverse each other test case among all test cases except this target test case. When each other test case is traversed, perform feature matching on the code features of the first program code segment bound to the target test case and the second program code segment bound to the traversed other test case, calculate the degree of similarity between the first program code segment bound to the target test case and the second program code segment bound to the other test case, and determine the degree of similarity as the similarity between the code coverage data corresponding to the test case and the code coverage data corresponding to the other test case. This embodiment does not limit the specific process of obtaining the similarity.

[0123] It can be understood that the higher the degree of similarity between the program code segments bound by two test cases respectively, the more similar the code coverage data corresponding to these two test cases. The number of program code segments bound by these two test cases respectively can be one or multiple.

[0124] 1033. Determine whether the similarity meets a preset similarity condition. If it meets, determine that the code coverage data corresponding to the target test case and the code coverage data corresponding to other test cases are similar to each other.

[0125] Among them, the preset similarity condition can be set as: when the similarity between any two pieces of code coverage data exceeds a preset threshold, then the two pieces of code coverage data are similar code coverage data. It can be understood that the preset threshold can be set according to the actual situation. For example, it can be set to 80%.

[0126] In one embodiment, as Figure 4 shown, in step 104 above, screening is performed on the test cases corresponding to the code coverage data that are similar to each other. This process may include the steps:

[0127] 1041. Classify the test cases corresponding to the code coverage data that are similar to each other into the same test case subset.

[0128] Among them, classifying the test cases corresponding to the code coverage data that are similar to each other into the same test case subset results in multiple test case subsets.

[0129] Exemplarily, if the code coverage data corresponding to test case a and test case b respectively are similar to each other, then classify test case a and test case b into the same test case subset.

[0130] It can be understood that the code coverage rates corresponding to the test cases in the same test case subset are similar to each other, while they are not similar to the code coverage rates corresponding to the test cases in other test case subsets.

[0131] 1042. Determine the code coverage rate corresponding to each test case in each test case subset.

[0132] 1043. Screen each test case subset according to the code coverage rate corresponding to each test case in each test case subset.

[0133] Specifically, screening each test case subset according to the code coverage rate corresponding to each test case in each test case subset may include:

[0134] For each subset of test cases, sort each test case in the subset of test cases in descending order of code coverage to obtain a sorting result, and select the top N test cases in the sorting result as the optimal test cases, where N is greater than or equal to 1.

[0135] In this embodiment, the test cases corresponding to the code coverage data that are similar to each other are classified into the same test subset to obtain multiple test subsets, and each test subset is filtered according to the code coverage corresponding to each test case in each test subset. Not only are the selected test cases highly targeted, which can effectively reduce the number of test cases of the software and avoid the execution of a large number of redundant test cases, but also the selected test cases are more comprehensive, so that even the program code segments covered by fewer test cases can be tested, which can improve the test effectiveness and comprehensiveness.

[0136] In one embodiment, a test case screening device is provided, as Figure 5 shown, the device may include:

[0137] A use case acquisition module 51, configured to acquire multiple test cases of a target service;

[0138] A use case execution module 52, configured to execute multiple test cases through a test case execution engine to obtain code coverage data corresponding to each test case;

[0139] A similarity determination module 53, configured to obtain the similarity between the code coverage data corresponding to each test case, and determine the code coverage data that are similar to each other according to each similarity;

[0140] A use case screening module 54, configured to screen the test cases corresponding to the code coverage data that are similar to each other.

[0141] In one embodiment, the use case acquisition module 51 includes:

[0142] A parameter acquisition unit, configured to acquire interface parameter information of the target service, where the interface parameter information includes the actual parameter values of all interface parameters obtained by parsing the actual traffic data of the target service;

[0143] A machine learning unit, configured to perform machine learning on all interface parameters according to the actual parameter values of each interface parameter and the feature information of the target service to obtain the parameter value rules of each interface parameter;

[0144] A use case generation unit, configured to assign values to each interface parameter according to the parameter value rules of each interface parameter to generate multiple test cases of the target service.

[0145] In one embodiment, the device further includes a parameter rule processing module, and the parameter rule processing module is configured to:

[0146] For each interface parameter, determine whether there is a preset parameter value rule for the interface parameter. If so, push the preset parameter value rule of the interface parameter and the parameter value rule obtained through machine learning to the user side for the user to select;

[0147] Receive the selection information of the parameter value rule for the interface parameter from the user side, and determine the parameter value rule indicated by the selection information as the parameter value rule of the interface parameter.

[0148] In one embodiment, the use case generation unit is specifically configured to:

[0149] Assign values to each interface parameter according to the parameter value rules of each interface parameter, and combine the equivalence class partitioning or / and boundary value method to generate multiple test cases for the target service.

[0150] In one embodiment, the similarity determination module 53 is specifically configured to:

[0151] Bind each test case to the program code segment covered by each test case according to the code coverage data corresponding to each test case;

[0152] For each target test case among all test cases, calculate the degree of similarity between the program code segment bound to the target test case and the program code segments bound to other test cases among all test cases, and obtain the similarity between the code coverage data corresponding to the target test case and the code coverage data corresponding to other test cases according to the calculation result.

[0153] Determine whether the similarity meets the preset similarity condition. If so, determine that the code coverage data corresponding to the target test case and the code coverage data corresponding to other test cases are similar to each other.

[0154] In one embodiment, the use case screening module 54 includes:

[0155] A use case classification unit, configured to classify the test cases corresponding to the code coverage data that are similar to each other into the same test case subset;

[0156] A coverage rate determination unit, configured to determine the code coverage rate corresponding to each test case in each test case subset;

[0157] A use case screening unit, configured to screen each test case subset according to the code coverage rate corresponding to each test case in each test case subset.

[0158] In one embodiment, the use case screening unit is specifically configured to:

[0159] For each subset of test cases, sort each test case in the subset of test cases in descending order of code coverage to obtain a sorting result; and

[0160] Filter out the top N test cases in the sorting result as the optimal test cases, where N is greater than or equal to 1.

[0161] For the specific limitations of the test case filtering device, reference can be made to the limitations of the test case filtering method in the above text, which will not be elaborated here. Each module in the above test case filtering device can be implemented in whole or in part by software, hardware, and their combinations. The above modules can be embedded in or independent of the processor in the computer device in the form of hardware, or stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.

[0162] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as Figure 6 shown. The server includes a processor, a memory, and a network interface connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with other devices through a network connection. When the computer program is executed by the processor, it implements a test case filtering method.

[0163] Those skilled in the art can understand that Figure 6 the structure shown in is only a block diagram of some structures related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine some components, or have different component arrangements.

[0164] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the computer program, the following steps are implemented:

[0165] Obtain multiple test cases of the target service;

[0166] Execute multiple test cases through a test case execution engine to obtain code coverage data corresponding to each test case;

[0167] Obtain the similarity between the code coverage data corresponding to each test case, and determine the code coverage data that are similar to each other based on each similarity;

[0168] Screen the test cases corresponding to the code coverage data that are similar to each other.

[0169] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the following steps are implemented:

[0170] Obtain multiple test cases of a target service;

[0171] Execute multiple test cases through a test case execution engine to obtain the code coverage data corresponding to each test case;

[0172] Obtain the similarity between the code coverage data corresponding to each test case, and determine the code coverage data that are similar to each other based on each similarity;

[0173] Screen the test cases corresponding to the code coverage data that are similar to each other.

[0174] Those of ordinary skill in the art can understand that all or part of the processes in the methods of the above embodiments can be completed by instructing relevant hardware through a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above methods. Among them, any reference to a memory, storage, database, or other medium used in the various embodiments provided in the present application can include non-volatile and / or volatile memories. Non-volatile memories can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memories can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.

[0175] The technical features of the above embodiments can be combined arbitrarily. For the sake of concise description, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, it should be considered as the scope described in this specification.

[0176] The above-described embodiments merely represent several implementation manners of the present application. The description is relatively specific and detailed, but it should not be construed as a limitation on the scope of the invention patent. It should be noted that for those of ordinary skill in the art, without departing from the concept of the present application, several modifications and improvements can still be made, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the appended claims.

Claims

1. A test case screening method, characterized in that, The method includes: Obtaining interface parameter information of a target service, where the interface parameter information includes the actual parameter values of all interface parameters obtained by parsing the actual traffic data of the target service; Performing machine learning on all the interface parameters according to the actual parameter values of each interface parameter and the characteristic information of the target service to obtain the parameter value rules of each interface parameter; Assigning values to each interface parameter according to the parameter value rules of each interface parameter and in combination with equivalence class partitioning or / and boundary value method to generate multiple test cases for the target service; Executing the multiple test cases through a test case execution engine to obtain a coverage report of the service code of the target service; Obtaining code coverage data corresponding to each test case according to the coverage report; Binding each test case to the program code segment covered by each test case according to the code coverage data corresponding to each test case; For each target test case among all the test cases, calculating the degree of similarity between the program code segment bound to the target test case and the program code segments bound to other test cases among all the test cases, and obtaining the similarity between the code coverage data corresponding to the target test case and the code coverage data corresponding to the other test cases according to the calculation result; Judging whether the similarity meets a preset similarity condition. If it meets, determining that the code coverage data corresponding to the target test case and the code coverage data corresponding to the other test cases are similar to each other; Classifying the test cases corresponding to the code coverage data that are similar to each other into the same test case subset; Determining the code coverage rate corresponding to each test case in each test case subset; Screening each test case subset according to the code coverage rate corresponding to each test case in each test case subset.

2. The method according to claim 1, wherein Before assigning values to each interface parameter according to the parameter value rules of each interface parameter to generate multiple test cases for the target service, the method further includes: For each interface parameter, judging whether there is a preset parameter value rule for the interface parameter. If there is, pushing the preset parameter value rule of the interface parameter and the parameter value rule obtained by machine learning to the user side for the user to select; Receiving the selection information of the parameter value rule of the interface parameter from the user side and determining the parameter value rule indicated by the selection information as the parameter value rule of the interface parameter.

3. The method according to claim 1, wherein The screening each test case subset according to the code coverage rate corresponding to each test case in each test case subset includes: For each test case subset, sorting each test case in the test case subset in descending order of code coverage rate to obtain a sorting result; and Screening out the top N test cases in the sorting result as the optimal test cases, where N is greater than or equal to 1.

4. An apparatus for implementing the test case screening method according to any one of claims 1-3, characterized in that, The device includes: A use case acquisition module for acquiring multiple test cases of a target service; A use case execution module for executing the multiple test cases through a test case execution engine to obtain code coverage data corresponding to each of the test cases; A similarity determination module for obtaining the similarity between the code coverage data corresponding to each of the test cases and determining the code coverage data that are similar to each other based on each of the similarities; A use case screening module for screening the test cases corresponding to the code coverage data that are similar to each other.

5. The device according to claim 4, characterized in that, The use case acquisition module includes: A parameter acquisition unit for acquiring interface parameter information of the target service, where the interface parameter information includes the actual parameter values of all interface parameters obtained by parsing the actual traffic data of the target service; A machine learning unit for performing machine learning on all the interface parameters according to the actual parameter values of each of the interface parameters and the feature information of the target service to obtain the parameter value rules of each of the interface parameters; A use case generation unit for assigning values to each of the interface parameters according to the parameter value rules of each of the interface parameters to generate multiple test cases of the target service.

6. A computer device, comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, When the processor executes the computer program, the steps of the method according to any one of claims 1 to 3 are implemented.

7. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, the steps of the method according to any one of claims 1 to 3 are implemented.

Citation Information

Patent Citations

  • Test case generation method and device, equipment and storage medium

    CN110750442A

  • Test case optimization method, device and equipment and computer readable storage medium

    CN111858288A