Test case generation method, device, computer equipment, computer readable storage medium and computer program product

The heuristic search operator generates test case populations, combined with the evaluation of multi-objective fitness and execution time, the balance of time cost and coverage in software product line testing is solved, and efficient test case generation is achieved.

CN119357068BActive Publication Date: 2025-04-04CHINA TELECOM CLOUD TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202411932227.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-12-26
Publication Date
2025-04-04
Estimated Expiration
2044-12-26

AI Technical Summary

Technical Problem

Existing model-based testing techniques are difficult to balance time cost and test coverage in testing the software product line, resulting in inefficient testing.

Method used

The preset heuristic search operator is used to generate test case populations, and the target test case individuals are selected through a comprehensive evaluation of multi-objective fitness, distance and execution time. Cross- and mutation processing is used to generate a new set of test cases, and the target test model is inferred based on the event sequence, and the target test case is finally generated.

Benefits of technology

Improves the coverage of test cases, reduces the total execution time and size cost of test cases in the test suite, and enhances the flexibility and applicability of test case generation methods.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119357068B_ABST
    Figure CN119357068B_ABST
Patent Text Reader

Abstract

The present application relates to the field of automated testing technology, and in particular to a method, device, computer equipment, computer-readable storage medium, and computer program product for generating test cases. The method comprises: using a heuristic search operator to generate a test case population; selecting a target test case individual and performing crossover and mutation processing on it as a parent to obtain a new test case population according to the multi-objective fitness of the test case individuals in the test case population, the distance between the test case individuals, and the execution time corresponding to each test case individual; and inferring the target test model and generating the target test case according to the event sequence corresponding to the test case set. The use of this method can solve the problem that it is difficult to balance the time cost and the test coverage in the prior art, so as to achieve the technical effect of maximizing the test coverage of the target test case and reducing the total execution time and size cost of the test case in the test suite.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of automated testing technology, and in particular to a test case generation method, apparatus, computer equipment, computer-readable storage medium, and computer program product. Background Art

[0002] In recent years, with the further development of automation technology, software product lines (SPLs) have emerged. A software product line refers to a collection of software-intensive systems with manageable common features. To improve the testing efficiency of software product lines, model-based testing technology can be used for automated testing.

[0003] In traditional technology, model-based testing technology can be used to represent the behavior of a software product line as one or more models, and the models are used as the basis for test cases to search in the test space of the software product line, thereby automatically generating and executing test cases that can cover various scenarios and paths of the software product line to complete the automated testing of the software product line. However, since software product lines usually involve a combination of multiple products, features, and configurations, the test space is huge, and existing model-based testing technologies are difficult to strike a balance between time cost and test coverage. Summary of the invention

[0004] Based on this, it is necessary to provide a method, apparatus, computer device, computer-readable storage medium and computer program product for generating test cases that can increase the effectiveness of test cases while considering reducing time costs in response to the above technical problems.

[0005] In a first aspect, the present application provides a method for generating a test case, comprising:

[0006] Get test code data;

[0007] Using a preset heuristic search operator to process the test code data to generate a test case population;

[0008] Selecting a target test case individual from the test case population according to the multi-objective fitness of the test case individuals in the test case population, the distances between different test case individuals, and the execution time corresponding to each test case individual;

[0009] Using the target test case individual as a parent to perform crossover and mutation processing to obtain a new test case population, and using the test case population and the new test case population to determine a test case set;

[0010] Inferring a target test model according to the event sequence corresponding to the test case set;

[0011] A target test case is generated through the target test model.

[0012] In one embodiment, selecting a target test case individual from the test case population according to the multi-objective fitness of the test case individuals in the test case population, the distance between different test case individuals, and the execution time corresponding to each test case individual includes:

[0013] Determine the multi-objective fitness of the test case individuals under the coverage objective and the scale quantity objective;

[0014] Determining the distance between the individual test cases according to the differences between the individual test cases;

[0015] Generate a target evaluation parameter corresponding to the test case individual using the multi-target fitness, the distance and the execution time;

[0016] A test case individual whose target evaluation parameter meets a preset condition is selected from the test case population as the target test case individual.

[0017] In one embodiment, the process of processing the test code data using a preset heuristic search operator to generate a test case population includes:

[0018] Randomly generate an initial test population using the test code data;

[0019] According to the non-dominated levels and crowding distances of the initial individuals in the initial test population, the initial test population is iteratively processed to obtain a second generation population;

[0020] According to the non-dominated strength of the second-generation individuals in the second-generation population, the second-generation population is iteratively processed to obtain a third-generation population;

[0021] The third generation population is iteratively processed according to the speed and position of the third generation individuals in the third generation population to obtain the test case population.

[0022] In one embodiment, the inference of the target test model according to the event sequence corresponding to the test case set includes:

[0023] Taking the events corresponding to the test case set as vertices, and using the event sequence to construct edges between the vertices, to obtain an event sequence graph corresponding to the test case set;

[0024] Determine model parameters using the test behavior information, event interaction information, and event sequence relationship in the event sequence diagram;

[0025] The target test model is constructed using the model parameters.

[0026] In one embodiment, the method further comprises:

[0027] Iteratively process the event sequence to determine a prefix path that matches the current iteration state;

[0028] adding a new vertex in the event sequence graph through the prefix path;

[0029] Generate a new model element by using the newly added vertex and the edge between the vertices;

[0030] The target test model is updated using the model elements.

[0031] In one embodiment, the determining of model parameters by using the test behavior information, event interaction information, and event sequence relationship in the event sequence diagram includes:

[0032] Determine the target vertex and the target edge that meet the path restriction condition from the event sequence graph;

[0033] Determine the test behavior information, event interaction information, and event sequence relationship corresponding to the target vertex and the target edge.

[0034] In a second aspect, the present application also provides a test case generation device, comprising:

[0035] A data acquisition module, used to acquire test code data;

[0036] A heuristic processing module, used to process the test code data using a preset heuristic search operator to generate a test case population;

[0037] An individual selection module, configured to select a target test case individual from the test case population according to the multi-objective fitness of the test case individuals in the test case population, the distance between different test case individuals, and the execution time corresponding to each test case individual;

[0038] An individual optimization module, used to use the target test case individual as a parent to perform crossover and mutation processing to obtain a new test case population, and determine a test case set using the test case population and the new test case population;

[0039] A model inference module, used to infer a target test model according to the event sequence corresponding to the test case set;

[0040] The use case generation module is used to generate a target test case through the target test model.

[0041] In a third aspect, the present application further provides a computer device, wherein the computer device comprises a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the method for generating a test case described in any one of the embodiments of the first aspect is implemented.

[0042] In a fourth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the method for generating a test case described in any one of the embodiments of the first aspect above is implemented.

[0043] In a fifth aspect, the present application further provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, the method for generating a test case described in any one of the embodiments of the first aspect above is implemented.

[0044] The above-mentioned test case generation method, device, computer equipment, computer-readable storage medium and computer program product obtain test code data; use a preset heuristic search operator to process the test code data to generate a test case population; select target test case individuals from the test case population according to the multi-objective fitness of the test case individuals in the test case population, the distance between different test case individuals and the execution time corresponding to each test case individual; use the target test case individuals as parents to perform crossover and mutation processing to obtain a new test case population, and use the test case population and the new test case population to determine a test case set; according to the event sequence corresponding to the test case set, infer the target test model; generate the target test case through the target test model, which can maximize the test coverage of the target test case and reduce the total execution time and size cost of the test cases in the test suite. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] In order to more clearly illustrate the technical solutions in the embodiments of the present application or related technologies, the drawings required for use in the embodiments of the present application or related technical descriptions will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.

[0046] Figure 1 A schematic diagram of a flow chart of a method for generating a test case in an embodiment;

[0047] Figure 2A flowchart of a step of selecting a target test case individual in an embodiment;

[0048] Figure 3 A schematic diagram of a flow chart of a test case population generation step in one embodiment;

[0049] Figure 4 A schematic diagram of a process for constructing a target test model in one embodiment;

[0050] Figure 5 is a schematic diagram of an event sequence diagram in one embodiment;

[0051] Figure 6 A schematic diagram of a process flow of a target test model updating step in one embodiment;

[0052] Figure 7 is a structural block diagram of a test case generating device 700 in an embodiment;

[0053] Figure 8 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION

[0054] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0055] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.

[0056] In an exemplary embodiment, Figure 1 As shown, a method for generating a test case is provided. This embodiment uses the method applied to a server as an example for illustration. It can be understood that the method can also be applied to a terminal, and can also be applied to a system including a terminal and a server, and is implemented through the interaction between the terminal and the server. In this embodiment, the method includes the following steps S102 to S112:

[0057] Step S102, obtaining test code data.

[0058] Exemplarily, the server may obtain the test code data from a source code database or a test code database, or the server may obtain the test code data from a data communication network.

[0059] Step S104: Process the test code data using a preset heuristic search operator to generate a test case population.

[0060] The heuristic search operator can be used to characterize the function used in the heuristic search algorithm. The heuristic search operator can include but is not limited to the operator of the ant colony algorithm, the operator of the genetic algorithm, the operator of the simulated annealing algorithm, etc.

[0061] Exemplarily, the server may store a preset heuristic search operator. The preset heuristic search operator may be used to process the test code data as follows: an initial population of test cases is randomly generated using the test code data, and corresponding test case individuals are selected from the initial population according to the fitness of each individual in the initial population in maximizing the test target and minimizing the test target of the test case. The test case population is formed using the test case individuals.

[0062] Step S106 , selecting a target test case individual from the test case population according to the multi-objective fitness of the test case individual in the test case population, the distance between different test case individuals, and the execution time corresponding to each test case individual.

[0063] Exemplarily, the server can use the objective function to evaluate the multi-objective fitness of the test case individual in the test case of maximizing the test goal and minimizing the test goal. The distance between different test case individuals is determined by using Euclidean distance, cosine similarity or Jaccard similarity coefficient. The execution time spent by the preset heuristic search operator in the process of generating each test case individual is obtained. The target test case individual with the optimal solution for test case generation is selected from the test case population using multi-objective fitness, distance and execution time.

[0064] Step S108, using the target test case individual as the parent to perform crossover and mutation processing to obtain a new test case population, and using the test case population and the new test case population to determine the test case set.

[0065] Exemplarily, the server can use the target test case individual selected in step S106 as the parent, extract code elements between different target test cases for cross-replacement, and / or perform mutation processing on a certain code parameter in the target test case to generate a new test case individual. Use the new test case individual to build a new test case population. Perform a performance comparison between the existing test case population generated in step S104 and the new test case population generated in the current step S108, so as to screen out the test case individuals that achieve the best performance in terms of individual population, diversity between populations, and time cost to build a test case collection.

[0066] Step S110, inferring a target test model according to the event sequence corresponding to the test case set.

[0067] Among them, the event sequence can be used to represent the time sequence composed of all events experienced from the start node to the end node of the test case.

[0068] Exemplarily, the server can extract all events and the time sequence between events from the test case set. The events and the time sequence between events are used to form an event sequence diagram corresponding to the test case set. Through the model-based testing algorithm, the system under test is modeled according to the event sequence diagram, covering the test path of the test case set, so as to construct a target test model.

[0069] Step S112, generating a target test case through a target test model.

[0070] Exemplarily, the server can take the target test model and the preset test selection criteria as input to generate the representation of the abstract test case and the test suite. The abstract test case is mapped to a method call to a page object class (also known as Page Object) or assertion through the object application programming interface to form a target test case that can be executed in the system under test.

[0071] In the above test case generation method, by using a preset heuristic search operator to generate a test case population, meaningful test cases can be generated and the quality of the test case population can be improved. By selecting target test case individuals according to multi-objective fitness, individual distance and execution time, and using the target test case individuals as parent crossover mutations to generate new test case populations, the total execution time and size cost of the test cases in the test suite can be reduced while maximizing the test coverage. By combining the existing test case set with the model-based testing algorithm, the target test model is inferred according to the event sequence corresponding to the test case set, and the target test case is generated through the target test model. It can adapt to the test case generation scenario of the system under test with complex and fine-grained interactions, and improve the flexibility and applicability of the test case generation method.

[0072] In an exemplary embodiment, Figure 2 As shown, step S106 may include the following steps S202 to S208. Among them:

[0073] Step S202, determining the multi-objective fitness of the test case individuals under the coverage objective and the scale quantity objective.

[0074] Exemplarily, the server can compare the code of each individual test case with the source code of the system under test to determine the coverage parameter of the individual test case. The fitness of the individual test case under the coverage target is evaluated according to the coverage parameter, and the fitness under the scale target is evaluated according to the number of individual test cases, so as to obtain the multi-target fitness of the individual test case.

[0075] Optionally, in some implementations, the coverage target may be expressed using the following formula:

[0076] .

[0077] in, Function to find the maximum value. Indicates a state of the system under test.

[0078] Indicates the effectiveness of an individual test case in a certain state of the system under test. Represents the coverage of individual test cases relative to the system under test.

[0079] Optionally, in some other implementations, the following formula may be used to express the scale quantity target:

[0080] .

[0081] in, Function to use to find the minimum value. (Also known as Transition Coverage) can be used to indicate the proportion of state transitions of the system under test that are covered by individual test cases. (also known as Transition Pair) can be used to indicate the coverage of system state transition pairs of the system under test. (also known as Size of Test Suite) can be used to indicate the total number of individual test cases.

[0082] Alternatively, in some other implementations, the following formula may be used to determine the multi-objective fitness:

[0083] .

[0084] in, Can represent multi-objective fitness. Can represent individual test cases. The weight coefficient used to represent the multi-objective fitness. Refers to changes in coverage targets and scale quantity targets.

[0085] is the calling heuristic Execution time.

[0086] The server can compare the current best solution in the test case population (that is, the test case individual with the best performance) with the existing solution in the final solution through the above multi-objective fitness determination formula. If the performance of the current solution is higher than that of the existing solution, then will be replaced. The server passes The heuristic performance of individual test cases can be evaluated.

[0087] Step S204, determining the distance between individual test cases according to the differences between individual test cases.

[0088] For example, the server can determine the differences between individual test cases by comparing the codes of different individual test cases, and process the differences between individual test cases using the Jaccard similarity coefficient to generate the distance between individual test cases.

[0089] Optionally, in some implementations, the distance may be determined using the following formula:

[0090] .

[0091] in, Indicates distance. Represents a function used to measure the diversity between test case individuals, which evaluates the diversity between different test case individuals by calculating the distance between different test case individuals. The higher the value of, the higher the diversity among test case individuals. represents test case individual 1, Represents test case individual 2.

[0092] Optionally, in some implementations, the following formula may be used to determine the cumulative sum of the diversity between individual test cases:

[0093] .

[0094] in, Function for cumulative calculation The server can compare the cumulative sum with the diversity of existing results. If the cumulative sum is greater than the diversity of existing results, it means that the diversity has improved.

[0095] Step S206, using the multi-objective fitness, distance and execution time, generate the target evaluation parameters corresponding to the test case individuals.

[0096] Exemplarily, the server may store weight values ​​corresponding to the multi-objective fitness, distance, and execution time. The multi-objective fitness, distance, and execution time are weighted using the corresponding weight values, and the weighted values ​​are added to obtain the target evaluation parameters corresponding to the test case individuals.

[0097] Optionally, in some implementations, the execution time may be determined by the following formula:

[0098] .

[0099] in, Can be used to represent heuristic algorithms When generating individual test cases The execution time of the process.

[0100] Optionally, in some implementations, the target evaluation parameter may be determined by the following formula:

[0101] .

[0102] in Represents individual test cases The target evaluation parameters, , and Indicates the corresponding weight value, which can be set by the user. The weight value can be used to adjust the influence of the corresponding multi-objective fitness, distance and execution time in the target evaluation parameters. It can represent the multi-objective fitness of individual test cases. Can represent individual test cases and The distance between. It can represent the execution time of individual test cases.

[0103] Step S208: Select test case individuals whose target evaluation parameters meet preset conditions from the test case population as target test case individuals.

[0104] Exemplarily, the server may sort the individual test cases from large to small according to the target evaluation parameter. An improved selection rule with an improved selection function is used to select the first test case individual or the test case individual in the top n% (the value of n can be set according to user requirements) of the sorting result of the target evaluation parameter as the target test case individual that meets the preset conditions.

[0105] In this embodiment, the target evaluation parameters are comprehensively determined by integrating multiple different metrics, and the final target test case individuals are selected based on the target evaluation parameters, which can help improve the diversity and intensification of balance based on reinforcement learning.

[0106] In an exemplary embodiment, Figure 3 As shown, step S102 may include the following steps S302 to S308. Among them:

[0107] Step S302: randomly generate an initial test population using the test code data.

[0108] Exemplarily, the server may encode the test code data into a character string or a digital sequence in a preset form, and randomly generate an initial population of test cases using the character string or the digital sequence, that is, obtain an initial test population.

[0109] Step S304, iteratively processing the initial test population according to the non-dominated levels and crowding distances of the initial individuals in the initial test population to obtain a second generation population.

[0110] Exemplarily, the server may use an operator of a non-dominated sorting genetic algorithm with a low-level heuristic (NSGA-II-LLH) to determine the non-dominated level and crowding distance of each initial individual in the initial test population. The initial individuals whose non-dominated level and crowding distance meet the preset iteration conditions (for example, the non-dominated level reaches a preset level threshold, or the crowding distance is greater than a preset distance threshold, etc.) are selected as parents for crossover and mutation processing to generate a second-generation population of test cases.

[0111] Step S306, iteratively processing the second generation population according to the non-dominated strength of the second generation individuals in the second generation population to obtain a third generation population.

[0112] Exemplarily, the server may use an operator of a Pareto evolutionary algorithm with low-level heuristic strength (SPEA2-LLH) to determine the non-dominated strength of the initial individuals in the initial test population and the non-dominated strength of each second-generation individual in the second-generation population. The second-generation individuals with higher non-dominated strength than the initial individuals are selected as parents for crossover and mutation processing to generate the third-generation population of the test case.

[0113] Step S308, iteratively processing the third generation population according to the speed and position of the third generation individuals in the third generation population to obtain a test case population.

[0114] For example, the server may use a particle swarm optimization algorithm with low-level heuristics (PSO-LLH) to determine the speed and position of the third-generation individuals in the third-generation population. The third-generation individuals whose speed and position reach a preset iteration threshold are selected as parents for crossover and mutation processing to obtain a new test case population.

[0115] In this embodiment, by combining multiple meta-heuristic new algorithms to iteratively optimize the test case population, it can not only ensure that the generated test case population meets the specific needs of users, but also help to improve the quality and performance of the test case population.

[0116] In an exemplary embodiment, Figure 4 As shown, step S110 may include the following steps S402 to S406. Among them:

[0117] Step S402, taking the events corresponding to the test case set as vertices, and using the event sequence to construct edges between the vertices, to obtain an event sequence graph corresponding to the test case set.

[0118] Exemplarily, the server can extract events and the time sequence between events from the test case set. With the events corresponding to the test case set as vertices, edges between vertices are constructed using event sequences to form a directed graph of event sequences, that is, an event sequence graph corresponding to the test case set is obtained.

[0119] Optionally, in some implementations, the server may generate the following test case set:

[0120] ,

[0121] ,

[0122] ,

[0123] .

[0124] in, , , , can represent a test case respectively. The server maps the test case set to the event sequence model and can generate Figure 5 The event sequence diagram shown.

[0125] Among them, the test case and Representing the same sequence of events, Different parameter values ​​(param1:value1 / value2) are used to distinguish. Test case and and There is a common prefix path prefix (i.e. ), so the remaining suffix suffix (i.e. ) is appended to the end of the path prefix representing the public part. There is no common prefix path with the other three use cases, so a different branch is added to the initial node.

[0126] Step S404: Determine model parameters using the test behavior information, event interaction information, and event sequence relationship in the event sequence diagram.

[0127] Step S406: construct a target test model using the model parameters.

[0128] Exemplarily, the server can determine the model parameters by using the test behavior information of the system under test in the event sequence diagram, the event interaction information between the events of the test case and the expected behavior of the system under test, and the event sequence relationship corresponding to the test case. The model parameters are used to update the initial event sequence model to obtain the target test model.

[0129] In this embodiment, by inferring a target test model from an existing test case set, the synergy between the existing automated test and the model-based test method can be improved.

[0130] In an exemplary embodiment, Figure 6 As shown, the following steps S602 to S608 are also provided. Among them:

[0131] Step S602, iteratively process the event sequence to determine a prefix path that matches the current iteration state.

[0132] Step S604: adding a new vertex to the event sequence graph through the prefix path.

[0133] The prefix path can be used to represent the front part of the method call sequence currently iterated.

[0134] Exemplarily, the server can extract the event sequence of method calls from the test case set for iterative processing to build or update the target test model. In the process of iterative processing of the event sequence of method calls, check whether the prefix path (prefix) matching the current iteration state already exists in the target test model. This prefix path is constructed by gradually adding new vertices (representing method calls / events) in the target test model until a method call in the event sequence is encountered.

[0135] Step S606: Generate new model elements using the edges between the newly added vertices.

[0136] Step S608: Update the target test model using the model elements.

[0137] Exemplarily, in the target test model, if the last method call has parameters, it usually means that the method call is an operation that produces side effects, that is, this method call will change the state of the system under test or produce some output. Compared with method calls without parameters (such as query or verification operations), method calls with parameters are more likely to affect the expected behavior of the system under test. Therefore, if the prefix path exists in the target test model and the last method call has parameters, the node of the last method call is merged with the newly added vertex. Otherwise, no merging operation is required. The new event sequence is determined using the edges between the newly added vertices and the original vertices in the target test model. New model elements are generated according to the new event sequence. The target test model is updated using the new model elements.

[0138] Optionally, in some implementations, if the current prefix path is not in the target test model, a new node may be created to represent the current method call as the end point corresponding to the current prefix path, and the end point may be added to the target test model. If the current method call is already the last node in the event sequence, a special end node may also be added to represent the end of the event sequence, and the current node may be connected to the end node.

[0139] Optionally, in some embodiments, if the current prefix path exists in the target test model, the last method call in the event sequence can be detected. If the last method call has no parameters, it can be explained that the method call may be a query or verification operation that does not produce side effects, and no merge operation is required. Otherwise, in the case where the last method call has parameters, it is necessary to query the target test model for a path that matches the current prefix path and determine the last node with parameters. The last method call and its parameters in the current sequence are merged with the found node. That is, the information of the node is updated to include the new method call and parameters corresponding to the newly added vertex.

[0140] Optionally, in other implementations, the server may repeatedly perform the above-mentioned checking and merging operations, and continuously update the target test model until all method call sequences are processed. When all method call sequences are iteratively processed and the target test model is updated, the updated target test model may be used as the final model for generating the target test case.

[0141] In this embodiment, the test coverage of the target test model can be increased by iteratively updating the target test case by adding a new vertex in the event sequence.

[0142] In an exemplary embodiment, step S404 may also include: determining the target vertex and target edge that meet the path restriction conditions from the event sequence diagram; and determining the model parameters using the test behavior information, event interaction information and event sequence relationship corresponding to the target vertex and target edge.

[0143] Exemplarily, the following path constraints may be stored in the server: 1. Each target vertex can be reached through a path to ensure that each event vertex in the event sequence diagram is accessible, thereby ensuring that the subsequent test cases generated based on the target test model can cover all events. 2. It must be reachable from all vertices. A sequence of events from the start node to the end node can become a complete event sequence, representing a test case, to ensure that each event in the event sequence diagram is reachable, thereby ensuring that the test case can completely execute the event sequence from start to end. Using the above path constraints, valid target vertices and target edges can be screened out from the event sequence diagram. The model parameters are determined using the test behavior information, event interaction information, and event sequence relationship corresponding to the target vertices and target edges.

[0144] In this embodiment, by using path restriction conditions to constrain nodes in the event sequence diagram, it is possible to avoid generating untrustworthy paths or test cases, thereby improving the test execution success rate of the target test model.

[0145] It should be understood that, although the steps in the flowcharts involved in the above embodiments are displayed in sequence according to the indications of the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless there is a clear description in this article, there is no strict order restriction on the execution of these steps, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above embodiments may include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.

[0146] Based on the same inventive concept, the embodiment of the present application also provides a test case generation device for implementing the test case generation method involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in the embodiments of the device for generating one or more test cases provided below can refer to the limitations of the test case generation method above, and will not be repeated here.

[0147] In an exemplary embodiment, Figure 7 As shown, a test case generation device 700 is provided, comprising: a data acquisition module 702, an inspiration processing module 704, an individual selection module 706, an individual optimization module 708, a model inference module 710 and a test case generation module 712, wherein:

[0148] The data acquisition module 702 is used to acquire test code data.

[0149] The heuristic processing module 704 is used to process the test code data using a preset heuristic search operator to generate a test case population.

[0150] The individual selection module 706 is used to select a target test case individual from the test case population according to the multi-objective fitness of the test case individuals in the test case population, the distance between different test case individuals, and the execution time corresponding to each test case individual.

[0151] The individual optimization module 708 is used to use the target test case individual as the parent to perform crossover and mutation processing to obtain a new test case population, and determine the test case set using the test case population and the new test case population.

[0152] The model inference module 710 is used to infer the target test model according to the event sequence corresponding to the test case set.

[0153] The use case generation module 712 is used to generate a target test case through a target test model.

[0154] In an exemplary embodiment, the individual selection module 706 includes: a fitness evaluation unit, which is used to determine the multi-objective fitness of the test case individual under the coverage target and the scale quantity target; a distance determination unit, which is used to determine the distance between the test case individuals according to the differences between the test case individuals; a parameter generation unit, which is used to generate target evaluation parameters corresponding to the test case individuals using the multi-objective fitness, distance and execution time; and an individual selection unit, which is used to select the test case individuals whose target evaluation parameters meet the preset conditions from the test case population as the target test case individuals.

[0155] In an exemplary embodiment, the heuristic processing module 704 includes: an initialization unit for randomly generating an initial test population using test code data; a first optimization unit for iteratively processing the initial test population according to the non-dominated level and crowding distance of the initial individuals in the initial test population to obtain a second-generation population; a second optimization unit for iteratively processing the second-generation population according to the non-dominated strength of the second-generation individuals in the second-generation population to obtain a third-generation population; a third optimization unit for iteratively processing the third-generation population according to the speed and position of the third-generation individuals in the third-generation population to obtain a test case population.

[0156] In an exemplary embodiment, the model inference module 710 includes: a sequence diagram generation unit, which is used to use the events corresponding to the test case set as vertices, and use the event sequence to construct edges between the vertices to obtain an event sequence diagram corresponding to the test case set; a parameter determination unit, which is used to determine model parameters using the test behavior information, event interaction information and event sequence relationship in the event sequence diagram; and a model construction unit, which is used to construct a target test model using the model parameters.

[0157] In an exemplary embodiment, the test case generation device 700 also includes: a model update module, which is used to iteratively process the event sequence and determine the prefix path that matches the current iteration state; add new vertices to the event sequence diagram through the prefix path; generate new model elements using the edges between the new vertices; and update the target test model using the model elements.

[0158] In an exemplary embodiment, the parameter determination unit is also used to determine the target vertex and target edge that meet the path restriction conditions from the event sequence diagram; and determine the model parameters using the test behavior information, event interaction information and event sequence relationship corresponding to the target vertex and target edge.

[0159] Each module in the above test case generation device can be implemented in whole or in part by software, hardware and a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module.

[0160] In an exemplary embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as shown in FIG. Figure 8As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. Among them, the processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store test code data, test case populations, heuristic search operators, multi-objective fitness, distance, execution time and other data. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a method for generating a test case is implemented.

[0161] Those skilled in the art will understand that Figure 8 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0162] In an exemplary embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above-mentioned method embodiments when executing the computer program.

[0163] In an exemplary embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.

[0164] In an exemplary embodiment, a computer program product is provided, including a computer program, and when the computer program is executed by a processor, the steps in the above method embodiments are implemented.

[0165] A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment method can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, an artificial intelligence (AI) processor, etc., but are not limited to this.

[0166] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.

[0167] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.

Claims

1. A method for generating a test case, characterized in that: The method comprises: Get test code data; Using a preset heuristic search operator to process the test code data to generate a test case population; Selecting a target test case individual from the test case population according to the multi-objective fitness of the test case individuals in the test case population, the distances between different test case individuals, and the execution time corresponding to each test case individual; Using the target test case individual as a parent to perform crossover and mutation processing to obtain a new test case population, and using the test case population and the new test case population to determine a test case set; Inferring a target test model according to the event sequence corresponding to the test case set; Generate a target test case through the target test model; The step of inferring a target test model according to the event sequence corresponding to the test case set includes: Taking the events corresponding to the test case set as vertices, and using the event sequence to construct edges between the vertices, to obtain an event sequence graph corresponding to the test case set; Determine model parameters using the test behavior information, event interaction information, and event sequence relationship in the event sequence diagram; The target test model is constructed using the model parameters.

2. The method according to claim 1, characterized in that The step of selecting a target test case individual from the test case population according to the multi-objective fitness of the test case individuals in the test case population, the distances between different test case individuals, and the execution time corresponding to each test case individual includes: Determine the multi-objective fitness of the test case individuals under the coverage objective and the scale quantity objective; Determining the distance between the individual test cases according to the differences between the individual test cases; Generate a target evaluation parameter corresponding to the test case individual using the multi-target fitness, the distance and the execution time; A test case individual whose target evaluation parameter meets a preset condition is selected from the test case population as the target test case individual.

3. The method according to claim 1, characterized in that The step of using a preset heuristic search operator to process the test code data to generate a test case population includes: Randomly generate an initial test population using the test code data; Iteratively processing the initial test population according to the non-dominated levels and crowding distances of the initial individuals in the initial test population to obtain a second generation population; According to the non-dominated strength of the second-generation individuals in the second-generation population, the second-generation population is iteratively processed to obtain a third-generation population; The third generation population is iteratively processed according to the speed and position of the third generation individuals in the third generation population to obtain the test case population.

4. The method according to claim 1, characterized in that: The method further comprises: Iteratively process the event sequence to determine a prefix path that matches the current iteration state; adding a new vertex in the event sequence graph through the prefix path; Generate a new model element by using the newly added vertex and the edge between the vertices; The target test model is updated using the model elements.

5. The method according to claim 1, characterized in that The method of determining model parameters by using the test behavior information, event interaction information, and event sequence relationship in the event sequence diagram includes: Determine the target vertex and the target edge that meet the path restriction condition from the event sequence graph; The model parameters are determined using the test behavior information, event interaction information, and event sequence relationship corresponding to the target vertex and the target edge.

6. A test case generation device, characterized in that: The device comprises: A data acquisition module, used to acquire test code data; A heuristic processing module, used to process the test code data using a preset heuristic search operator to generate a test case population; An individual selection module, configured to select a target test case individual from the test case population according to the multi-objective fitness of the test case individuals in the test case population, the distance between different test case individuals, and the execution time corresponding to each test case individual; An individual optimization module, used to use the target test case individual as a parent to perform crossover and mutation processing to obtain a new test case population, and determine a test case set using the test case population and the new test case population; A model inference module, used to infer a target test model according to the event sequence corresponding to the test case set; A use case generation module, used to generate a target test case through the target test model; Wherein, the model inference module includes: A sequence diagram generating unit, configured to use the events corresponding to the test case set as vertices, construct edges between the vertices using the event sequence, and obtain an event sequence diagram corresponding to the test case set; A parameter determination unit, used to determine model parameters by using the test behavior information, event interaction information and event sequence relationship in the event sequence diagram; A model building unit is used to build the target test model using the model parameters.

7. The device according to claim 6, characterized in that The device also includes: The model update module is used to iteratively process the event sequence to determine a prefix path that matches the current iteration state; add a new vertex to the event sequence diagram through the prefix path; generate a new model element using the edge between the new vertex and the vertex; and update the target test model using the model element.

8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 5 are implemented.

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

10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 5 are implemented.

Citation Information

Patent Citations

  • Solver performance defect detection method based on multi-target genetic algorithm

    CN113377676A