Test case generation method and device, computer equipment, readable storage medium and program product
Generating asynchronous task interface test cases through genetic algorithms solves the problems of low efficiency and poor accuracy of test case generation in the prior art, and achieves faster and more accurate test case generation.
Patent Information
- Application Number
- CN202411712618.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-27
- Publication Date
- 2024-12-27
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
In the prior art, the generation of asynchronous task interface test cases is low, time-consuming and poor accuracy, mainly because technicians need to manually write test cases.
Genetic algorithm is used to encode the request parameters, generate the initial test case population, and genetic processing is performed based on the hierarchical fitness information, and the target test case population is gradually determined, and finally the target test case is obtained through decoding.
It significantly reduces the time-consuming and cost-effectiveness of test cases, and improves the accuracy of test cases, thereby improving the efficiency of test case generation.
Smart Images

Figure CN119201755A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a test case generation method, apparatus, computer equipment, computer-readable storage medium, and computer program product. Background Art
[0002] Asynchronous task interface testing is a test of the interface between system components. The focus of asynchronous task interface testing is to check the data exchange, transmission and control management process, as well as the mutual logical dependencies between systems.
[0003] In the prior art, most technicians manually write test cases to test the interface according to the written test cases to determine the stability and availability of the interface.
[0004] However, this method of manually writing test cases is not only time-consuming and costly, but also has poor accuracy, which leads to low efficiency in test case generation. Summary of the invention
[0005] Based on this, it is necessary to provide a more efficient test case generation method, apparatus, computer device, computer-readable storage medium and computer program product to address the above technical problems.
[0006] In a first aspect, the present application provides a test case generation method, comprising:
[0007] Acquire test case information, where the test case information is used to generate a target test case, and the test case information includes request parameters and hierarchical fitness information;
[0008] The request parameter is encoded by using a genetic algorithm to obtain an initial test case population, and the initial test case population is genetically processed by using a genetic algorithm according to the hierarchical fitness information to obtain an intermediate test case population;
[0009] A target test case population is determined according to the hierarchical fitness information and the intermediate test case population, and a reverse encoding process is performed on the target test case population to obtain the target test case.
[0010] In one embodiment, the request parameters are encoded using a genetic algorithm to obtain an initial test case population, including: encoding the request parameters to obtain a chromosome sequence corresponding to the request parameters; randomly combining the chromosome sequences to generate multiple individuals, and determining the initial test case population based on the multiple individuals.
[0011] In one embodiment, the genetic algorithm is used to perform genetic processing on the initial test case population according to the graded fitness information to obtain an intermediate test case population, including: performing fitness evaluation processing on the initial test case population according to the graded fitness information to obtain a first fitness level of the initial test case population; and using a genetic algorithm to perform genetic processing on the initial test case population according to the first fitness level to obtain the intermediate test case population.
[0012] In one of the embodiments, the genetic algorithm is used to perform genetic processing on the initial test case population according to the first fitness level to obtain the intermediate test case population, including: grouping the initial test case population according to the first fitness level to obtain initial test case population groups; performing selection genetic operations, crossover genetic operations and mutation genetic operations on the initial test case population groups according to a preset mating function to obtain the intermediate test case population.
[0013] In one of the embodiments, the target test case population is determined based on the graded fitness information and the intermediate test case population, including: performing fitness evaluation processing on the intermediate test case population based on the graded fitness information to obtain a fitness evaluation result; and when the fitness evaluation result indicates that the intermediate test case population passes the fitness evaluation, determining the intermediate test case population as the target test case population.
[0014] In one of the embodiments, the method further includes: when the fitness evaluation result indicates that the intermediate test case population has not passed the fitness evaluation, obtaining a second fitness level of the intermediate test case population, and screening individuals in the intermediate test case population according to the second fitness level to obtain a screened intermediate test case population; performing genetic processing on the screened intermediate test case population using a genetic algorithm to obtain a new intermediate test case population; and determining the target test case population based on the graded fitness information and the new intermediate test case population.
[0015] In a second aspect, the present application also provides a test case generation device, comprising:
[0016] An acquisition module, used to acquire test case information, the test case information is used to generate a target test case, the test case information includes request parameters and hierarchical fitness information;
[0017] An execution module is used to encode the request parameter using a genetic algorithm to obtain an initial test case population, and to perform genetic processing on the initial test case population according to the hierarchical fitness information using a genetic algorithm to obtain an intermediate test case population;
[0018] The determination module is used to determine the target test case population according to the hierarchical fitness information and the intermediate test case population, and perform a reverse coding process on the target test case population to obtain the target test case.
[0019] In a third aspect, the present application further provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the method described in any embodiment of the first aspect when executing the computer program.
[0020] In a fourth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the method described in any embodiment of the first aspect above.
[0021] In a fifth aspect, the present application further provides a computer program product, including a computer program, which, when executed by a processor, implements the steps of the method described in any embodiment of the first aspect above.
[0022] The above-mentioned test case generation method, device, computer equipment, computer-readable storage medium and computer program product first obtain test case information, which is used to generate a target test case, and the test case information includes request parameters and hierarchical fitness information; then use a genetic algorithm to encode the request parameters to obtain an initial test case population, and use a genetic algorithm to genetically process the initial test case population according to the hierarchical fitness information to obtain an intermediate test case population; finally, determine the target test case population according to the hierarchical fitness information and the intermediate test case population, and perform inverse encoding processing on the target test case population to obtain the target test case. The test case generation method provided by the present application can generate a target test case according to the request parameters and hierarchical fitness information in the test case information. Compared with the manual writing of test cases by technicians in the prior art, it not only reduces time and cost, but also can effectively improve the accuracy of the generated test cases, thereby effectively improving the efficiency of test case generation. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] 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.
[0024] Figure 1 A schematic diagram of a flow chart of a test case generation method in an embodiment;
[0025] Figure 2 A schematic diagram of a flow chart of a method for obtaining an initial test case population in one embodiment;
[0026] Figure 3 A schematic diagram of a flow chart of a method for obtaining an intermediate test case population in one embodiment;
[0027] Figure 4 A schematic flow chart of a method for obtaining an intermediate test case population in another embodiment;
[0028] Figure 5 A schematic diagram of a flow chart of a method for determining a target test case population according to the hierarchical fitness information and the intermediate test case population in one embodiment;
[0029] Figure 6 A flowchart of a method in an embodiment when the fitness evaluation result indicates that the intermediate test case population has not passed the fitness evaluation;
[0030] Figure 7 A schematic diagram of a flow chart of a test case generation method in another embodiment;
[0031] Figure 8 A structural block diagram of a test case generating device in an embodiment;
[0032] Fig. 9 is an internal structure diagram of a computer device in one embodiment;
[0033] Fig.10 FIG. 4 is a diagram showing the internal structure of a computer device in another embodiment. DETAILED DESCRIPTION
[0034] 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.
[0035] Asynchronous task interface testing is a test of the interface between system components. The focus of asynchronous task interface testing is to check the data exchange, transmission and control management process, as well as the mutual logical dependencies between systems.
[0036] In the prior art, most technicians manually write test cases to test the interface according to the written test cases to determine the stability and availability of the interface.
[0037] However, this method of manually writing test cases is not only time-consuming and costly, but also has poor accuracy, which leads to low efficiency in test case generation.
[0038] In view of this, the present application provides a test case generation method, in which the user only needs to input the test case information to generate the required target test case for the user. This not only shortens the time and cost of test case generation, but also effectively improves the accuracy of the generated test cases, thereby effectively improving the efficiency of test case generation.
[0039] The test case generation method provided in the embodiment of the present application can be executed by a computer device, which can be a terminal or a server. The terminal can be, but is not limited to, various personal computers, laptops, tablet computers, and Internet of Things devices. The server can be an independent physical server, a server cluster or a distributed system composed of multiple physical servers, or a cloud server that provides cloud computing services.
[0040] In an exemplary embodiment, Figure 1 As shown, a test case generation method is provided, the method comprising the following steps:
[0041] Step 101: Get test case information.
[0042] The test case information is used to generate a target test case, and the test case information includes request parameters and hierarchical fitness information.
[0043] Optionally, the target test case can execute an asynchronous task interface test task. The request parameter can be used to simulate various operations of the user or system on the interface, and the request parameter can include parameter type, parameter name, parameter length and parameter dependency condition.
[0044] The hierarchical fitness information can be used to determine the test result coverage of the generated target test case. The hierarchical fitness information can include the number of test results of the target test case and the test expected results achieved by each test result. The test expected results achieved by each test result can be understood as the test results that can be output by the target test case.
[0045] In some exemplary embodiments, when a user has a need to generate a test case, a computer device may display a preset test case information form to the user, and the user fills in the test case information form according to the test requirements. After the user completes the filling, the computer device may obtain the test case information based on the test case information form filled in by the user.
[0046] Step 102: Encode the request parameters using a genetic algorithm to obtain an initial test case population, and perform genetic processing on the initial test case population according to the hierarchical fitness information using a genetic algorithm to obtain an intermediate test case population.
[0047] Alternatively, a genetic algorithm (GA) is a computational model of biological evolution that simulates Darwin's theory of biological evolution through natural selection and genetics. It is a method for searching for optimal solutions by simulating the natural evolution process. A genetic algorithm can target all individuals in a population and use randomization techniques to guide efficient searches of an encoded parameter space.
[0048] The encoding process refers to a process of converting a request parameter from a current form or format to another form. Exemplarily, the encoding process may be a binary encoding process, that is, converting the request parameter into a binary sequence. The encoding process may also be a floating point encoding process or a symbol encoding process.
[0049] A population is a well-known concept in genetic algorithms. A population is composed of individuals, individuals are composed of chromosomes, and chromosomes are composed of genes. In the present application, there is a corresponding relationship between the genes in the initial test case population and the request parameters.
[0050] In some exemplary embodiments, the request parameter may be input into a pre-trained initial test case population determination model to obtain the initial test case population output by the initial test case population determination model. The initial test case population determination model may be used to implement a genetic algorithm and has coding processing capabilities.
[0051] In other exemplary embodiments, the request parameter may be first encoded to obtain a chromosome sequence corresponding to the request parameter; the chromosome sequence may then be randomly combined to generate a plurality of individuals, and the initial test case population may be determined based on the plurality of individuals.
[0052] Furthermore, after the initial test case population is determined, a genetic algorithm may be used to perform genetic processing on the initial test case population according to the hierarchical fitness information to obtain an intermediate test case population.
[0053] As described above, the hierarchical fitness information can be used to determine the test result coverage of the generated target test cases, that is, the hierarchical fitness information can be used to evaluate the test case population. Since the gap between the test cases corresponding to the current test case population and the target test cases can be measured based on the hierarchical fitness information, the test case population can be evaluated based on the gap.
[0054] Therefore, in some exemplary embodiments, a genetic algorithm may be used to perform genetic processing on the initial test case population according to the graded fitness information to generate a new test case population, that is, the intermediate test case population. Specifically, the initial test case population may be first subjected to fitness evaluation processing according to the graded fitness information to obtain a first fitness level of the initial test case population, and then a genetic algorithm may be used to perform genetic processing on the initial test case population according to the first fitness level to obtain the intermediate test case population.
[0055] In other exemplary embodiments, the hierarchical fitness information and the initial test case population may also be input into a pre-trained intermediate test case population determination model to obtain the intermediate test case output by the intermediate test case population determination model. The intermediate test case determination model has the ability of genetic processing.
[0056] Step 103: determine a target test case population according to the hierarchical fitness information and the intermediate test case population, and perform a reverse coding process on the target test case population to obtain the target test case.
[0057] In some exemplary embodiments, after determining the intermediate test case population, the target test case population can be determined based on the graded fitness information and the intermediate test case population. Specifically, a preset rule can be determined based on the graded fitness information, and the preset rule can be used to measure whether the intermediate test case population meets the requirements of the target test case. Determine whether the intermediate test case population meets the preset rule. If so, the intermediate test case population can be determined as the target test case population, and the target test case population is decoded to obtain the target test case.
[0058] In other exemplary embodiments, after determining the intermediate test case population, the intermediate test case population may be first subjected to fitness evaluation processing according to the graded fitness information to obtain a fitness evaluation result. When the fitness evaluation result indicates that the intermediate test case population passes the fitness evaluation, the intermediate test case population is determined as the target test case population.
[0059] The above-mentioned test case generation method, device, computer equipment, computer-readable storage medium and computer program product first obtain test case information, which is used to generate a target test case, and the test case information includes request parameters and hierarchical fitness information; then use a genetic algorithm to encode the request parameters to obtain an initial test case population, and use a genetic algorithm to genetically process the initial test case population according to the hierarchical fitness information to obtain an intermediate test case population; finally, determine the target test case population according to the hierarchical fitness information and the intermediate test case population, and perform inverse encoding processing on the target test case population to obtain the target test case. The test case generation method provided by the present application can generate a target test case according to the request parameters and hierarchical fitness information in the test case information. Compared with the manual writing of test cases by technicians in the prior art, it not only reduces time and cost, but also can effectively improve the accuracy of the generated test cases, thereby effectively improving the efficiency of test case generation.
[0060] In an exemplary embodiment, Figure 2 As shown, the request parameters are encoded using a genetic algorithm to obtain an initial test case population, including the following steps:
[0061] Step 201: Encode the request parameter to obtain a chromosome sequence corresponding to the request parameter.
[0062] Optionally, the encoding process in the present application may be binary encoding of the request parameters.
[0063] In some exemplary embodiments, the request parameters in the test case information may be binary encoded to obtain a chromosome sequence corresponding to the request parameter, and the chromosome sequence may be a sequence of 0s and 1s. Specifically, a request parameter may consist of multiple parameters, and the chromosome sequence corresponding to the request parameter may be represented as , the 0-4 bits of the chromosome sequence are parameter one, the 5-10 bits are parameter two, and so on, constituting the chromosome sequence.
[0064] As described above, the request parameter includes parameter type, parameter name, and parameter length. Taking parameter 1 in the above chromosome sequence as an example, bits 0-4 of parameter 1 in the chromosome sequence can be used as the gene segment corresponding to parameter 1, the identifier of the gene segment is the parameter name of parameter 1, and the information length contained in the gene segment is determined according to the parameter type and parameter length of parameter 1.
[0065] Step 202: Randomly combine the chromosome sequences to generate multiple individuals, and determine the initial test case population based on the multiple individuals.
[0066] In some exemplary embodiments, after a chromosome sequence is generated according to the request parameters, the chromosome sequences corresponding to the request parameters may be randomly combined to generate multiple individuals, each of which may correspond to a test case.
[0067] Furthermore, after generating multiple individuals, the multiple individuals can be used as the initial test case population. Specifically, the individual can be represented as I, then , the initial test case population can be expressed as P, then .
[0068] In an exemplary embodiment, Figure 3 As shown, the genetic algorithm is used to perform genetic processing on the initial test case population according to the hierarchical fitness information to obtain an intermediate test case population, including the following steps:
[0069] Step 301: Perform fitness evaluation processing on the initial test case population according to the graded fitness information to obtain a first fitness level of the initial test case population.
[0070] In some exemplary embodiments, different fitness levels can be set according to the hierarchical fitness information to evaluate each individual in the initial test case population to determine whether it meets the corresponding test requirements. For example, the test requirement can include response types including successful response 1, successful response 2, failed response 1, and failed response 2.
[0071] Furthermore, the fitness can be determined by the parameter matching degree and the satisfaction degree of the preset constraint conditions. Specifically, the preset constraint conditions include format constraints and relationship constraints. The format preset is used to determine whether the parameter has format requirements and semantic requirements. The relationship constraint is used to determine whether the parameter has a binding relationship with other parameters and whether there are preconditions that need to be met.
[0072] The format constraint can be verified by using regular expressions for satisfaction verification. The format verification fitness parameter can be expressed as , ; The verification of the relationship constraint can be punished by deducting points according to whether the relationship constraint conditions are met. The relationship verification fitness parameter can be expressed as , , where N is the number of relations satisfied by a single parameter, T i It is the sum of all the relations that need to be satisfied for a single parameter.
[0073] Furthermore, after the fitness evaluation process is performed on the initial test case population, the fitness evaluation results of each individual in the initial test case population can be obtained, and the first fitness level of each individual in the initial test case population can be determined according to the fitness evaluation results. Specifically, taking one of the multiple individuals as an example, if the single fitness of the individual reaches the expected effect, it indicates that it has a greater probability of inheriting the corresponding response as a normal response, and the first fitness level of the individual can be determined to be excellent. If the multiple fitness of the individual reaches the expected effect, it indicates that the common parameter matching degree is good, but the gap between the fitness functions is small, and it can be used as an excellent genetic individual, and the first fitness level of the individual can be determined to be general. If the individual does not have the expected fitness, it means that the various fitnesses are very different from the expected ones, and the first fitness level of the individual can be determined to be eliminated.
[0074] Step 302: Using a genetic algorithm, perform genetic processing on the initial test case population according to the first fitness level to obtain the intermediate test case population.
[0075] Optionally, this genetic operation can be used to generate a new population.
[0076] In some exemplary embodiments, the first fitness level can be input into a pre-trained intermediate test case population determination model to obtain the intermediate test case population output by the intermediate test case population determination model, and the intermediate test case population determination model has the function of implementing genetic operations.
[0077] In other exemplary embodiments, the initial test case population may be first grouped according to the first fitness level to obtain an initial test case population grouping, and then the initial test case population grouping may be subjected to selection genetic operations, crossover genetic operations and mutation genetic operations according to a preset mating function to obtain the intermediate test case population.
[0078] In an exemplary embodiment, Figure 4 As shown, the use of a genetic algorithm to perform genetic processing on the initial test case population according to the first fitness level to obtain the intermediate test case population includes the following steps:
[0079] Step 401: group the initial test case population according to the first fitness level to obtain initial test case population groups.
[0080] Optionally, as described above, the first fitness level may include excellent, general and to-be-eliminated, and by dividing the initial test case population based on the first fitness level, an excellent population, a general population and a to-be-eliminated population may be obtained.
[0081] Furthermore, by grouping the above three populations, six groups can be obtained, and the six groups consist of excellent-general use, general use-general use, excellent-excellent, excellent-to be eliminated, general use-to be eliminated and to be eliminated-to be eliminated. The above six groups are the initial test case population groupings.
[0082] Step 402: performing selection genetic operation, crossover genetic operation and mutation genetic operation on the initial test case population group according to a preset mating function to obtain the intermediate test case population.
[0083] Optionally, the mating function may be pre-set by a technician according to actual needs.
[0084] The selection operation refers to a method of selecting excellent individuals in a group to enter a new population, the crossover operation refers to a method of generating new individuals by exchanging a certain sequence of different individuals in different groups, and the mutation operation refers to a method of generating new individuals by changing a certain gene or a certain segment of a gene of an individual in a group. Among them, the crossover operation is determined by the crossover probability, and the mutation operation is determined by the mutation probability. The mutation probability in the to-be-eliminated group in the initial test case population grouping should be appropriately higher than that in other groups.
[0085] In some exemplary embodiments, selection genetic operation, crossover genetic operation and mutation genetic operation may be performed on each group in the initial test case population grouping according to a preset mating function to obtain the intermediate test case population.
[0086] In an exemplary embodiment, Figure 5 As shown, determining the target test case population according to the hierarchical fitness information and the intermediate test case population includes the following steps:
[0087] Step 501: Perform fitness evaluation processing on the intermediate test case population according to the graded fitness information to obtain a fitness evaluation result.
[0088] Step 502: When the fitness evaluation result indicates that the intermediate test case population has passed the fitness evaluation, the intermediate test case population is determined as the target test case population.
[0089] In some exemplary embodiments, after the intermediate test case population is determined, a fitness evaluation process may be performed on the intermediate test case population based on the graded fitness information to obtain a fitness evaluation result.
[0090] Furthermore, if it is determined that the fitness evaluation result indicates that the intermediate test case population satisfies the expected test results achieved by each test result, that is, it contains all test results that can be output by the target test case, then it can be determined that the intermediate test case population has passed the fitness evaluation, and the intermediate test case population can be determined as the target test case population.
[0091] Further, as described above, after determining the target test case population, the target test case population can be decoded to obtain the target test case. Specifically, the target test case population can be classified according to the fitness response type satisfied by the target test case population, and multiple populations with higher fitness can be selected from each type as the test case result, and then decoded to convert the gene sequence into an information field, and output it in the required format, that is, the target test case.
[0092] In an optional embodiment of the present application, after generating a target test case, the user can also determine whether to perform interface simulation testing based on the target test case according to actual needs, and verify whether the target test case meets the corresponding response result by outputting the simulated test result of the target test case.
[0093] In an exemplary embodiment, Figure 6 As shown, when the fitness evaluation result indicates that the intermediate test case population has not passed the fitness evaluation, the method further includes the following steps:
[0094] Step 601: Obtain a second fitness level of the intermediate test case population, and screen individuals in the intermediate test case population according to the second fitness level to obtain a screened intermediate test case population.
[0095] In some exemplary embodiments, when the fitness evaluation result indicates that the intermediate test case population has not passed the fitness evaluation, the second fitness level of the intermediate test case population can be first determined based on the graded fitness information, and individuals with higher fitness in the intermediate test case population are retained, while individuals with lower fitness are eliminated to obtain a screened intermediate test case population.
[0096] Step 602: Use a genetic algorithm to perform genetic processing on the intermediate test case population after the screening process to obtain a new intermediate test case population.
[0097] In some exemplary embodiments, after determining the intermediate test case population after screening processing, a genetic algorithm can be used to perform genetic processing on the intermediate test case population after screening processing, that is, to select genetic operations, crossover genetic operations and mutation genetic operations to obtain a new intermediate test case population again.
[0098] Step 603: Determine the target test case population according to the hierarchical fitness information and the new intermediate test case population.
[0099] In some exemplary embodiments, after determining the new intermediate test case population, the new intermediate test case population may be subjected to fitness evaluation processing according to the graded fitness information to obtain a corresponding new fitness evaluation result;
[0100] Further, when the new fitness evaluation result indicates that the new intermediate test case population passes the fitness evaluation, the new intermediate test case population is determined as the target test case population.
[0101] If it fails, the above-mentioned screening process, genetic process and fitness evaluation process will continue to be executed until the fitness evaluation passes.
[0102] In an exemplary embodiment, Figure 7 As shown, another test case generation method is provided, the method comprising the following steps:
[0103] Step 701: Acquire test case information, which is used to generate a target test case, and includes request parameters and hierarchical fitness information; encode the request parameters to obtain a chromosome sequence corresponding to the request parameters; randomly combine the chromosome sequences to generate a plurality of individuals, and determine the initial test case population based on the plurality of individuals;
[0104] Step 702: Perform fitness evaluation processing on the initial test case population according to the graded fitness information to obtain a first fitness level of the initial test case population; perform grouping processing on the initial test case population according to the first fitness level to obtain an initial test case population group; perform selection genetic operation, crossover genetic operation and mutation genetic operation on the initial test case population group according to a preset mating function to obtain the intermediate test case population;
[0105] Step 703: Perform fitness evaluation processing on the intermediate test case population according to the graded fitness information to obtain a fitness evaluation result; if the fitness evaluation result indicates that the intermediate test case population passes the fitness evaluation, determine the intermediate test case population as the target test case population; perform decoding processing on the target test case population to obtain the target test case;
[0106] Step 704: When the fitness evaluation result indicates that the intermediate test case population has not passed the fitness evaluation, obtain a second fitness level of the intermediate test case population, and screen the individuals in the intermediate test case population according to the second fitness level to obtain a screened intermediate test case population; perform genetic processing on the screened intermediate test case population using a genetic algorithm to obtain a new intermediate test case population; and determine the target test case population based on the graded fitness information and the new intermediate test case population.
[0107] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can 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.
[0108] 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 one or more test case generation device embodiments provided below can refer to the limitations of the test case generation method above, and will not be repeated here.
[0109] In an exemplary embodiment, Figure 8 As shown, a test case generating device 800 is provided, comprising: an acquisition module 801, an execution module 802 and a determination module 803, wherein:
[0110] An acquisition module 801 is used to acquire test case information, where the test case information is used to generate a target test case, and the test case information includes request parameters and hierarchical fitness information;
[0111] An execution module 802 is used to encode the request parameter using a genetic algorithm to obtain an initial test case population, and to perform genetic processing on the initial test case population according to the hierarchical fitness information using a genetic algorithm to obtain an intermediate test case population;
[0112] The determination module 803 is used to determine the target test case population according to the hierarchical fitness information and the intermediate test case population, and perform a reverse coding process on the target test case population to obtain the target test case.
[0113] In one embodiment, the execution module 802 is specifically used to encode the request parameter to obtain a chromosome sequence corresponding to the request parameter; randomly combine the chromosome sequence to generate multiple individuals, and determine the initial test case population based on the multiple individuals.
[0114] In one embodiment, the execution module 802 is specifically used to perform fitness evaluation processing on the initial test case population according to the graded fitness information to obtain a first fitness level of the initial test case population; and use a genetic algorithm to perform genetic processing on the initial test case population according to the first fitness level to obtain the intermediate test case population.
[0115] In one embodiment, the execution module 802 is specifically used to group the initial test case population according to the first fitness level to obtain an initial test case population grouping; and perform selection genetic operations, crossover genetic operations and mutation genetic operations on the initial test case population grouping according to a preset mating function to obtain the intermediate test case population.
[0116] In one embodiment, the determination module 803 is specifically used to perform fitness evaluation processing on the intermediate test case population according to the graded fitness information to obtain a fitness evaluation result; when the fitness evaluation result indicates that the intermediate test case population passes the fitness evaluation, the intermediate test case population is determined as the target test case population.
[0117] In one embodiment, the determination module 803 is also used to obtain a second fitness level of the intermediate test case population when the fitness evaluation result indicates that the intermediate test case population has not passed the fitness evaluation, and screen the individuals in the intermediate test case population according to the second fitness level to obtain a screened intermediate test case population; perform genetic processing on the screened intermediate test case population using a genetic algorithm to obtain a new intermediate test case population; and determine the target test case population based on the graded fitness information and the new intermediate test case population.
[0118] Each module in the above test case generation device can be implemented in whole or in part by software, hardware, or 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.
[0119] 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. Fig. 9 As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. 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. 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 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 test case generation method is implemented.
[0120] In an exemplary embodiment, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as shown in FIG. Fig.10 As shown. The computer device includes a processor, a memory, an input / output interface, a communication interface, a display unit and an input device. The processor, the memory and the input / output interface are connected through a system bus, and the communication interface, the display unit and the input device are connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The 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 in a wired or wireless manner, and the wireless manner can be implemented through WIFI, a mobile cellular network, near field communication (NFC) or other technologies. When the computer program is executed by the processor, a test case generation method is implemented. The display unit of the computer device is used to form a visually visible picture, which can be a display screen, a projection device or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covering the display screen, or a button, trackball or touchpad set on the computer device shell, or an external keyboard, touchpad or mouse.
[0121] Those skilled in the art will understand that Fig. 9 and Fig.10 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.
[0122] 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 when the processor executes the computer program, the following steps are implemented:
[0123] Acquire test case information, where the test case information is used to generate a target test case, and the test case information includes request parameters and hierarchical fitness information;
[0124] The request parameter is encoded by using a genetic algorithm to obtain an initial test case population, and the initial test case population is genetically processed by using a genetic algorithm according to the hierarchical fitness information to obtain an intermediate test case population;
[0125] A target test case population is determined according to the hierarchical fitness information and the intermediate test case population, and a reverse encoding process is performed on the target test case population to obtain the target test case.
[0126] In one embodiment, when the processor executes the computer program, the following steps are also implemented: encoding the request parameter to obtain a chromosome sequence corresponding to the request parameter; randomly combining the chromosome sequence to generate multiple individuals, and determining the initial test case population based on the multiple individuals.
[0127] In one embodiment, when the processor executes the computer program, the following steps are also implemented: performing fitness evaluation processing on the initial test case population according to the graded fitness information to obtain a first fitness level of the initial test case population; using a genetic algorithm, performing genetic processing on the initial test case population according to the first fitness level to obtain the intermediate test case population.
[0128] In one embodiment, the processor further implements the following steps when executing the computer program: grouping the initial test case population according to the first fitness level to obtain an initial test case population grouping; performing selection genetic operations, crossover genetic operations and mutation genetic operations on the initial test case population grouping according to a preset mating function to obtain the intermediate test case population.
[0129] In one embodiment, when the processor executes the computer program, the following steps are also implemented: performing fitness evaluation processing on the intermediate test case population according to the graded fitness information to obtain a fitness evaluation result; when the fitness evaluation result indicates that the intermediate test case population passes the fitness evaluation, determining the intermediate test case population as the target test case population.
[0130] In one embodiment, the processor further implements the following steps when executing the computer program: when the fitness evaluation result indicates that the intermediate test case population has not passed the fitness evaluation, obtaining a second fitness level of the intermediate test case population, and screening individuals in the intermediate test case population according to the second fitness level to obtain a screened intermediate test case population; performing genetic processing on the screened intermediate test case population using a genetic algorithm to obtain a new intermediate test case population; and determining the target test case population based on the graded fitness information and the new intermediate test case population.
[0131] In one embodiment, a computer readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:
[0132] Acquire test case information, where the test case information is used to generate a target test case, and the test case information includes request parameters and hierarchical fitness information;
[0133] The request parameter is encoded by using a genetic algorithm to obtain an initial test case population, and the initial test case population is genetically processed by using a genetic algorithm according to the hierarchical fitness information to obtain an intermediate test case population;
[0134] A target test case population is determined according to the hierarchical fitness information and the intermediate test case population, and a reverse encoding process is performed on the target test case population to obtain the target test case.
[0135] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented: encoding the request parameter to obtain a chromosome sequence corresponding to the request parameter; randomly combining the chromosome sequence to generate multiple individuals, and determining the initial test case population based on the multiple individuals.
[0136] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: performing fitness evaluation processing on the initial test case population according to the graded fitness information to obtain a first fitness level of the initial test case population; using a genetic algorithm, performing genetic processing on the initial test case population according to the first fitness level to obtain the intermediate test case population.
[0137] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: grouping the initial test case population according to the first fitness level to obtain an initial test case population grouping; performing selection genetic operations, crossover genetic operations and mutation genetic operations on the initial test case population grouping according to a preset mating function to obtain the intermediate test case population.
[0138] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: performing fitness evaluation processing on the intermediate test case population according to the graded fitness information to obtain a fitness evaluation result; when the fitness evaluation result indicates that the intermediate test case population passes the fitness evaluation, determining the intermediate test case population as the target test case population.
[0139] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: when the fitness evaluation result indicates that the intermediate test case population has not passed the fitness evaluation, a second fitness level of the intermediate test case population is obtained, and individuals in the intermediate test case population are screened according to the second fitness level to obtain a screened intermediate test case population; genetic processing is performed on the screened intermediate test case population using a genetic algorithm to obtain a new intermediate test case population; and the target test case population is determined according to the graded fitness information and the new intermediate test case population.
[0140] In one embodiment, a computer program product is provided, comprising a computer program, which, when executed by a processor, implements the following steps:
[0141] Acquire test case information, where the test case information is used to generate a target test case, and the test case information includes request parameters and hierarchical fitness information;
[0142] The request parameter is encoded by using a genetic algorithm to obtain an initial test case population, and the initial test case population is genetically processed by using a genetic algorithm according to the hierarchical fitness information to obtain an intermediate test case population;
[0143] A target test case population is determined according to the hierarchical fitness information and the intermediate test case population, and a reverse encoding process is performed on the target test case population to obtain the target test case.
[0144] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented: encoding the request parameter to obtain a chromosome sequence corresponding to the request parameter; randomly combining the chromosome sequence to generate multiple individuals, and determining the initial test case population based on the multiple individuals.
[0145] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: performing fitness evaluation processing on the initial test case population according to the graded fitness information to obtain a first fitness level of the initial test case population; using a genetic algorithm, performing genetic processing on the initial test case population according to the first fitness level to obtain the intermediate test case population.
[0146] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: grouping the initial test case population according to the first fitness level to obtain an initial test case population grouping; performing selection genetic operations, crossover genetic operations and mutation genetic operations on the initial test case population grouping according to a preset mating function to obtain the intermediate test case population.
[0147] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: performing fitness evaluation processing on the intermediate test case population according to the graded fitness information to obtain a fitness evaluation result; when the fitness evaluation result indicates that the intermediate test case population passes the fitness evaluation, determining the intermediate test case population as the target test case population.
[0148] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: when the fitness evaluation result indicates that the intermediate test case population has not passed the fitness evaluation, a second fitness level of the intermediate test case population is obtained, and individuals in the intermediate test case population are screened according to the second fitness level to obtain a screened intermediate test case population; genetic processing is performed on the screened intermediate test case population using a genetic algorithm to obtain a new intermediate test case population; and the target test case population is determined according to the graded fitness information and the new intermediate test case population.
[0149] 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.
[0150] 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.
[0151] 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 test case generation method, characterized in that: The method comprises: Acquire test case information, where the test case information is used to generate a target test case, and the test case information includes request parameters and hierarchical fitness information; Using a genetic algorithm to encode the request parameters to obtain an initial test case population, and using a genetic algorithm to genetically process the initial test case population according to the hierarchical fitness information to obtain an intermediate test case population; A target test case population is determined according to the hierarchical fitness information and the intermediate test case population, and a reverse encoding process is performed on the target test case population to obtain the target test case.
2. The method according to claim 1, characterized in that The step of encoding the request parameters using a genetic algorithm to obtain an initial test case population includes: Encoding the request parameters to obtain a chromosome sequence corresponding to the request parameters; The chromosome sequences are randomly combined to generate a plurality of individuals, and the initial test case population is determined based on the plurality of individuals.
3. The method according to claim 1, characterized in that: The using of a genetic algorithm to perform genetic processing on the initial test case population according to the hierarchical fitness information to obtain an intermediate test case population includes: Performing fitness evaluation processing on the initial test case population according to the graded fitness information to obtain a first fitness level of the initial test case population; The initial test case population is genetically processed by using a genetic algorithm according to the first fitness level to obtain the intermediate test case population.
4. The method according to claim 3, characterized in that The step of using a genetic algorithm to perform genetic processing on the initial test case population according to the first fitness level to obtain the intermediate test case population includes: Grouping the initial test case population according to the first fitness level to obtain an initial test case population grouping; The initial test case population is grouped according to a preset mating function to perform selection genetic operation, crossover genetic operation and mutation genetic operation to obtain the intermediate test case population.
5. The method according to claim 1, characterized in that The step of determining a target test case population according to the hierarchical fitness information and the intermediate test case population includes: Performing fitness evaluation processing on the intermediate test case population according to the hierarchical fitness information to obtain a fitness evaluation result; In a case where the fitness evaluation result indicates that the intermediate test case population passes the fitness evaluation, the intermediate test case population is determined as the target test case population.
6. The method according to claim 5, characterized in that The method further comprises: When the fitness evaluation result indicates that the intermediate test case population has not passed the fitness evaluation, obtaining a second fitness level of the intermediate test case population, and screening individuals in the intermediate test case population according to the second fitness level to obtain a screened intermediate test case population; Using a genetic algorithm to perform genetic processing on the intermediate test case population after the screening process to obtain a new intermediate test case population; The target test case population is determined according to the hierarchical fitness information and the new intermediate test case population.
7. A test case generating device, characterized in that: The device comprises: An acquisition module, used to acquire test case information, wherein the test case information is used to generate a target test case, and the test case information includes request parameters and hierarchical fitness information; An execution module, configured to encode the request parameters using a genetic algorithm to obtain an initial test case population, and to perform genetic processing on the initial test case population according to the hierarchical fitness information using a genetic algorithm to obtain an intermediate test case population; A determination module is used to determine a target test case population according to the hierarchical fitness information and the intermediate test case population, and to perform a reverse coding process on the target test case population to obtain the target test case.
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 6 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 6 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 6 are implemented.
Citation Information
Patent Citations
Test case optimization method based on genetic algorithm
CN103605611A
Test case obtaining method, system and device and computer readable storage medium
CN112579462A
Test case generation method, system and equipment based on genetic algorithm and medium
CN114185800A
Test case generation method and device and computer storage medium
CN116302905A
Test case processing method and system and storage medium
CN116737597A
Cited By
Method and system for generating autonomous accompanying test case
CN120045453A