Test case generation method and device, equipment, storage medium and program product
By using adaptive decision trees and multi-objective optimization algorithms to generate test paths and test case sets, the problems of low testing efficiency and incomplete coverage in existing technologies are solved, achieving efficient and dynamic test case generation that adapts to real-time updates of software systems.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-15
- Publication Date
- 2026-04-10
AI Technical Summary
Existing technologies are ill-suited to real-time updates of software systems, resulting in low testing efficiency of generated test cases and an inability to effectively cover testing blind spots, leading to rigid and redundant testing.
By using an adaptive decision tree to determine node splitting conditions based on test entropy and failure rate gradient, test paths are generated. Combined with multi-objective optimization algorithms and multi-modal defect prediction models, the test case set is dynamically adjusted to generate test paths and test case sets adapted to the test objects.
It improves testing efficiency, covers more testing blind spots, reduces redundant testing, increases defect detection rate and computing resource utilization efficiency, and adapts to real-time changes in software systems.
Smart Images

Figure CN121833495A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of financial technology or the technical field of software testing, and in particular, relates to a test case generation method and device, equipment, a storage medium and a program product. BACKGROUND
[0002] In the software development process, the code base of the software system is frequently iterated and the complexity continues to rise, and the software testing work faces three core challenges of dynamic, efficient and accurate.
[0003] The related art relies on static rules to generate test cases, and this method is difficult to adapt to real-time updates of the test object, and the test efficiency of the generated test cases is low. SUMMARY
[0004] The present application provides a test case generation method, device, equipment, storage medium and program product to adapt to real-time updates of the test object and generate test cases with higher test efficiency.
[0005] In a first aspect, the present application provides a test case generation method, comprising: determining a split condition of a node of an adaptive decision tree according to a test entropy and a failure rate gradient of a test object; performing node splitting on the adaptive decision tree represented by the test object based on the split condition to generate a test path, the test path being a path from a root node to a leaf node in the adaptive decision tree after node splitting; and generating a test case set according to the test path.
[0006] In a possible embodiment, the split condition comprises: in the case that the test entropy of a child node is greater than the product of the test entropy of a parent node and a first coefficient, performing node splitting on the child node according to a split direction with the highest failure rate gradient among a plurality of candidate split directions, the first coefficient being greater than 1.
[0007] In a possible embodiment, after generating the test case set according to the test path, the test case generation method further comprises: determining a reward value by a reward function, the reward term of the reward function being a defect detection rate after executing the test case set, and the penalty term of the reward function being a computing resource cost of executing the test case set; and adjusting and updating the first coefficient according to the reward value.
[0008] In a possible embodiment, generating the test case set according to the test path comprises: parsing path constraints of the test path based on a symbolic execution tool to generate a parameter combination covering the test path; and generating a test case set satisfying a code coverage condition and a test case number condition by a multi-objective optimization algorithm.
[0009] In a possible implementation, before determining the split condition of the node of the adaptive decision tree, the test case generation method further includes: outputting a defect probability of the test object by the multi-modal defect prediction model, the defect probability being calculated based on fusion of the static code features, the dynamic running data and the personnel behavior data; determining a priority of the test object according to the defect probability of the test object, the priority indicating an order of generating the test case set of the test object.
[0010] In a possible implementation, the multi-modal defect prediction model is obtained through ensemble learning.
[0011] In a possible implementation, after generating the test case set according to the test path, the test case generation method further includes: determining a training sample according to a test result of the test case set; and updating the multi-modal defect prediction model according to the training sample.
[0012] In a possible implementation, after generating the test case set according to the test path, the test case generation method further includes: generating an incremental test case set by a generative adversarial network, and performing incremental updating on the test case set according to the incremental test case set.
[0013] In a second aspect, the present application provides a test case generation apparatus, including: a split condition determination module configured to determine a split condition of a node of an adaptive decision tree according to a test entropy and a failure rate gradient of a test object; a node splitting module configured to perform node splitting on the adaptive decision tree represented by the test object based on the split condition, and generate a test path, the test path being a path from a root node to a leaf node in the adaptive decision tree after node splitting; and a test case set generation module configured to generate a test case set according to the test path.
[0014] In a third aspect, the present application provides an electronic device, including: a processor, and a memory connected with the processor in communication; the memory stores computer execution instructions; and the processor executes the computer execution instructions stored in the memory, to implement the method of any one of the first aspect.
[0015] In a fourth aspect, the present application provides a computer readable storage medium, the computer readable storage medium storing computer execution instructions, the computer execution instructions being executed by a processor to implement the method of any one of the first aspect.
[0016] In a fifth aspect, the present application provides a computer program product, including a computer program, the computer program being executed by a processor to implement the method of any one of the first aspect.
[0017] The embodiment of the present application quantifies the test coverage blind area by the test entropy of the test object, and determines whether the splitting direction of the node is effective by the failure rate gradient of the test object. The splitting condition of the node of the adaptive decision tree determined according to the test entropy and the failure rate gradient of the test object can guide to cover more test blind areas and guide to the effective splitting direction in real time, and the adaptive decision can cope with the real-time change of the test object. Therefore, the node splitting of the adaptive decision tree represented by the test object based on the splitting condition can generate a test path adapted to the current test object in real time, and improve the response lag problem of the test object. The test case set generated according to the test path has higher accuracy, can cover more test blind areas, reduce the execution of redundant test cases, and further improve the test efficiency. BRIEF DESCRIPTION OF DRAWINGS
[0018] The accompanying drawings, which are incorporated herein and form a part of the specification, illustrate embodiments consistent with the present application and, together with the description, further serve to explain the principles of the present application.
[0019] Figure 1 A schematic diagram of an application scenario of a test case generation method of an embodiment of the present application;
[0020] Figure 2 A flowchart of a test case generation method of an embodiment of the present application;
[0021] Figure 3 A schematic diagram of node splitting of an embodiment of the present application;
[0022] Figure 4 A schematic diagram of a test case generation device of an embodiment of the present application;
[0023] Figure 5 A schematic diagram of an electronic device of an embodiment of the present application.
[0024] The above-described drawings have shown specific embodiments of the present application, and will be described in more detail hereinafter. These drawings and the written description are not intended to restrict the scope of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by reference to specific embodiments. DETAILED DESCRIPTION
[0025] The exemplary embodiments will be described in detail hereinbelow with reference to the drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of apparatuses and methods consistent with some aspects of the present application as detailed in the appended claims.
[0026] It should be noted that the user information (including but not limited to user equipment information, user personal information, etc.) and data (including but not limited to data for analysis, stored data, displayed data, etc.) involved in the present application are all information and data authorized by the user or authorized by all parties, and the collection, storage, use, processing, transmission, provision, disclosure and application of related data comply with relevant laws, regulations and standards of relevant countries and regions, necessary security measures are taken, do not violate public order and good customs, and provide corresponding operation portal for user to choose authorization or refusal.
[0027] And the present application involves big data analysis of user information (including but not limited to personal biological characteristics, identity data, consumption data, asset data, electronic terminal operation data, etc.), and uses artificial intelligence technology for automatic decision, and makes a technical solution based on the automatic decision result that has a significant impact on personal rights and interests, provides a corresponding operation portal for the user to choose to agree or refuse the automatic decision result; if the user chooses to refuse, enter the expert decision process.
[0028] It should be noted that the test case generation method, device, equipment, storage medium and program product provided by the present application can be used in the field of financial technology or software testing technology, and can also be used in any field other than the field of financial technology or software testing technology. The application of the test case generation method, device, equipment, storage medium and program product is not limited.
[0029] In the field of software development technology, especially in the continuous integration / continuous delivery (CI / CD) and agile development mode, the code base of software system is frequently iterated and the complexity continues to rise, and the test work faces three core challenges of dynamic, efficient and accurate.
[0030] The test case generation method of the embodiments of the present application can be applied to the financial application program in the test development of the financial institution. For example, the financial institution provides financial services to the user who installs the financial application program later by developing the financial application program. During the development of the financial application program, each module, component and the like of the financial application program needs to be tested by executing the test case set to test its functions, performance and the like.
[0031] Figure 1 The application scenario diagram of the test case generation method of the embodiments of the present application.
[0032] For example, the test case generation method of the embodiments of the present application can be applied to the financial application program in the test development of the financial institution. For example, the financial institution provides financial services to the user who installs the financial application program later by developing the financial application program. During the development of the financial application program, each module, component and the like of the financial application program needs to be tested by executing the test case set to test its functions, performance and the like. Figure 1As shown, the tester 1 of the financial institution takes the test object from the code library through the terminal device 2, and the terminal device 2 can generate a test case set by executing the test case method of the embodiment of the application. The test case set can be sent to the cloud server 3, and the cloud server 3 executes the test case set. Alternatively, the test case set 3 can be sent to the server cluster, and the server cluster executes the test case set.
[0033] The related technology 1 generates a test case set based on static rules (such as a code coverage threshold, static syntax analysis). This way cannot perceive the runtime state of the test object (such as the historical defect distribution, the developer behavior characteristics), resulting in test rigidity. When the test object has a structural change, the test case set needs to be adjusted manually, and the number of test case sets increases exponentially with the improvement of coverage, and the marginal benefit decreases.
[0034] The related technology 2 generates a test case set based on a genetic algorithm, specifically simulates the evolution process of the test object and optimizes the test case set. However, this method has high computational cost for generating a test case set, and it is difficult to respond to changes in the test object in real time.
[0035] The test case generation method, device, equipment, storage medium and program product provided by the application aim to solve at least one of the above technical problems of the related technology.
[0036] The technical solutions of the application and how the technical solutions of the application solve the above technical problems will be described in detail in the specific embodiments below. The following specific embodiments can be combined with each other, and the same or similar concepts or processes can not be described in detail in some embodiments. The embodiments of the application will be described below with reference to the drawings.
[0037] Figure 2 The flowchart of the test case generation method of the embodiment of the application. The test case generation method of the embodiment of the application is executed by an electronic device, and the electronic device includes a terminal device and a server. As shown in Figure 2 The test case generation method includes steps S110 to S130.
[0038] S110, determining the splitting condition of the node of the adaptive decision tree according to the test entropy and the failure rate gradient of the test object.
[0039] The adaptive decision tree refers to a decision tree algorithm that aims to split nodes in combination with dynamic feedback. In the embodiment of the application, the adaptive decision tree dynamically adjusts the splitting condition of the node according to the test entropy and the failure rate gradient to generate a test path.
[0040] Test entropy is a metric that quantifies the degree of blind spots in test coverage. It is calculated by the coupling degree of code branches and the distribution of historical defects in the test object. For example, if a test object has complex branch logic and a high density of historical defects, its test entropy value will be high, indicating that the test object has many blind spots.
[0041] Code branch coupling refers to the degree of association between code branches, such as shared variables and call chain length. For example, if two code branches interact through shared variables, their coupling is 0.8.
[0042] Failure rate gradient refers to the distribution trend of failure rates among test cases, used to guide the splitting direction of nodes. For any given node, the splitting direction indicates the node's partitioning rules.
[0043] S120. Based on the splitting conditions, the adaptive decision tree representing the test object performs node splitting to generate the test path.
[0044] The test path is the path from the root node to a leaf node in the adaptive decision tree after node splitting. The test path can represent the set of logical paths consisting of conditional branches during the execution of the test object.
[0045] The adaptive decision tree representing the test object is split based on splitting conditions. Generating the test path can be understood as splitting the parent node to generate child nodes if the parent node meets the splitting conditions. The root node of the adaptive decision tree is the test object.
[0046] S130. Generate a test case set based on the test path.
[0047] In this embodiment, the test coverage blind spots are quantified by the test entropy of the test object, and the effectiveness of node splitting direction is determined by the failure rate gradient of the test object. Based on the test entropy and failure rate gradient of the test object, the determined splitting conditions of the nodes in the adaptive decision tree can guide the coverage of more test blind spots and guide effective splitting directions in real time. Furthermore, the adaptive decision-making can respond to real-time changes in the (code) of the test object. Therefore, by performing node splitting on the adaptive decision tree representing the test object based on the splitting conditions, test paths adapted to the current test object can be generated in real time, improving the lag in response to the test object. The test case sets generated based on the test paths are more accurate, covering more test blind spots, reducing redundant tests, and thus improving testing efficiency.
[0048] In one possible embodiment, the splitting condition includes: if the test entropy of the child node is greater than the product of the test entropy of the parent node and a first coefficient, the child node is split according to the splitting direction with the highest failure rate gradient among multiple candidate splitting directions, and the first coefficient is greater than 1.
[0049] The following example illustrates the splitting conditions and node splitting.
[0050] Figure 3 This is a schematic diagram of node splitting in an embodiment of this application. Figure 3 As shown, the test object is the root node N0 of adaptive decision tree 1, with the root node NO as the parent node and its test entropy being 0.1. Since the parent node N0 does not have a parent node, the node can be split directly based on the failure rate gradient of the root node NO to obtain child nodes N11 and N12, thus obtaining adaptive decision tree 2.
[0051] The test entropies of child nodes N11 and N12 are 0.3 and 0.08, respectively. Taking a first coefficient of 1.3 as an example, the test entropy of child node N11 is greater than the product of the test entropy of parent node NO (0.1) and the first coefficient (1.3), which is 0.13. The electronic device can perform node splitting on child node N11 to obtain node N111 and node N112, thus obtaining the adaptive decision tree 3.
[0052] The test paths include three paths P1, P2, and P3 from the root node to the three leaf nodes in the adaptive decision tree 3. P1 is the path from the root node NO through node N11 to the leaf node N111, P2 is the path from the root node N0 through node N11 to the leaf node N112, and P3 is the path from the root node N0 to the leaf node N12.
[0053] Regarding the splitting direction, taking the transfer module as an example, represented by the root node NO in adaptive decision tree 1, the candidate splitting directions for root node N0 include user type, transfer amount range, and sub-functions of the transfer module. The candidate splitting direction of sub-functions of the transfer module has the highest failure rate gradient. Taking the transfer module as an example, which includes balance transfer sub-functions and interbank transfer sub-functions, the electronic device can split root node N0, resulting in child nodes N11 and N12 representing the balance transfer sub-function and the interbank transfer sub-function, respectively. Thus, adaptive decision tree 2 can be obtained. The process of obtaining adaptive decision tree 3 based on adaptive decision tree 2 is similar and will not be elaborated here.
[0054] In this embodiment, the test entropy of a child node is greater than the product of the test entropy of the parent node and the first coefficient. This indicates that the test entropy of the child node after node splitting is higher than that of the parent node, and the node splitting can cover more test blind spots. The splitting direction with the highest failure rate gradient among multiple candidate splitting directions represents the most effective splitting direction. This can be understood as the overall test failure rate of the parent node before node splitting being ambiguous, while the distribution of test failure rates of the multiple child nodes obtained after node splitting has greater differences. Therefore, it is possible to accurately focus on high-risk test scenarios and minimize redundant testing. Thus, in this embodiment, the splitting conditions can balance covering more test blind spots and reducing redundant testing, generating better test paths and test case sets with higher testing efficiency.
[0055] In one possible embodiment, after generating a test case set based on the test path in step S130, the test case generation method may further include: determining a reward value through a reward function; and adjusting and updating a first coefficient based on the reward value.
[0056] The reward term of the reward function is the defect detection rate after executing the test case set, and the penalty term of the reward function is the computational resource cost of executing the test case set.
[0057] The defect detection rate can be understood as the number of defects detected per unit of time. The defect detection rate can be normalized, and the normalized defect detection rate is used as a reward item.
[0058] Computational resource costs can be considered across multiple cost dimensions, including time costs (total time spent), computing power costs (CPU resources used, etc.), and storage costs. These cost values can be normalized and weighted to obtain the final resource cost as a penalty.
[0059] In this embodiment, the testing efficiency of the test case set obtained under the current splitting conditions is evaluated through a reward function, and the reward value reflects this testing efficiency. The first coefficient can be dynamically adjusted by adjusting and updating it based on the reward value, thereby adaptively and dynamically optimizing the splitting conditions. Therefore, the test case set obtained through the splitting conditions not only covers more testing blind spots and reduces redundant testing, but also has a higher defect detection rate and uses fewer computational resources, improving the utilization efficiency of testing resources and thus comprehensively improving testing efficiency.
[0060] In addition, a dynamic first coefficient can adapt to the complexity differences of the test objects, avoid excessive or insufficient splitting caused by a fixed first coefficient, and improve the coverage depth of the test path.
[0061] In one possible embodiment, step S130 of generating a test case set based on the test path includes: parsing the path constraints of the test path using a symbolic execution tool to generate a parameter combination that covers the test path; and generating a test case set that satisfies the code coverage condition and the number of test cases condition through a multi-objective optimization algorithm.
[0062] Symbolic execution tools are tools that use formal methods to resolve test path constraints and generate parameter combinations. For example, a symbolic execution tool can transform the test path condition x>10 into a parameter constraint such as x=15.
[0063] The code coverage condition indicates an increase in code coverage. The test case quantity condition indicates a reduction in the number of test cases. The test entropy condition indicates testing test paths with high test entropy, resulting in test cases that achieve higher code coverage and higher test entropy with the minimum number of test cases required.
[0064] For example, a multi-objective algorithm includes the Non-dominated Sorting Genetic Algorithm II (NSGA-II). For instance, generating a test case set that satisfies code coverage and test case quantity conditions through a multi-objective optimization algorithm includes: population initialization, non-dominated sorting, crowding calculation, evolutionary operations, elite retention, and termination condition detection. Population initialization involves randomly generating a batch of test cases as initial candidate solutions. Non-dominated sorting involves stratifying all candidate solutions and selecting Pareto front solutions. Crowding calculation involves calculating the crowding degree of Pareto front solutions and retaining solutions with low crowding. Evolutionary operations involve generating offspring solutions through crossover (combining test cases from two test case sets) and mutation (adding / deleting test cases from test case sets). Elite retention involves merging parent and offspring solutions, sorting and filtering again, and retaining the optimal solution for the next iteration. Termination conditions include reaching a preset number of iterations or convergence of the Pareto front solution.
[0065] In this embodiment, the generated test case set can be optimized by combining symbolic execution tools with multi-objective optimization algorithms. For example, the test case set can achieve higher code coverage and higher test entropy with the fewest number of test cases, thereby improving the defect detection rate and reducing testing costs.
[0066] like Figure 2 As shown, in one possible embodiment, before determining the splitting conditions of the nodes of the adaptive decision tree in step S110, the test case generation method further includes steps S101 and S102.
[0067] S101. Output the defect probability of the test object through the multimodal defect prediction model.
[0068] The defect probability is calculated based on the fusion of static code features, dynamic runtime data, and personnel behavior data.
[0069] A multimodal defect prediction model is a model that integrates multiple dimensions to predict the probability of defects.
[0070] Static code characteristics include at least one of the following: cyclomatic complexity, inheritance depth, and comment density. Static code characteristics can be obtained using static analysis tools, which are used to extract structural attributes of the code.
[0071] Dynamic runtime data includes at least one of the following: function call frequency, number of modifications within a preset time period. Dynamic runtime data can be obtained through a version control system, which is used to manage code changes.
[0072] Personnel behavior data includes the developer's historical defect rate. This data can be obtained through a defect management system, which records defect data.
[0073] S102. Determine the priority of the test object based on the defect probability of the test object.
[0074] Priority indicates the order in which test case sets are generated for the test object.
[0075] For example, test objects with a defect probability greater than or equal to a defect probability threshold are designated as first priority. If there are multiple test objects with first priority, the execution order of their test case sets can be randomly determined. Similarly, test objects with a defect probability less than the defect probability threshold are designated as second priority. If there are multiple test objects with second priority, the execution order of their test case sets can be randomly determined. The test case sets of the first priority test objects are executed before those of the second priority test objects.
[0076] Alternatively, sort the multiple test objects in descending order of their defect probabilities.
[0077] For example, the defect probability ranges from [0,1], the defect probability threshold ranges from [0.65,1], and the defect probability threshold can be 0.8.
[0078] In this embodiment, the multimodal defect prediction model, by fusing static code features, dynamic runtime data, and personnel behavior data, avoids the bias of a single data source, accurately identifies the risk level of defects in test objects, and outputs more accurate defect probabilities. Accurate defect probabilities provide a basis for prioritizing subsequent defect test objects, ensuring that high-risk test objects are tested first, thereby improving testing efficiency.
[0079] In one possible embodiment, the multimodal defect prediction model is obtained through ensemble learning.
[0080] Ensemble learning is used to build a strong learner by combining multiple weak learners to compensate for the shortcomings of a single weak learner.
[0081] For example, the multimodal defect prediction model includes three weak learners: a logistic regression model, a decision vector machine, and a neural network model. The logistic regression module, decision vector machine, and neural network model perform defect probability prediction in parallel, obtaining three initial defect probabilities. These three initial defect probabilities are then processed through a voting mechanism or a weighted sum to obtain the final defect probability of the test object.
[0082] In this embodiment of the application, through ensemble learning, the defect prediction capabilities of multiple weak learners can be combined, and the resulting multimodal defect prediction model has higher accuracy and robustness in defect prediction.
[0083] In one possible embodiment, after generating a test case set according to the test path in step S130, the test case generation method further includes: determining training samples based on the test results of the test case set; and updating the multimodal defect prediction model based on the training samples.
[0084] For example, each test case in the test case set yields a test result after execution, which includes a defect probability. This test result is used as the defect probability label for that test case, and the training samples are test cases with defect probability labels.
[0085] For example, an electronic device can input training samples into an initial multimodal defect prediction model. The initial multimodal defect prediction model processes the training samples to obtain predicted defect probabilities. The predicted defect probabilities are evaluated using a preset loss function to obtain a loss value, which is used to assess the accuracy of the current predicted defect probabilities. If the loss value does not converge, the model parameters of the initial multimodal defect prediction model are adjusted based on the loss value, and new training samples are input into the multimodal defect prediction model with adjusted model parameters. If the loss value converges, training is complete.
[0086] In this embodiment of the application, training samples are determined based on the test results of the test case set, and the multimodal defect prediction model is updated based on the training samples. This can build a closed-loop, continuous learning mechanism for the multimodal defect prediction model, ensuring that the subsequent generation of test paths and test cases can quickly respond to changes in the test object.
[0087] Specifically, the test results from new, realistic test case sets are fed back into the multimodal defect prediction model for retraining. The retrained model learns features and knowledge not captured during the training phase, improving prediction accuracy and adapting to new defect patterns. For example, the test results from the test case sets can reflect different scenarios, edge cases, and developer characteristics. By retraining the multimodal defect prediction model, its generalization ability is strengthened, and defect predictions become more accurate.
[0088] In one possible embodiment, after generating the test case set according to the test path in step S130, the test case generation method further includes: generating an incremental test case set through a generative adversarial network, and incrementally updating the test case set according to the incremental test case set.
[0089] Generative Adversarial Networks (GANs) are adversarial training models consisting of a generator and a discriminator. The generator is used to generate test cases, and the discriminator is used to evaluate the defect triggering capability of the test cases.
[0090] In this embodiment, an incremental test case set is generated by a generative adversarial network (GAN), and the test case set is incrementally updated based on the incremental test case set, which improves the coverage diversity of test cases. Specifically, the incremental test case set generated by the GAN closely approximates the real test case set and can trigger defects not covered by the test case set during subsequent execution. This avoids missed tests caused by the test case set being concentrated on low-value test paths, thereby improving test robustness and defect detection rate.
[0091] It should be noted that after generating the test case set according to the test path in step S130, the electronic device can first execute the test results based on the test case set in the previous embodiment to determine the training samples; and update the multimodal defect prediction model based on the training samples. After updating the multimodal defect prediction model, the electronic device executes the generation of an incremental test case set through a generative adversarial network according to the embodiment of this application, and incrementally updates the test case set based on the incremental test case set.
[0092] Figure 4 This is a schematic diagram of the test case generation device according to an embodiment of this application. Figure 4 As shown, the test case generation device provided in this application embodiment includes: a splitting condition determination module 210, a node splitting module 220, and a test case set generation module 230.
[0093] The splitting condition determination module 210 is used to determine the splitting conditions of the nodes of the adaptive decision tree based on the test entropy and failure rate gradient of the test object.
[0094] The node splitting module 220 is used to perform node splitting on the adaptive decision tree representing the test object based on the splitting conditions, and generate test paths. The test paths are the paths from the root node to the leaf node in the adaptive decision tree after node splitting.
[0095] The test case set generation module 230 is used to generate test case sets based on the test path.
[0096] In one possible embodiment, the splitting condition includes: if the test entropy of the child node is greater than the product of the test entropy of the parent node and a first coefficient, the child node is split according to the splitting direction with the highest failure rate gradient among multiple candidate splitting directions, and the first coefficient is greater than 1.
[0097] In one possible embodiment, the test case generation device further includes: a reward value determination module, configured to determine a reward value through a reward function, wherein the reward term of the reward function is the defect detection rate after executing the test case set, and the penalty term of the reward function is the computational resource cost of executing the test case set; and a first coefficient update module, configured to adjust and update a first coefficient according to the reward value.
[0098] In one possible embodiment, the test case set generation module includes: a parameter combination generation submodule, used to parse the path constraints of the test path based on the symbolic execution tool and generate parameter combinations that cover the test path; and a test case set generation submodule, used to generate a test case set that satisfies the code coverage condition and the test case quantity condition through a multi-objective optimization algorithm.
[0099] In one possible embodiment, the test case generation device further includes: a defect probability determination module, used to output the defect probability of the test object through a multimodal defect prediction model, wherein the defect probability is calculated based on the fusion of static code features, dynamic runtime data and personnel behavior data; and a priority determination module, used to determine the priority of the test object according to the defect probability of the test object, wherein the priority indicates the order in which the test case set of the test object is generated.
[0100] In one possible embodiment, the multimodal defect prediction model is obtained through ensemble learning.
[0101] In one possible embodiment, the test case generation device further includes: a training sample determination module, used to determine training samples based on the test results of the test case set; and a multimodal defect prediction model update module, used to update the multimodal defect prediction model based on the training samples.
[0102] In one possible embodiment, the test case generation device further includes an incremental update module, configured to generate an incremental test case set through a generative adversarial network, and to incrementally update the test case set based on the incremental test case set.
[0103] Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Figure 5 As shown, this application embodiment provides an electronic device including a processor 301 and a memory 302. Optionally, the device further includes a communication component 303. The processor 301, memory 302, and communication component 303 are connected via a bus 304.
[0104] In the specific implementation process, the memory 302 stores code, and the processor 301 runs the code stored in the memory 302 to execute the method of the above method embodiment.
[0105] The specific implementation process of processor 301 can be found in the above method embodiments, and its implementation principle and technical effect are similar. It will not be repeated here.
[0106] In the above Figure 5 In the illustrated embodiments, it should be understood that the processor 301 can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), etc. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in this invention can be directly implemented by a hardware processor, or implemented by a combination of hardware and software modules within the processor.
[0107] The memory 302 may include high-speed RAM memory, and may also include non-volatile memory (NVM), such as at least one disk storage.
[0108] Bus 304 can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. Bus 304 can be divided into address bus, data bus, control bus, etc. For ease of illustration, the bus 304 in the accompanying drawings of this application is not limited to only one bus or one type of bus.
[0109] This application provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, are used to implement the methods described in the above-described method embodiments.
[0110] The aforementioned computer-readable storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk. The readable storage medium can be any available medium accessible to a general-purpose or special-purpose computer.
[0111] An exemplary readable storage medium is coupled to a processor, enabling the processor to read information from and write information to the readable storage medium. Of course, the readable storage medium can also be a component of the processor. The processor and the readable storage medium can reside in an Application Specific Integrated Circuit (ASIC). Alternatively, the processor and the readable storage medium can exist as discrete components in the device.
[0112] This application provides a computer program product, including a computer program that, when executed by a processor, implements the methods provided in any of the embodiments described above.
[0113] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, as some steps may be performed in other orders or simultaneously according to this application. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily essential to this application.
[0114] It should be further noted that although the steps in the flowchart are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowchart may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the sub-steps or stages of other steps.
[0115] It should be understood that the above-described device embodiments are merely illustrative, and the device of this application can also be implemented in other ways. For example, the division of units / modules in the above embodiments is only a logical functional division, and there may be other division methods in actual implementation. For example, multiple units, modules, or components may be combined, or integrated into another system, or some features may be ignored or not executed.
[0116] Furthermore, unless otherwise specified, the functional units / modules in the various embodiments of this application can be integrated into one unit / module, or each unit / module can exist physically separately, or two or more units / modules can be integrated together. The integrated units / modules described above can be implemented in hardware or as software program modules.
[0117] When integrated units / modules are implemented in hardware, the hardware can be digital circuits, analog circuits, etc. The physical implementation of the hardware structure includes, but is not limited to, transistors, memristors, etc. Unless otherwise specified, the processor can be any suitable hardware processor, such as a CPU, GPU, FPGA, DSP, and ASIC, etc. Unless otherwise specified, the storage unit can be any suitable magnetic or magneto-optical storage medium, such as Resistive Random Access Memory (RRAM), Dynamic Random Access Memory (DRAM), Static Random Access Memory (SRAM), Enhanced Dynamic Random Access Memory (EDRAM), High-Bandwidth Memory (HBM), Hybrid Memory Cube (HMC), etc.
[0118] If the integrated unit / module is implemented as a software program module and sold or used as an independent financial product, it can be stored in a computer-readable storage device (CMD). Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software financial product. This computer software financial product is stored in a memory and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned memory includes various media capable of storing program code, such as a USB flash drive, read-only memory (ROM), random access memory (RAM), portable hard drive, magnetic disk, or optical disk.
[0119] In the above embodiments, the descriptions of each embodiment have their own emphasis. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments. The technical features of the above embodiments can be combined arbitrarily. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as the combination of these technical features does not contradict each other, it should be considered within the scope of this specification.
[0120] Other embodiments of this application will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of this application that follow the general principles of this application and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this application are indicated by the following claims.
[0121] It should be understood that this application is not limited to the precise structure described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this application is limited only by the appended claims.
Claims
1. A test case generation method, characterized in that, include: Based on the test entropy and failure rate gradient of the test object, determine the splitting conditions of the nodes of the adaptive decision tree; Based on the splitting conditions, the adaptive decision tree representing the test object is split into nodes to generate a test path, which is the path from the root node to the leaf node in the adaptive decision tree after node splitting. A test case set is generated based on the test path.
2. The method according to claim 1, characterized in that, The splitting conditions include: when the test entropy of the child node is greater than the product of the test entropy of the parent node and the first coefficient, the child node is split according to the splitting direction with the highest failure rate gradient among multiple candidate splitting directions, and the first coefficient is greater than 1.
3. The method according to claim 2, characterized in that, After generating the test case set based on the test path, the method further includes: The reward value is determined by a reward function, wherein the reward item of the reward function is the defect detection rate after executing the test case set, and the penalty item of the reward function is the computational resource cost of executing the test case set; The first coefficient is adjusted and updated based on the reward value.
4. The method according to any one of claims 1-3, characterized in that, The step of generating a test case set based on the test path includes: Based on the symbolic execution tool, the path constraints of the test path are parsed, and a parameter combination covering the test path is generated; A multi-objective optimization algorithm is used to generate a test case set that meets the code coverage and test case quantity requirements.
5. The method according to any one of claims 1-3, characterized in that, Before determining the splitting conditions of the nodes in the adaptive decision tree, the method further includes: The defect probability of the test object is output by a multimodal defect prediction model. The defect probability is calculated based on the fusion of static code features, dynamic running data and personnel behavior data. The priority of the test object is determined based on the defect probability of the test object, and the priority indicates the order in which the test case set of the test object is generated.
6. The method according to claim 5, characterized in that, The multimodal defect prediction model is obtained through ensemble learning.
7. The method according to claim 5, characterized in that, After generating the test case set based on the test path, the method further includes: Based on the test results of the test case set, determine the training samples; The multimodal defect prediction model is updated based on the training samples.
8. The method according to claim 5, characterized in that, After generating the test case set based on the test path, the method further includes: An incremental test case set is generated by a generative adversarial network, and the test case set is incrementally updated based on the incremental test case set.
9. A test case generation device, characterized in that, include: The splitting condition determination module is used to determine the splitting conditions of nodes in the adaptive decision tree based on the test entropy and failure rate gradient of the test object. The node splitting module is used to perform node splitting on the adaptive decision tree representing the test object based on the splitting conditions, and generate a test path, wherein the test path is the path from the root node to the leaf node in the adaptive decision tree after node splitting; The test case set generation module is used to generate test case sets based on the test path.
10. An electronic device, characterized in that, include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executed instructions; The processor executes computer execution instructions stored in the memory to implement the method as described in any one of claims 1 to 8.
11. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, are used to implement the method as described in any one of claims 1 to 8.
12. A computer program product, characterized in that, Includes a computer program that, when executed by a processor, implements the method of any one of claims 1 to 8.