Test case generation method and system, electronic equipment and storage medium
Through deep learning models and reinforcement learning algorithms, the problems of low efficiency and poor accuracy of traditional test cases are solved, high-quality and efficient test case generation are achieved, and software test coverage and stability are improved.
Patent Information
- Application Number
- CN202411193193.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-27
- Publication Date
- 2024-12-27
AI Technical Summary
Traditional test case generation methods rely on manual writing, which is inefficient and difficult to meet the high-quality and efficient testing needs in modern software development, and it is easy to miss important test scenarios or boundary conditions.
Deep learning model combined with reinforcement learning and model optimization algorithms, generate data sets based on demand information and historical test data, set test constraints, train test cases to generate models, optimize preliminary test case sets, and adjust test cases according to execution logs to generate Test cases with high coverage and high accuracy.
It reduces manual writing time and errors, improves the accuracy and coverage of test cases, improves the quality of tests, ensures the stability and reliability of software products, and can flexibly respond to changes and resource optimization.
Smart Images

Figure CN119201689A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of software testing, and in particular to a test case generation method, system, electronic equipment and storage medium. Background Art
[0002] Software testing is a crucial part of the software development process. It is not only for finding errors, but also a process to comprehensively evaluate the quality of the software, ensure that the software can run correctly according to the design requirements, meet user needs, and ensure data security and integrity. In software testing, the comparison between the actual output and the expected output is a key step. By designing and executing test cases, testers can simulate user behavior, observe and record the actual performance of the software, and then compare it with the expected results. This comparison process helps to find defects, vulnerabilities or non-compliance with requirements in the software.
[0003] As the complexity and scale of software systems continue to increase, test case generation has become a key link in software development and testing. Traditional test case generation methods mainly rely on manual writing, which takes a lot of time and effort, especially when facing complex and large-scale software systems. This method is particularly inefficient. At the same time, due to human subjectivity and experience differences, test engineers may miss some important test scenarios or boundary conditions when writing test cases, and it is easy to make omissions. Traditional test case generation methods are difficult to meet the high-quality and efficient testing requirements in modern software development. Summary of the invention
[0004] In view of the above-mentioned deficiencies in the prior art, the present invention provides a test case generation method, system, electronic device and storage medium, which effectively solve the problem that traditional test case generation methods are difficult to meet the high-quality and high-efficiency testing requirements in modern software development.
[0005] In a first aspect, the present invention provides a method for generating a test case, the method comprising:
[0006] Generate data sets based on demand information and historical test data;
[0007] Setting test constraints according to the requirement information;
[0008] Using the data set to train the deep learning model to obtain a test case generation model;
[0009] Acquire a preliminary test case set according to the test constraint conditions and the test case generation model, and optimize the preliminary test case set to obtain an optimized test case set;
[0010] Execute the optimized test case set, adjust the optimized test case set according to the execution log, and obtain the target test case set.
[0011] Further, the demand information includes a demand document and a design document, and generating a data set according to the demand information and historical test data includes:
[0012] Performing text analysis on the requirement document and the design document to obtain key test points and test requirements;
[0013] Performing data preprocessing on the historical test data to obtain a preprocessed data set;
[0014] The data set is generated according to the key test points, the test requirements and the preprocessed data set.
[0015] Further, the test constraint conditions include test coverage constraint, execution time constraint, resource limitation constraint and priority constraint, and setting the test constraint conditions according to the requirement information includes:
[0016] Setting the test coverage constraint according to functional modules and requirements;
[0017] Setting the execution time constraints according to the project schedule and the test time window;
[0018] Setting the resource limit constraint according to the test resources;
[0019] The priority constraint is set according to a preset path and a preset module.
[0020] Furthermore, the deep learning model is trained using the data set to obtain a test case generation model, including:
[0021] Using the data set to train the deep learning model, and obtaining the test steps and expected results of the test case;
[0022] Using a reinforcement learning algorithm to optimize the test steps and the expected results, and updating the deep learning model according to the optimized test steps and the optimized expected results;
[0023] A model optimization algorithm is used to optimize the updated deep learning model, and a cross-validation technique is used to evaluate the optimized deep learning model to obtain the test case generation model.
[0024] Furthermore, the deep learning model is trained using the data set to obtain the test steps and expected results of the test case, including:
[0025] Constructing the deep learning model and setting training parameters of the deep learning model;
[0026] Using the data set to train the deep learning model according to the training parameters to obtain a mapping relationship between the test case and the requirement information;
[0027] Acquire the key test points and the test requirements according to the mapping relationship;
[0028] The test steps and the expected results of the test case are generated according to the key test points and the test requirements.
[0029] Further, the optimizing the preliminary test case set includes:
[0030] Obtaining test results and user feedback for the preliminary test case set;
[0031] Adjust the test steps according to the test results and the user feedback, and update the expected results;
[0032] The duplicate cases in the preliminary test case set are merged, and the invalid cases in the preliminary test case set are deleted.
[0033] Further, adjusting the optimized test case set according to the execution log includes:
[0034] Monitor the execution of the optimized test case set and obtain execution logs;
[0035] Obtaining the success rate and execution efficiency of the optimized test case set according to the execution log;
[0036] The expected results and test steps of the optimized test case set are adjusted according to the success rate and the execution efficiency.
[0037] In a second aspect, the present invention provides a test case generation system, the system comprising:
[0038] A data generation module is used to generate a data set based on demand information and historical test data;
[0039] A condition setting module, used to set test constraint conditions according to the requirement information;
[0040] A model generation module, used to train a deep learning model using the data set to obtain a test case generation model;
[0041] A case generation module, used to obtain a preliminary test case set according to the test constraint conditions and the test case generation model, and optimize the preliminary test case set to obtain an optimized test case set;
[0042] The test case optimization module is used to execute the optimized test case set, adjust the optimized test case set according to the execution log, and obtain the target test case set.
[0043] In a third aspect, the present invention provides an electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the test case generation method as described in the first aspect of the present invention.
[0044] In a fourth aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the method for generating a test case as described in the first aspect of the present invention.
[0045] The test case generation method, system, electronic device and storage medium provided by the present invention can reduce manual writing time and manpower input, improve the test case generation efficiency, reduce errors that may occur in the manual writing process, and improve the accuracy of the test case by automatically generating test cases. By optimizing the allocation of test resources, resource waste is avoided and resource utilization is improved. According to the test execution status and feedback, the test cases are adjusted and optimized in real time to ensure that the test process can flexibly respond to changes and improve adaptability. At the same time, the generated test cases can cover various functional modules and demand points of the system, improve the test coverage, and avoid missing tests of key functions. Through high coverage and high accuracy test cases, the test quality is improved, omissions and errors are reduced, and the stability and reliability of the software product are ensured. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments are briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present invention and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without creative work.
[0047] Figure 1 This is a first schematic diagram of the test case generation method process provided by an embodiment of the present invention;
[0048] Figure 2 This is a second schematic diagram of the test case generation method provided by an embodiment of the present invention;
[0049] Figure 3 It is a third schematic diagram of the test case generation method process provided by an embodiment of the present invention;
[0050] Figure 4 is a fourth schematic diagram of the test case generation method provided by an embodiment of the present invention;
[0051] Figure 5 is a fifth schematic diagram of a test case generation method process provided by an embodiment of the present invention;
[0052] Figure 6 is a sixth schematic diagram of the test case generation method provided by an embodiment of the present invention;
[0053] Figure 7 It is a structural diagram of a test case generation system provided by an embodiment of the present invention;
[0054] Figure 8 It is a structural schematic diagram of an electronic device provided by an embodiment of the present invention.
[0055] Description of main component symbols:
[0056] 700, test case generation system; 710, data generation module; 720, condition setting module; 730, model generation module; 740, use case generation module; 750, use case optimization module; 800, electronic device; 810, processor; 820, communication interface; 830, memory; 840, communication bus. DETAILED DESCRIPTION
[0057] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be further clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. It should be noted that the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.
[0058] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of the present invention, the meaning of "plurality" is two or more, unless otherwise clearly and specifically defined.
[0059] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used in this specification are only for the purpose of describing specific embodiments and are not intended to limit the present invention. The term "and / or" used herein includes any and all combinations of one or more of the related listed items.
[0060] As the complexity and scale of software systems continue to increase, test case generation has become a key link in software development and testing. Traditional test case generation methods mainly rely on manual writing, which takes a lot of time and effort, especially when facing complex and large-scale software systems. This method is particularly inefficient. At the same time, due to human subjectivity and experience differences, test engineers may miss some important test scenarios or boundary conditions when writing test cases, and it is easy to make omissions. Traditional test case generation methods are difficult to meet the high-quality and efficient testing requirements in modern software development.
[0061] Example 1
[0062] In view of the above-mentioned deficiencies in the prior art, an embodiment of the present invention provides a method for generating a test case, which effectively solves the problem that the traditional test case generation method is difficult to meet the high-quality and high-efficiency testing requirements in modern software development. Figure 1 FIG. 1 is a first schematic diagram of a test case generation method provided by an embodiment of the present invention. Figure 1 As shown, the method comprises the following steps:
[0063] S100: Generate a data set according to demand information and historical test data.
[0064] In the embodiment of the present invention, the demand information includes demand documents and design documents, wherein the demand documents include functional requirements, non-functional requirements, user requirements, etc., and the design documents include system architecture diagrams and module design specifications, etc. The historical test data includes historical test cases, historical test results, and defect reports, etc. Figure 2 is a second schematic diagram of the test case generation method provided by an embodiment of the present invention, such as Figure 2 As shown, the generation of the dataset includes the following steps:
[0065] S110. Perform text analysis on the requirement documents and design documents to obtain key test points and test requirements.
[0066] Optionally, natural language processing technology is used to perform text parsing on requirement documents and design documents, extract key test points and test requirements, and identify and classify functional and non-functional requirements in the test requirements to provide support for the subsequent generation of test cases.
[0067] S120: Perform data preprocessing on historical test data to obtain a preprocessed data set.
[0068] Data preprocessing includes but is not limited to data cleaning, data supplementation and data correction. For example, it can clean historical test data, delete irrelevant information and redundant data, supplement missing data and correct abnormal data to ensure the integrity and accuracy of the data.
[0069] S130 , generating a data set according to key test points, test requirements and preprocessed data sets.
[0070] In an embodiment of the present invention, the data set includes input features and output labels, wherein the input features may be key test points and test requirements, and the output labels are historical test data.
[0071] S200: Setting test constraints according to demand information.
[0072] Requirement documents and design documents usually include information such as functional modules, demand points, project progress, test time windows and test resources. Test constraints can be set based on this requirement information. Figure 3 3 is a third schematic diagram of the test case generation method provided by an embodiment of the present invention. Figure 3 As shown in the figure, the setting of test constraints includes the following steps:
[0073] S210. Set test coverage constraints according to functional modules and requirements.
[0074] In order to ensure that the generated test cases can cover all functional modules and requirements of the software system, it is necessary to set test coverage constraints. Optionally, coverage indicators (such as functional coverage and code coverage) can be used to constrain and measure the coverage of test cases.
[0075] S220. Set execution time constraints according to the project progress and the test time window.
[0076] According to the software project progress and test time window, allocate appropriate execution time, control the execution time of each test case, and ensure that the testing process is completed within a reasonable time frame.
[0077] S230: Set resource limitation constraints according to test resources.
[0078] In the embodiment of the present invention, the test resources include but are not limited to testers, test environment and hardware equipment, etc. Resource limitation constraints are set to reasonably allocate the test resources, thereby avoiding resource conflicts and waste and optimizing resource utilization.
[0079] S240: Setting priority constraints according to preset paths and preset modules.
[0080] The preset path can be the critical path of the software system. The critical path is a series of interdependent activities in the software development process. The completion time of these activities determines the shortest completion time of the entire project. The preset module can be a high-risk module. A high-risk module refers to a software module with high risk hidden dangers due to technical difficulty, complexity, dependency or external factors. Test cases are generated first for functions and modules on the critical path of the software system, and tests are arranged first for modules and functions with higher risks.
[0081] S300: Use the data set to train the deep learning model to obtain a test case generation model.
[0082] Figure 4 4 is a schematic diagram of the test case generation method provided by an embodiment of the present invention. Figure 4 As shown, the generation of the test case generation model includes the following steps:
[0083] S310. Use the data set to train the deep learning model to obtain the test steps and expected results of the test case.
[0084] First, a deep learning model is constructed. The deep learning model can adopt a long short-term memory network LSTM or a Transformer model based on an attention mechanism. In an embodiment of the present invention, a Transformer model is used for training. The model performs well in processing natural language processing tasks. The model includes an input layer, an encoder layer, a decoder layer and an output layer. The input layer accepts the requirement description text, the encoder layer is an overlay layer of multiple self-attention mechanisms and feedforward neural networks, the decoder layer is an overlay layer of multiple self-attention mechanisms, encoder-decoder attention mechanisms and feedforward neural networks, and the output layer generates test cases, including test steps and expected results.
[0085] Then set the training parameters of the deep learning model, such as learning rate, batch size, number of training rounds, and optimizer. In the embodiment of the present invention, the learning rate is set to 0.001, and the learning rate can be dynamically adjusted according to the training process; the batch size is set to 32 or 64, which can be set according to the amount of data and computing resources; the number of training rounds is set to 10-50 rounds, which can be adjusted according to the convergence of the model; the optimizer uses the Adam optimizer, which has high effectiveness when processing large-scale data.
[0086] The data set is divided into training set, validation set and test set. Model training is performed according to the training parameters to obtain the mapping relationship between test cases and demand information. The training set is the main data for training the model, accounting for 60%-70% of the total data volume. The validation set is used for parameter adjustment and model selection, accounting for 15%-20% of the total data volume. The test set is used for the final evaluation of model performance, accounting for 15%-20% of the total data volume.
[0087] The pre-trained language representation model BERT based on the Transformer structure is used to extract the key features in the requirement description. The mapping relationship from the requirement description to the test case is learned through the Transformer model. During the training process, the Transformer model will automatically capture the key test points and test requirements in the requirement information, thereby generating corresponding test steps and expected results based on the key test points and test requirements.
[0088] S320. Use a reinforcement learning algorithm to optimize the test steps and expected results, and update the deep learning model according to the optimized test steps and the optimized expected results.
[0089] Reinforcement learning algorithm is used to optimize the test case generation strategy to maximize test coverage and detection efficiency. Specifically, the following steps are used for optimization:
[0090] First, the state and action are defined. In the embodiment of the present invention, the state is the progress of the current test case generation, including the generated test steps and expected results, and the action is the test step or expected result to be generated in the next step.
[0091] Then, a reward function is designed, including coverage reward and efficiency reward. The coverage reward is for the new test cases generated to cover new functional modules or execution paths, and the efficiency reward is for the new defects discovered during the execution of the test cases.
[0092] Then choose a reinforcement learning algorithm, you can choose the deep Q network algorithm DQN or the proximal policy optimization algorithm PPO. DQN stores the Q value of the state-action pair in the Q table and approximates the Q value through a deep neural network. PPO optimizes the policy function to obtain the maximum cumulative reward under the current policy.
[0093] Then, the reinforcement learning algorithm is used to train the model, randomly generate initial test cases, and select an action based on the current state, such as generating new test steps or expected results. Execute the action to generate new test cases, calculate the reward and update the Q value or policy function, and repeat the above steps until the model converges.
[0094] During the test execution process, the model can be updated in real time, and the generation strategy can be adjusted according to the new test results. At the same time, the benefits of exploring new test paths and utilizing existing test paths can be balanced to avoid local optimal solutions.
[0095] S330. Use a model optimization algorithm to optimize the updated deep learning model, use a cross-validation technique to evaluate the updated deep learning model, and obtain a test case generation model.
[0096] In an embodiment of the present invention, a genetic algorithm or a simulated annealing algorithm is used to optimize a deep learning model. Specifically, the genetic algorithm optimization includes the following steps:
[0097] A set of model parameters is randomly generated as the initial population, and the performance of each model parameter combination is evaluated to select the fitness function, such as the accuracy and coverage of the generated test cases. According to the fitness function, individuals with better performance are selected as parents, and new offspring are generated through crossover operations. Some parameters of the offspring are randomly modified to increase population diversity. The steps of parent selection, crossover generation of offspring, and modification of offspring parameters are repeated until the fitness function converges.
[0098] The optimization using simulated annealing algorithm includes the following steps:
[0099] Select a random combination of model parameters as the initial solution, set the initial temperature and cooling rate, randomly select a new solution in the neighborhood of the current solution, and decide whether to accept the new solution based on the acceptance probability function. The acceptance probability function is as follows:
[0100]
[0101] In the above formula, P(ΔE,T) is the probability of accepting a new solution, ΔE is the fitness difference between the new solution and the current solution, and T is the current temperature.
[0102] The temperature is gradually reduced so that the algorithm gradually converges to the global optimal solution, and the neighborhood search and acceptance probability steps are repeated until the temperature drops to the preset threshold.
[0103] Cross-validation techniques are used to evaluate the optimized deep learning model to avoid overfitting and underfitting problems. The specific steps include the following:
[0104] First, divide the data set into K subsets to ensure that the distribution of each subset is as similar as possible. Then select one subset as the validation set and the remaining K-1 subsets as the training set. Use the training set to train the optimized deep learning model, use the validation set to evaluate the model performance, and record the performance indicators of the model on the validation set, such as accuracy and coverage. Repeat the above steps K times, selecting a different subset as the validation set each time, ensuring that each subset is used as the validation set once, and calculate the average of the K validation results as the final performance indicator of the model.
[0105] S400, obtaining a preliminary test case set according to the test constraint conditions and the test case generation model, and optimizing the preliminary test case set to obtain an optimized test case set.
[0106] Using the trained test case generation model, a preliminary test case set is generated according to the set test constraints. The model generates specific test cases, including test steps and expected results, based on the input key test points and test requirements. The preliminary test case set is manually reviewed to ensure the rationality and feasibility of the test cases, and then the preliminary test case set is adjusted and optimized to ensure test coverage and execution efficiency. Finally, the test case generation model is used to dynamically optimize the preliminary test case set based on test results and feedback. Figure 5 5 is a fifth schematic diagram of the test case generation method provided by an embodiment of the present invention. Figure 5 As shown, optimizing the preliminary test case set includes the following steps:
[0107] S410: Obtain test results and user feedback for the preliminary test case set.
[0108] Record the execution of the preliminary test case set, including details of passes, failures, and errors. Collect feedback from testers and users on the preliminary test case set, especially defects found and suggestions for improvement.
[0109] S420. Adjust the test steps according to the test results and user feedback, and update the expected results.
[0110] Identify failed test cases and analyze the reasons for failure, such as functional defects and data problems. At the same time, evaluate the coverage of the initial test case set and identify uncovered functional modules and requirements. Based on the failure reasons and coverage analysis results, modify or add test steps to ensure that the preliminary test case set can cover more functional modules and requirements. At the same time, update the expected results based on actual test results and user feedback to ensure accuracy and consistency.
[0111] S430, merging duplicate cases in the preliminary test case set, and deleting invalid cases in the preliminary test case set.
[0112] Merge duplicate test cases in the preliminary test case set to reduce redundancy, optimize test resource utilization, delete invalid test cases that are no longer applicable to the preliminary test case set, and keep the preliminary test case set concise and efficient.
[0113] S500, executing the optimized test case set, adjusting the optimized test case set according to the execution log, and obtaining a target test case set.
[0114] The execution of the optimized test case set includes the following steps: publish the optimized test case set and assign it to testers through the test management system, and provide a detailed description of the test case, including the test purpose, test steps and expected results. At the same time, a test case query function is provided to facilitate testers to understand the test arrangement and case details at any time, and support querying test cases by requirements, function points and modules. A test case change function can also be provided to respond to changes in requirements and emergencies, record the change history of test cases, and ensure the traceability of changes. Monitor the execution process of test cases in real time, collect test execution data, analyze test results, identify potential problems and defects, and ensure the efficiency and coverage of the test process.
[0115] Figure 6 6 is a schematic diagram of the test case generation method provided by an embodiment of the present invention. Figure 6 As shown in the figure, the test case set after adjusting and optimizing according to the execution log includes the following steps:
[0116] S510: Monitor the execution status of the optimized test case set and obtain the execution log.
[0117] Record the execution log of each test execution, including execution time, execution steps, execution results, etc. At the same time, collect real-time feedback from testers on the execution of the optimized test case set, especially the problems found and improvement suggestions.
[0118] S520. Obtain the success rate and execution efficiency of the optimized test case set according to the execution log.
[0119] The success rate and failure rate of the optimized test case set are calculated based on the information in the execution log, the test steps and modules with frequent problems are identified, the execution efficiency of the optimized test case set is evaluated, and the test steps and modules that take a long time are identified.
[0120] S530. Adjust the expected results and test steps of the optimized test case set according to the success rate and execution efficiency.
[0121] According to the success rate and execution efficiency, adjust the test purpose of the test case for the test steps and modules with frequent problems and long test time to ensure that they can cover new requirements or new problems found. At the same time, modify or rearrange the test steps to improve the execution efficiency and coverage of the optimized test case set. Update the expected results based on the actual test results and user feedback to ensure that they are consistent with the actual situation and avoid false positives and false negatives.
[0122] During the test execution of the optimized test case set, continuously monitor and analyze the test execution status, adjust the test cases in real time, and adjust the test cases in a timely manner according to new problems and changes in requirements discovered during the test execution to ensure the flexibility and efficiency of the testing work.
[0123] The test case generation method provided in the embodiment of the present invention reduces manual writing time and manpower input by automatically generating test cases, thereby improving the test case generation efficiency. When requirements change or new functions are added, new test cases are quickly generated to ensure that the testing work can be followed up in a timely manner. The errors that may occur in the manual writing process are reduced, the generated test cases are ensured to be consistent and reliable, and the differences in test cases caused by differences in personal understanding are reduced. At the same time, test cases covering different functions and execution paths are generated to ensure that all aspects of the software are fully tested. In the event of changes in requirements or emergencies, test cases are quickly generated and adjusted to ensure that the testing work responds to changes in a timely manner.
[0124] Example 2
[0125] Based on the same technical concept as the method embodiment of the above embodiment 1, the embodiment of the present invention provides a test case generation system. Figure 7 is a schematic diagram of the structure of a test case generation system provided by an embodiment of the present invention, such as Figure 7 As shown, the test case generation system 700 includes:
[0126] A data generation module 710 is used to generate a data set based on demand information and historical test data;
[0127] The condition setting module 720 is used to set the test constraint conditions according to the requirement information;
[0128] A model generation module 730 is used to train a deep learning model using a data set to obtain a test case generation model;
[0129] A case generation module 740 is used to obtain a preliminary test case set according to the test constraint conditions and the test case generation model, and optimize the preliminary test case set to obtain an optimized test case set;
[0130] The test case optimization module 750 is used to execute the optimized test case set, adjust the optimized test case set according to the execution log, and obtain the target test case set.
[0131] The test case generation system provided by the embodiment of the present invention optimizes the allocation of test resources, avoids resource waste, improves resource utilization, reduces the cost of manually writing test cases, saves testers' time and energy, and improves overall test efficiency by automatically generating and managing test cases. At the same time, it provides intelligent test case query, change and management functions, which facilitates testers to understand and adjust test arrangements at any time and improves the efficiency of test management. The test execution process is monitored in real time, and problems in the test process are discovered and solved in a timely manner to ensure efficient testing. Through high coverage and high accuracy test cases, the test quality is improved, omissions and errors are reduced, and the stability and reliability of software products are ensured. Through comprehensive and accurate test cases, the defect discovery rate is increased to ensure that the software meets high quality standards before release.
[0132] It can be understood that the implementation method of the test case generation method described in the above embodiment 1 is also applicable to this embodiment and can achieve the same technical effect, so it will not be repeated here.
[0133] Example 3
[0134] Based on the same concept, an embodiment of the present invention further provides an electronic device, Figure 8 is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention, such as Figure 8 As shown, the electronic device 800 may include: a processor 810, a communication interface 820, a memory 830 and a communication bus 840, wherein the processor 810, the communication interface 820, and the memory 830 communicate with each other through the communication bus 840. The processor 810 may call the logic instructions in the memory 830 to execute the steps of the test case generation method described in the above embodiments. For example, it includes:
[0135] S100, generating a data set according to demand information and historical test data;
[0136] S200, setting test constraints according to demand information;
[0137] S300, using the data set to train the deep learning model to obtain a test case generation model;
[0138] S400, obtaining a preliminary test case set according to the test constraint conditions and the test case generation model, and optimizing the preliminary test case set to obtain an optimized test case set;
[0139] S500, executing the optimized test case set, adjusting the optimized test case set according to the execution log, and obtaining a target test case set.
[0140] The processor 810 may be a central processing unit (CPU). The processor may also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, or a combination of the above chips.
[0141] In addition, the logic instructions in the above-mentioned memory 830 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.
[0142] The memory 830 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created by the processor, etc. In addition, the memory may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory may optionally include a memory remotely disposed relative to the processor, and these remote memories may be connected to the processor via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0143] Example 4
[0144] Based on the same concept, an embodiment of the present invention further provides a computer-readable storage medium, which stores a computer program, and the computer program includes at least one code segment, which can be executed by a main control device to control the main control device to implement the steps of the test case generation method described in the above embodiments. For example, it includes:
[0145] S100, generating a data set according to demand information and historical test data;
[0146] S200, setting test constraints according to demand information;
[0147] S300, using the data set to train the deep learning model to obtain a test case generation model;
[0148] S400, obtaining a preliminary test case set according to the test constraint conditions and the test case generation model, and optimizing the preliminary test case set to obtain an optimized test case set;
[0149] S500, executing the optimized test case set, adjusting the optimized test case set according to the execution log, and obtaining a target test case set.
[0150] Based on the same technical concept, an embodiment of the present invention further provides a computer program, which is used to implement the above method embodiment when executed by a main control device.
[0151] The computer program may be stored in whole or in part on a computer-readable storage medium packaged with the processor, or may be stored in whole or in part on a memory not packaged with the processor.
[0152] Based on the same technical concept, an embodiment of the present invention further provides a processor, which is used to implement the above method embodiment. The above processor can be a chip.
[0153] In summary, the test case generation method, system, electronic device and storage medium provided by the present invention can reduce manual writing time and manpower input, improve the test case generation efficiency, reduce errors that may occur in the manual writing process, and improve the accuracy of test cases by automatically generating test cases. By optimizing the allocation of test resources, resource waste is avoided and resource utilization is improved. According to the test execution status and feedback, the test cases are adjusted and optimized in real time to ensure that the test process can flexibly respond to changes and improve adaptability. At the same time, the generated test cases can cover various functional modules and demand points of the system, improve the test coverage, and avoid missing tests of key functions. Through high coverage and high accuracy test cases, the test quality is improved, omissions and errors are reduced, and the stability and reliability of the software product are ensured.
[0154] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0155] The above-mentioned embodiments only express several implementation methods of the present invention, and the description thereof is relatively specific and detailed, but it cannot be understood as limiting the scope of the patent of the present invention. It should be pointed out that, for ordinary technicians in this field, several variations and improvements can be made without departing from the concept of the present invention, which all belong to the protection scope of the present invention. Therefore, the protection scope of the patent of the present invention shall be subject to the attached claims.
[0156] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for generating a test case, characterized in that: The method comprises: Generate data sets based on demand information and historical test data; Setting test constraints according to the requirement information; Using the data set to train the deep learning model to obtain a test case generation model; Acquire a preliminary test case set according to the test constraint conditions and the test case generation model, and optimize the preliminary test case set to obtain an optimized test case set; Execute the optimized test case set, adjust the optimized test case set according to the execution log, and obtain the target test case set.
2. The method for generating a test case according to claim 1, characterized in that: The demand information includes a demand document and a design document, and the step of generating a data set according to the demand information and historical test data includes: Performing text analysis on the requirement document and the design document to obtain key test points and test requirements; Performing data preprocessing on the historical test data to obtain a preprocessed data set; The data set is generated according to the key test points, the test requirements and the preprocessed data set.
3. The method for generating a test case according to claim 2, characterized in that: The test constraint conditions include test coverage constraint, execution time constraint, resource limitation constraint and priority constraint. The setting of the test constraint conditions according to the requirement information includes: Setting the test coverage constraint according to functional modules and requirements; Setting the execution time constraints according to the project schedule and the test time window; Setting the resource limit constraint according to the test resources; The priority constraint is set according to a preset path and a preset module.
4. The method for generating a test case according to claim 2, characterized in that: The method of using the data set to train the deep learning model to obtain a test case generation model includes: Using the data set to train the deep learning model, and obtaining the test steps and expected results of the test case; Using a reinforcement learning algorithm to optimize the test steps and the expected results, and updating the deep learning model according to the optimized test steps and the optimized expected results; A model optimization algorithm is used to optimize the updated deep learning model, and a cross-validation technique is used to evaluate the optimized deep learning model to obtain the test case generation model.
5. The method for generating a test case according to claim 4, characterized in that: The step of using the data set to train the deep learning model to obtain the test steps and expected results of the test case includes: Constructing the deep learning model and setting training parameters of the deep learning model; Using the data set to train the deep learning model according to the training parameters to obtain a mapping relationship between the test case and the requirement information; Acquire the key test points and the test requirements according to the mapping relationship; The test steps and the expected results of the test case are generated according to the key test points and the test requirements.
6. The method for generating a test case according to claim 4, characterized in that: The step of optimizing the preliminary test case set to obtain an optimized test case set includes: Obtaining test results and user feedback for the preliminary test case set; Adjust the test steps according to the test results and the user feedback, and update the expected results; The duplicate cases in the preliminary test case set are merged, and the invalid cases in the preliminary test case set are deleted.
7. The method for generating a test case according to claim 6, characterized in that: The step of adjusting the optimized test case set according to the execution log includes: Monitor the execution of the optimized test case set and obtain execution logs; Obtaining the success rate and execution efficiency of the optimized test case set according to the execution log; The expected results and test steps of the optimized test case set are adjusted according to the success rate and the execution efficiency.
8. A test case generation system, characterized in that: The system comprises: A data generation module is used to generate a data set based on demand information and historical test data; A condition setting module, used to set test constraint conditions according to the requirement information; A model generation module, used to train a deep learning model using the data set to obtain a test case generation model; A case generation module, used to obtain a preliminary test case set according to the test constraint conditions and the test case generation model, and optimize the preliminary test case set to obtain an optimized test case set; The test case optimization module is used to execute the optimized test case set, adjust the optimized test case set according to the execution log, and obtain the target test case set.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: The processor executes the computer program to implement the test case generation method according to any one of claims 1 to 7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method for generating a test case as claimed in any one of claims 1 to 7 is implemented.
Citation Information
Cited By
Security transaction system automatic test method based on result feedback
CN119847940A
Unit test case generation large model fine tuning method based on feedback reinforcement learning
CN120407426A
Test case optimization method and device based on machine learning and medium
CN121705167A