Test case generation method, device and equipment and computer readable storage medium
Patent Information
- Application Number
- CN202310883068.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-18
- Publication Date
- 2026-08-21
- Estimated Expiration
- 2043-07-18
AI Technical Summary
这样,不仅会消耗大量的人力、物力,极大的增加了软件代码的测试成本;并且,测试的可靠性因人而异,从而导致测试的准确率也自然得不到保障
[0013]本申请提出的测试用例生成方法、装置、设备和计算机可读存储介质,首先,确定目标需求结构中的判断节点以及判断节点所属的结构类型;其中,目标需求结构中包含多个节点以及节点之间的逻辑执行关系;多个节点中包含判断节点;结构类型包括循环结构和非循环结构。之后,根据判断节点的输出结果以及判断节点所属的结构类型,生成第1代测试用例种群;其中,第1代测试用例种群中包括至少一个初始测试用例,初始测试用例中包括每一判断节点对应的配置结果;最后,基于第1代测试用例种群和遗传算法,确定最终测试用例集群。相比人工编写测试用例的方式,可以降低测试用例的生成时间,提升测试用例的生成效率,减少人力物力的消耗,降低软件测试耗时;并且,基于遗传算法得到的最终测试用例种群,能够有效解决测试用例新增困难、开发方向不清晰、测试用例设计不全面引起的漏测问题,保障软件质量。
Smart Images

Figure CN116932394B_ABST
Abstract
Description
Technical Field
[0001] This application generally relates to the field of testing technology, and more particularly to a test case generation method, apparatus, device, and computer-readable storage medium. Background Technology
[0002] As the core of satellite platform management, satellite administration software primarily provides software support for the stable operation of the satellite platform. Due to the massive amount of code in satellite administration software, the workload of software development and testing also increases with the increasing number of satellite functions.
[0003] In existing technologies, test cases for testing software code are typically written manually. This not only consumes a significant amount of manpower and resources, greatly increasing the cost of testing software code, but also results in inconsistent reliability due to varying individual testers, thus compromising the accuracy of the tests. Summary of the Invention
[0004] In view of the above-mentioned defects or deficiencies in the prior art, it is desirable to provide a test case generation method, apparatus, device and computer-readable storage medium that can automatically generate test cases.
[0005] Firstly, this application provides a test case generation method, which includes: determining the judgment nodes in the target requirement structure and the structure type to which the judgment nodes belong; the target requirement structure contains multiple nodes and the logical execution relationship between the nodes; the multiple nodes include judgment nodes; the structure type includes a loop structure and an acyclic structure; generating a first-generation test case population based on the output results of the judgment nodes and the structure type to which the judgment nodes belong, the first-generation test case population including at least one initial test case, the initial test case including the configuration result corresponding to each judgment node; and determining the final test case cluster based on the first-generation test case population and a genetic algorithm.
[0006] Secondly, this application provides a test case generation apparatus, which includes:
[0007] The acquisition module is used to determine the decision nodes in the target requirement structure and the structure type to which the decision nodes belong; the target requirement structure contains multiple nodes and the logical execution relationship between the nodes; multiple nodes include decision nodes; the structure type includes loop structure and non-loop structure.
[0008] The processing module is used to generate a first-generation test case population based on the output results of the judgment nodes and the structure type to which the judgment nodes belong. The first-generation test case population includes at least one initial test case, and the initial test case includes the configuration result corresponding to each judgment node.
[0009] The determination module is used to determine the final test case cluster based on the first-generation test case population and the genetic algorithm.
[0010] Thirdly, embodiments of this application provide a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the method described in embodiments of this application.
[0011] Fourthly, embodiments of this application provide a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method described in embodiments of this application.
[0012] Fifthly, embodiments of this application provide a computer program product including instructions that, when executed, cause the method described in embodiments of this application to be performed.
[0013] The test case generation method, apparatus, device, and computer-readable storage medium proposed in this application first determine the decision nodes in the target requirement structure and the structure type to which the decision nodes belong. The target requirement structure contains multiple nodes and logical execution relationships between them; each node includes a decision node; the structure type includes loop structures and non-loop structures. Next, based on the output results of the decision nodes and the structure type to which the decision nodes belong, a first-generation test case population is generated. This first-generation test case population includes at least one initial test case, which includes the configuration result corresponding to each decision node. Finally, based on the first-generation test case population and a genetic algorithm, a final test case cluster is determined. Compared to manually writing test cases, this method reduces test case generation time, improves test case generation efficiency, reduces manpower and material resources, and lowers software testing time. Furthermore, the final test case population obtained based on the genetic algorithm effectively solves the problems of missed tests caused by difficulties in adding new test cases, unclear development directions, and incomplete test case design, thus ensuring software quality.
[0014] Additional aspects and advantages of this application will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of this application. Attached Figure Description
[0015] Other features, objects, and advantages of this application will become more apparent from the following detailed description of non-limiting embodiments with reference to the accompanying drawings:
[0016] Figure 1 A flowchart illustrating a test case generation method provided in an embodiment of this application;
[0017] Figure 2A schematic diagram of a target requirement structure provided in an embodiment of this application;
[0018] Figure 3 This is a schematic diagram of another target requirement structure provided in an embodiment of this application;
[0019] Figure 4 A flowchart illustrating another test case generation method provided in this application embodiment;
[0020] Figure 5 A flowchart illustrating another test case generation method provided in this application embodiment;
[0021] Figure 6 A flowchart illustrating another test case generation method provided in this application embodiment;
[0022] Figure 7 This is a schematic diagram of the structure of a test case generation device provided in an embodiment of this application;
[0023] Figure 8 This is a schematic diagram of the structure of a computer device provided in an embodiment of this application. Detailed Implementation
[0024] The present application will now be described in further detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and not intended to limit it. Furthermore, it should be noted that, for ease of description, only the parts relevant to the invention are shown in the accompanying drawings.
[0025] It should be noted that, unless otherwise specified, the embodiments and features described in this application can be combined with each other. This application will now be described in detail with reference to the accompanying drawings and embodiments.
[0026] This application discloses a test case generation method to meet the structured requirements and structural coverage requirements for different software functional requirements. This application focuses on software functional requirements design specifications. First, the requirements specifications input from the front end are constructed into a structured flowchart specification (i.e., the target requirement structure). Then, based on the method of this application, test cases are automatically generated, which can be directly used to guide testers in manual testing or automated test script development. The construction of the front-end structured flowchart requirement specification is not within the scope of this description; it only needs to conform to the general standardized flowchart structure required by this application, and may include sequential, branching, looping structures and their derived structures.
[0027] The technical solution of this application and how the technical solution of this application solves the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments.
[0028] like Figure 1 As shown in the figure, this application provides a test case generation method, which specifically includes the following steps:
[0029] 101. Determine the decision nodes in the target requirement structure and the structure type to which the decision nodes belong; the target requirement structure contains multiple nodes and the logical execution relationship between the nodes; multiple nodes include decision nodes; the structure type includes loop structure and non-loop structure.
[0030] The target requirement structure is a flowchart structure generated based on actual requirements. This flowchart structure contains multiple nodes, and there are logical execution relationships between the nodes.
[0031] A decision node is a node in the target requirement structure that performs corresponding judgments on variables based on judgment conditions, and whose judgment result can be controlled by external instructions. Generally, the judgment result of a decision node includes two types: true (1) and false (0).
[0032] Specifically, the decision nodes are configured with conditional expressions, which are used to control the flow of the process during the execution of the flowchart structure based on the configured conditional expressions.
[0033] In one possible application scenario, refer to Figure 2 The diagram illustrates a flow chart of the thermal control loop, showing the demand structure (i.e., the target demand structure) for the thermal control loop, which includes the following nodes:
[0034] Node 201: YS4000 == 1, indicating that the enabled / disabled flag YS4000 of the received thermal control loop is determined by node 201 to be an enabled flag (i.e., 1); if yes, then execute node 202; if no, then end.
[0035] Node 202: YS4300>32 indicates that the temperature acquisition value TK of the thermistor in the thermal control circuit received by node 202 is determined to be greater than 32; if yes, then node 203 is executed; if no, then node 208 is executed.
[0036] Node 203: Send command: B1AAFFFF; Wait: 5000; Assign value: IGCNT = HIGHCNT + 1; This means that the B1AAFFFF (high level) command is sent to the thermal control switch of the thermal control loop corresponding to the thermal point group through node 203 to control the thermal control switch in the thermal control loop to disconnect. After waiting for 5000ms, the value of IGCNT is assigned to the value of HIGHCNT plus 1, which is the number of times the thermal control resistor is sampled at high level.
[0037] Node 204: SW1 == 0, indicating that the level acquisition value of the thermal control switch is determined by node 204; if yes, then node 205 is executed; if no, then node 206 is executed.
[0038] Node 205: Assignment: HIGHCNT = 0; This means that the number of times the high level of the thermal control resistor is sampled through node 205 is assigned the value HIGHCNT as 0.
[0039] Node 206: HIGHCNT > 3; This means that the number of times the thermal control switch's level acquisition value is high is counted through node 205. The count is then performed on HIGHCNT, and it is determined whether the value is greater than 3. If yes, then node 207 is executed; otherwise, node 203 is returned.
[0040] Node 207: Assignment: YS4200 = 0; Assignment: YS4000 = 0; Assignment: HIGHCNT = 0; This means that the health flag YS4200 of the thermal control circuit is assigned the value corresponding to the unhealthy flag (i.e., 0) through node 207, the enable / disable flag YS4000 of the thermal control circuit is assigned the value of the disabled flag (i.e., 0), and the number of high-level samplings of the thermal control resistor HIGHCNT is assigned the value of 0.
[0041] Node 208: YS4300<12; This means that the temperature acquisition value TK of the thermistor in the thermal control circuit received by node 202 is determined to be less than 12; if yes, then node 209 is executed; if no, then the process ends.
[0042] Node 209: Send command: B1AA0000; Wait: 5000; Assign value: OWCNT = LOWCNT + 1; This means that the B1AA0000 command is sent to the thermal control switch of the thermal control loop corresponding to the thermal point group through node 209 to control the thermal control switch in the thermal control loop to be turned off, and after waiting for 5000ms, the value of OWCNT is assigned to the value of LOWCNT plus 1.
[0043] Node 210: SW1 == 1, indicating that the level acquisition value of the thermal control switch is high level 1 is determined by node 210; if yes, then node 211 is executed; if no, then node 212 is executed.
[0044] Node 211: Assignment: LOWCNT = 0; This means that the number of times the low level of the thermal control resistor is sampled through node 211 is set to 0.
[0045] Node 212: LOWCNT > 3; This means that the number of times the thermal control switch's level acquisition value is low is counted through node 212. The count is then determined to be greater than 3. If yes, then node 213 is executed; otherwise, node 209 is returned.
[0046] Node 213: Assignment: YS4200 = 0; Assignment: YS4000 = 0; Assignment: LOWCNT = 0; This means that the health flag YS4200 of the thermal control circuit is assigned the value corresponding to the unhealthy flag (i.e., 0) through node 213, the enable / disable flag YS4000 of the thermal control circuit is assigned the value of the disabled flag (i.e., 0), and the number of low-level samplings of the thermal control resistor HIGHCNT is assigned the value of 0.
[0047] Among them, nodes 201, 202, 204, 208, 210, 206, and 212 are nodes with decision-making functions in the target requirement structure. Since nodes 206 and 212 are internally executing decisions, their flow cannot be controlled by external instructions; therefore, Figure 2 The decision nodes are nodes 201, 202, 204, 208, and 210.
[0048] In addition, if the judgment result of nodes 204 and 210 is negative, the judgment may be re-executed. Therefore, the structure type corresponding to nodes 204 and 210 is a circular structure. After execution, nodes 201, 202 and 208 do not return to their respective nodes to re-execute the judgment. Therefore, the structure type corresponding to nodes 201, 202 and 208 is a non-circular structure.
[0049] Reference Figure 3 This is a flowchart illustrating the thermistor selection process in a thermal control circuit. Typically, a thermal control circuit includes two thermistors: TH1 and TH2. Figure 3 Three nodes are shown:
[0050] Node 301: YS4100 == 1, indicating that node 301 determines whether the thermistor usage flag of the received thermal control circuit is 1. If yes, then node 302 is executed; otherwise, node 303 is executed. Here, 1 indicates the use of thermistor TH1, and 0 indicates the use of thermistor TH2.
[0051] Node 302: Assignment: YS4300 = TK1, which means that the temperature acquisition value YS4300 of the thermistor in the thermal control loop is assigned the value TK1 through node 301.
[0052] Node 303: Assignment: YS4300 = TK2, which means that the temperature acquisition value YS4300 of the thermistor in the thermal control loop is assigned the value TK2 through node 301.
[0053] In this context, the 301 node is a decision node. Furthermore, it is not executed again after it has been executed. Therefore, the structure type corresponding to the 301 node is a non-cyclic structure.
[0054] Specifically, Table 1 provides an explanation of the relevant parameters of the thermal control loop logic model:
[0055] Table 1
[0056]
[0057] Table 2 provides a description of the relevant instructions in the thermal control loop's requirement structure:
[0058] Table 2
[0059]
[0060]
[0061] Based on the above analysis, combined with Figure 2 The automatic temperature control logic of the thermal control loop is as follows:
[0062] 1) If the thermal control auto-control is enabled, compare the temperature data collected by the thermistor with the upper and lower threshold values. If the temperature exceeds the threshold, proceed to step 2).
[0063] Each thermal control circuit contains two thermistors, namely the TH1 thermistor and the TH2 thermistor. These two thermistors are changed according to specific instructions. If TH1 is used, the thermal control circuit uses the thermistor specified by TH1 to control the temperature.
[0064] 2) If n consecutive frames exceed the upper limit (i.e., the result of the thermal control switch's level acquisition value being low level 0 is no) and the thermal control switch is in the on state, then it is confirmed that the threshold has been exceeded, and proceed to step 3. If the above conditions are not met, return to step 1).
[0065] 3) The thermal control switch is disconnected, causing the switch to disconnect and proceeding to step 4).
[0066] 4) Wait for m cycles and check if the switch state is open. If the switch state is open for k consecutive frames, the transmission is successful. Return to step 1. If the above conditions are not met, go to step 3 and resend the command. If the command count operation is h times (i.e., HIGHCNT > 3) and the switch is not open, go to step 5.
[0067] 5) Set the health flag of the thermal control circuit to unhealthy (i.e., YS4200 = 0), and assign the enable / disable flag YS4000 of the thermal control circuit to the disabled flag, i.e., set the thermal control circuit to automatic control disabled (i.e., YS4000 = 0).
[0068] 102. Based on the output results of the judgment nodes and the structure type to which the judgment nodes belong, generate a first-generation test case population. The first-generation test case population includes at least one initial test case, and the initial test case includes the configuration result corresponding to each judgment node.
[0069] In some implementations, pre-selected test cases are generated based on the output of the judgment node and its structural type, combined with the target requirement structure and a preset test case generation function. After generating the pre-selected test cases, they can be filtered according to a preset method. Based on the filtered pre-selected test cases, a first-generation test case population is obtained, which constitutes the initial test cases in the first-generation test case population. The filtering method can be flexibly set according to actual needs; in one example, the filtering method can be random filtering.
[0070] The preset test case generation function can be flexibly configured according to actual needs. In one example, the preset test case generation function can be generated in the following way: obtain test cases of different types as a sample set, train the function based on machine learning and the sample set, and then obtain the test case generation function.
[0071] 103. Based on the first-generation test case population and genetic algorithm, determine the final test case cluster.
[0072] It should be understood that a Genetic Algorithm (GA) is an algorithm that searches for the optimal solution by simulating the natural evolutionary process using computers. Genetic Algorithms were initially developed based on Darwin's theory of natural selection and Mendel's genetic compilation theory. They start with a population of a certain size (composed of random individuals with specific characteristics), select individuals that meet certain criteria according to a strategy (fitness), and then generate a new population through selection, crossover, and mutation operations. After several iterations, the population approximates the optimal solution.
[0073] The test case generation method proposed in this application first determines the decision nodes in the target requirement structure and the structure type to which the decision nodes belong. The target requirement structure includes multiple nodes and logical execution relationships between them; each node includes a decision node; and the structure type includes loop structures and non-loop structures. Then, based on the output results of the decision nodes and the structure type to which the decision nodes belong, a first-generation test case population is generated. This first-generation test case population includes at least one initial test case, which includes the configuration result corresponding to each decision node. Finally, based on the first-generation test case population and a genetic algorithm, a final test case cluster is determined. Compared to manually writing test cases, this method reduces test case generation time, improves test case generation efficiency, reduces manpower and material resources, and lowers software testing time. Furthermore, the final test case population obtained based on the genetic algorithm effectively solves the problems of missed tests caused by difficulties in adding new test cases, unclear development directions, and incomplete test case design, thus ensuring software quality.
[0074] In one possible implementation, refer to Figure 4 The system determines whether a node contains a first-type node and / or a second-type node, where the first-type node belongs to a cyclic structure and the second-type node belongs to a non-cyclic structure. Based on the output of the determined node and its structural type, a first-generation test case population is generated, including:
[0075] 401. Based on the number of iterations of the first type of node, determine the number of element configurations corresponding to the first type of node.
[0076] Optionally, the number of elements configured for the first type of node is greater than or equal to the sum of the maximum number of loops for the first type of node and the number of other branches.
[0077] For example, Figure 2 During the execution of node 204, if its judgment result is yes, a configuration value is required. If the judgment result is no, and the process is to execute node 207 after node 206, the discriminant in node 206 requires the thermal control switch's level acquisition value to be low for a number of times LOWCNT > 3. This means that the maximum number of loops for node 204 is 4, therefore at least 4 configuration values are required. Based on this, the minimum number of element configurations for node 204 is 5.
[0078] 402. The number of elements configured for the first type of node, the judgment result of the first type of node and / or the judgment result of the second type of node are used to generate initial test cases to obtain the first generation of test case population.
[0079] In some embodiments, generating initial test cases based on the number of elements configured for the first type of node, the judgment result of the first type of node, and / or the judgment result of the second type of node includes: for each initial test case, randomly selecting one of the judgment results of the first type of node as the configuration value of the first type of node according to the number of elements corresponding to the first type of node, to obtain the configuration result of the first type of node, and / or randomly selecting one of the judgment results of the second type of node as the configuration result of the second type of node; and generating initial test cases based on the configuration result of the first type of node and / or the configuration result of the second type of node.
[0080] In one possible implementation, refer to Figure 5 Based on the first-generation test case population and genetic algorithm, the final test case cluster is determined, including:
[0081] 501. Determine at least one target test case based on the nth generation test case population, where the initial value of n is 1 and n is a positive integer.
[0082] It is understandable that at least one target test case corresponding to the nth generation test case population is actually the optimal test case in the nth generation test case population. The optimal test case can be...
[0083] 502. Based on the coverage of nodes in the target requirement structure by at least one target test case in each generation of the test case population of the first n generations, generate the (n+1)th generation test case population, which contains at least one initial test case.
[0084] In one implementation, in the target requirement structure, nodes covered by the target test cases corresponding to each generation of test case population in the first n generations of test case population are excluded to obtain nodes not covered by the target requirement structure. At least one initial test case in the (n+1)th generation of test case population is randomly generated based on the uncovered nodes.
[0085] In this embodiment of the invention, since n starts from 1, after obtaining the target test cases corresponding to the nth generation test case population, the target test cases corresponding to the previous n generations of test case populations have actually been obtained. Therefore, based on the target test cases corresponding to the previous n generations of test case populations, the (n+1)th generation test case population is determined; wherein, the (n+1)th generation test case population contains one or more initial test cases.
[0086] For example, after obtaining the first-generation test case population, a genetic algorithm is used to select, crossover, and mutate the target test cases corresponding to the first-generation test case population. Then, a second-generation test case population is generated based on the target test cases corresponding to the first-generation test case population. After selecting, crossover, and mutating the target test cases, the target test cases corresponding to the second-generation test case population are obtained. Then, a third-generation test case population is generated based on the target test cases corresponding to the first-generation and second-generation test case populations. After selecting, crossover, and mutating the target test cases, the target test cases corresponding to the third-generation test case population are obtained. This process is repeated, and the target test cases obtained from each generation of test case populations are determined as the test cases in the final target test case population.
[0087] 503. Update the (n+1)th generation test case population to the nth generation test case population, iteratively determine at least one target test case corresponding to the (n+1)th generation test case population, until the preset conditions are met, and stop iterating.
[0088] In practical applications, the initial test cases in the first generation test case population are randomly generated, and the initial test cases of each subsequent generation test case population are generated based on at least one target test case corresponding to all previous generations of test case populations.
[0089] As an example, suppose the target requirement structure contains two branches, branch 1 and branch 2. Taking the first two generations of test case populations as an example, suppose the first generation of test case population corresponds to one target test case, and the target test case of the first generation of test case population covers all nodes of branch 1. Then, when generating the initial test cases of the second generation of test case population, the nodes of branch 1 are excluded, and the initial test cases of the second generation of test case population are generated based on branch 2.
[0090] 504. Based on at least one target test case determined in each generation of test case population, the final test case cluster is obtained.
[0091] Optionally, preset conditions include: the number of iterations reaches the first threshold or the total coverage of the nodes in the target requirement structure by the obtained target test cases is greater than or equal to the second threshold.
[0092] In some embodiments, the preset conditions can be flexibly set according to actual needs. In some embodiments, the preset conditions may include reaching a preset genetic iteration number threshold (i.e., a first threshold), or obtaining the optimal solution of the genetic algorithm (i.e., obtaining the optimal test case population). The preset genetic iteration number threshold can be flexibly set according to actual needs.
[0093] In one possible implementation, refer to Figure 6 Based on the nth generation test case population, at least one target test case is determined, including:
[0094] 601. For each initial test case in the nth generation test case population, the configuration result in the initial test case is assigned to the corresponding judgment node. After each judgment node executes the instruction corresponding to the configuration result, the fitness of the initial test case is obtained. The fitness of the initial test case is used to characterize the degree of coverage of the nodes in the target requirement structure by the initial test case.
[0095] In some implementations, the genetic algorithm includes a fitness function, and each decision node can process the configuration results corresponding to the assigned initial test cases based on the fitness function to obtain the fitness of each initial test case.
[0096] The fitness function can be flexibly set according to actual needs. In one example, each decision node can process the configuration results corresponding to the assigned initial test case to obtain the executability and coverage of the initial test case. Based on the coverage and executability, the fitness of the initial test case is determined. Executability characterizes whether the initial test case can be executed, and coverage characterizes the degree to which the initial test case covers the nodes in the target requirement structure.
[0097] 602. Based on the fitness of each initial test case, perform selection, crossover, and mutation operations on the initial test cases in the nth generation test case population to obtain at least one sub-test case.
[0098] In some implementations, the genetic algorithm includes a selection operator. When selecting at least one initial test case from the nth generation test case population, the selection can be based on the selection operator and the fitness of each initial test case to select at least one initial test case and at least one sub-test case from the nth generation test case population, resulting in at least one selected test case. The selection operator can be flexibly set according to actual needs.
[0099] In some implementations, the genetic algorithm includes a crossover operator. When performing crossover based on at least one selected test case to obtain crossover test cases, the crossover operator can be used to perform crossover on the selected initial test cases to obtain crossover test cases. The crossover strategies corresponding to the crossover operator include, but are not limited to, single-point crossover, multi-point crossover, uniform crossover, and discrete recombination. It should be understood that multi-point crossover refers to randomly setting multiple crossover points in the individual's encoding string and then exchanging partial gene blocks at intervals. The specific crossover strategy corresponding to the crossover operator can be flexibly set according to actual needs. In one example, the crossover operator can be multi-point crossover.
[0100] In some implementations, the genetic algorithm includes a mutation operator. When mutating test cases after crossover to obtain sub-test cases, the mutation algorithm can be used to mutate new test cases to obtain sub-test cases. The mutation operator can be flexibly set according to actual needs.
[0101] 603. For each sub-test case, the configuration results in the sub-test case are assigned to the corresponding judgment nodes, and the fitness of the sub-test case is obtained after each judgment node executes the instruction corresponding to the configuration result.
[0102] 604. Based on the fitness of at least one initial test case and the fitness of at least one sub-test case in the nth generation test case population, determine at least one target test case corresponding to the nth generation test case population.
[0103] Optionally, among at least one initial test case and at least one sub-test case in the nth generation test case population, the test case with the fitness ranked in the top x positions from largest to smallest is selected as the target test case.
[0104] In some implementations, the genetic algorithm includes a selection operator. When selecting at least one initial test case and at least one sub-test case from the nth generation test case population, the selection can be based on the selection operator, the fitness of each initial test case, and the fitness of each sub-test case to obtain the target test case. The selection operator can be flexibly set according to actual needs.
[0105] In one example, the selection operator could be: selecting b test cases with high fitness from at least one initial test case and at least one sub-test case, where the number of b can be flexibly set according to actual needs. For example, assuming b is 2, there are a total of 3 test cases (initial and sub-test cases), and the fitness of the test cases is ranked as: test case 1 > test case 2 > test case 3, then test case 1 and test case 2 are selected as the target test cases.
[0106] It is understandable that the higher the fitness of a test case, the higher the coverage of the nodes in the target requirement structure, that is, the higher the degree of coverage of the nodes in the target requirement structure.
[0107] In one possible implementation, the nth generation test case population contains an m-generation sub-test case population, where m is initially set to 1 and is a positive integer. The initial test cases of the nth generation test case population are used as sub-test cases of the first-generation sub-test case population within that nth generation test case population. Therefore, determining at least one target test case based on the nth generation test case population further includes the following steps:
[0108] Step 1: For each sub-test case in the m-th generation sub-test case population, assign the configuration result in the sub-test case to the corresponding judgment node, and obtain the fitness of the sub-test case after each judgment node executes the instruction corresponding to the configuration result; the fitness of the sub-test case is used to characterize the degree of coverage of the sub-test case to the nodes in the target requirement structure.
[0109] Step 2: Based on the fitness of each sub-test case, perform selection, crossover, and mutation operations on the sub-test cases in the m-th generation sub-test case population to obtain the (m+1)-th generation sub-test case population.
[0110] Step 3: Update the subtest case population of generation m+1 to the subtest case population of generation m, iteratively determine the fitness of each subtest case in the subtest case population of generation m+1 until the stopping condition is met, and stop the iteration.
[0111] The stopping condition can be that the number of iterations reaches a first set value or the total coverage of the nodes in the target requirement structure by the obtained target test cases is greater than or equal to a second set value.
[0112] The first and second settings can be set according to actual needs, and no restrictions are imposed here.
[0113] Step 4: Based on the fitness of each sub-test case in the m-generation sub-test case population, determine at least one target test case corresponding to the n-generation test case population.
[0114] Besides the expression judgment model, the basic model of thermal control automatic control function can generate test segments corresponding to each judgment node in its own test cases. Table 4 shows... Figure 2 and Figure 3 Test fragment generation information:
[0115] Table 4
[0116] 1. YS4100==1 Assignment: YS4100 = 1 Assignment: YS4100 = 0 2. YS4000==1 Assignment: YS4000 = 1 Assignment: YS4000 = 0 3. YS4300<12 Assignment: YS4300 = 11 Assignment: YS4300 = 12 4. YS4300>32 Assignment: YS4300 = 33 Assignment: YS4300 = 32 5. SW1==1 Assignment: SW1 = 1 Assignment: SW1 = 0 6. SW1==0 Assignment: SW1 = 0 Assignment: SW1 = 1
[0117] As can be seen, many of the test segments here are for reviewing software parameters. Such operations cannot be implemented in a testing environment; they require conversion using existing instruction and process models to achieve software replication. The conversion process is illustrated in Table 5 below, which shows the conversion instructions for the decision node test segments:
[0118] Table 5
[0119]
[0120]
[0121] To make the generated test snippets usable, modifications can currently only be made through external parameter assignment and software command sending. All test judgments after model transformation still require further transformation into external parameter assignment and software commands. The transformation steps are as follows: First, check if there are any commands to modify the software parameter assignments. If so, directly convert the software parameter assignment test snippets into command sending. If there are no direct command modifications, such as those in rows 3 and 4 of the table above, it is necessary to search other flowchart models for related software parameter changes, prioritizing the use of the smallest flowchart model for modification, and then transforming it in conjunction with the flowchart content.
[0122] Next, test segments are generated for nodes in the thermal control loop that have a judgment function. The specific generated content is shown in Table 6 below. Table 6 shows some changes to internal variables. These changes cannot be judged externally, nor can they be changed externally; therefore, test segments cannot be generated for these variables.
[0123] Table 6
[0124]
[0125]
[0126] It should be noted that although the operations of the method of this application are described in a specific order in the accompanying drawings, this does not require or imply that these operations must be performed in that specific order, or that all of the operations shown must be performed in order to achieve the desired result.
[0127] Figure 7 This is a block diagram of a test case generation apparatus according to an embodiment of this application.
[0128] like Figure 7 As shown, the test case generation device includes: an acquisition module 701, a processing module 702, and a determination module 703, wherein,
[0129] The acquisition module 701 is used to determine the judgment nodes in the target requirement structure and the structure type to which the judgment nodes belong; the target requirement structure contains multiple nodes and the logical execution relationship between the nodes; multiple nodes include judgment nodes; the structure type includes loop structure and non-loop structure.
[0130] The processing module 702 is used to generate a first-generation test case population based on the output result of the judgment node and the structure type to which the judgment node belongs. The first-generation test case population includes at least one initial test case, and the initial test case includes the configuration result corresponding to each judgment node.
[0131] The determination module 703 is used to determine the final test case cluster based on the first-generation test case population and the genetic algorithm.
[0132] In some embodiments, the determination node includes a first type of node and / or a second type of node, wherein the structure type of the first type of node is a cyclic structure, and the structure type of the second type of node is an acyclic structure; the processing module 702 is specifically used for,
[0133] The number of element configurations corresponding to the first type of node is determined based on the number of iterations of the first type of node.
[0134] The number of element configurations corresponding to the first type of node, the judgment result of the first type of node, and / or the judgment result of the second type of node are used to generate initial test cases to obtain the first generation of test case population.
[0135] In some embodiments, the processing module 702 is specifically used for,
[0136] For each initial test case, based on the number of elements corresponding to the first type of node, one of the judgment results of the first type of node is randomly selected as the configuration value of the first type of node to obtain the configuration result of the first type of node, and / or, one of the judgment results of the second type of node is randomly selected as the configuration result of the second type of node.
[0137] Based on the configuration results of the first type of nodes and / or the configuration results of the second type of nodes, generate initial test cases.
[0138] In some embodiments, the determining module 703 is specifically used for,
[0139] At least one target test case is determined based on the nth generation test case population, where the initial value of n is 1 and n is a positive integer.
[0140] Based on the coverage of nodes in the target requirement structure by at least one target test case in each generation of the test case population of the previous n generations, a test case population of the (n+1)th generation is generated, which contains at least one initial test case.
[0141] Update the (n+1)th generation test case population to the nth generation test case population, iteratively determine at least one target test case corresponding to the (n+1)th generation test case population, until the preset conditions are met, and stop iterating.
[0142] The final test case cluster is obtained based on at least one target test case determined in each generation of test case population.
[0143] In some embodiments, the determining module 703 is specifically used for,
[0144] For each initial test case in the nth generation test case population, the configuration result in the initial test case is assigned to the corresponding judgment node. After each judgment node executes the instruction corresponding to the configuration result, the fitness of the initial test case is obtained. The fitness of the initial test case is used to characterize the degree of coverage of the nodes in the target requirement structure by the initial test case.
[0145] Based on the fitness of each initial test case, the initial test cases in the nth generation test case population are selected, crossovered, and mutated to obtain at least one sub-test case.
[0146] For each sub-test case, the configuration results in the sub-test case are assigned to the corresponding decision nodes. After each decision node executes the instruction corresponding to the configuration result, the fitness of the sub-test case is obtained.
[0147] Based on the fitness of at least one initial test case and the fitness of at least one sub-test case in the nth generation test case population, determine at least one target test case corresponding to the nth generation test case population.
[0148] In some embodiments, the determining module 703 is specifically used to select, from at least one initial test case and at least one sub-test case in the nth generation test case population, the test case whose fitness is ranked in the top x positions from largest to smallest as the target test case.
[0149] In some embodiments, the preset conditions include: the number of iterations reaches a first threshold or the total coverage of the nodes in the target requirement structure by the obtained target test cases is greater than or equal to a second threshold.
[0150] It should be understood that the units described in the test case generation apparatus correspond to the various steps in the method described with reference to 1. Therefore, the operations and features described above for the method also apply to the test case generation apparatus and the units it contains, and will not be repeated here. The test case generation apparatus can be pre-implemented in a browser or other security application on a computer device, or it can be loaded into a browser or other security application on a computer device through download or other means. The corresponding units in the test case generation apparatus can cooperate with the units in the computer device to implement the solutions of the embodiments of this application.
[0151] The division of modules or units mentioned in the detailed description above is not mandatory. In fact, according to the embodiments of this application, the features and functions of two or more modules or units described above can be embodied in one module or unit. Conversely, the features and functions of one module or unit described above can be further divided and embodied by multiple modules or units.
[0152] It should be noted that for details not disclosed in the test case generation device of this application embodiment, please refer to the details disclosed in the above embodiments of this application, which will not be repeated here.
[0153] The following is for reference. Figure 8 , Figure 8 A schematic diagram of a computer device suitable for implementing embodiments of this application is shown, such as... Figure 8 As shown, the computer system 800 includes a central processing unit (CPU) 801, which can perform various appropriate actions and processes based on programs stored in read-only memory (ROM) 802 or programs loaded from storage section 808 into random access memory (RAM) 803. RAM 803 also stores various programs and data required for the system's operating instructions. CPU 801, ROM 802, and RAM 803 are interconnected via bus 804. Input / output (I / O) interface 805 is also connected to bus 804.
[0154] The following components are connected to I / O interface 805: an input section 806 including a keyboard, mouse, etc.; an output section 807 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and speakers, etc.; a storage section 808 including a hard disk, etc.; and a communication section 809 including a network interface card such as a LAN card, modem, etc. The communication section 809 performs communication processing via a network such as the Internet. A drive 810 is also connected to I / O interface 805 as needed. A removable medium 811, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., is installed on drive 810 as needed so that computer programs read from it can be installed into storage section 808 as needed.
[0155] Specifically, according to embodiments of this application, the flowchart above refers to... Figure 1 The described process can be implemented as a computer software program. For example, embodiments of this application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowchart. In such an embodiment, the computer program contains program code for performing the methods shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network via communication section 809, and / or installed from removable medium 811. When the computer program is executed by central processing unit (CPU) 801, it performs the functions defined in the system of this application.
[0156] It should be noted that the computer-readable medium shown in this application can be a computer-readable signal medium or a computer-readable storage medium, or any combination of the two. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this application, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In this application, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media can also be any computer-readable medium other than computer-readable storage media, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wireless, wire, optical fiber, RF, etc., or any suitable combination thereof.
[0157] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operational instructions of possible implementations of systems, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two connected blocks may actually be executed substantially in parallel, or they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified functions or operational instructions, or using a combination of dedicated hardware and computer instructions.
[0158] The units or modules described in the embodiments of this application can be implemented in software or hardware. The described units or modules can also be located in a processor; for example, a processor may be described as including a processing module. The names of these units or modules do not necessarily constitute a limitation on the unit or module itself.
[0159] On the other hand, this application also provides a computer-readable storage medium, which may be included in the computer device described in the above embodiments, or may exist independently and not assembled into the computer device. The aforementioned computer-readable storage medium stores one or more programs that, when used by one or more processors, execute the test case generation method described in this application. For example, it may execute... Figure 1 The steps of the test case generation method are shown.
[0160] This application provides a computer program product including instructions that, when executed, cause the method described in this application to be performed. For example, it can execute... Figure 1 The steps of the test case generation method are shown.
[0161] The above description is merely a preferred embodiment of this application and an explanation of the technical principles employed. Those skilled in the art should understand that the scope of disclosure in this application is not limited to technical solutions formed by specific combinations of the above-described technical features, but should also cover other technical solutions formed by arbitrary combinations of the above-described technical features or their equivalents without departing from the foregoing disclosed concept. For example, technical solutions formed by substituting the above features with (but not limited to) technical features with similar functions disclosed in this application.
Claims
1. A test case generation method, characterized in that, The method includes: Determine the decision nodes in the target requirement structure and the structure type to which the decision nodes belong; the target requirement structure contains multiple nodes and the logical execution relationships between the nodes; the multiple nodes include the decision nodes; the structure type includes a loop structure and a non-loop structure; Based on the output of the judgment node and the structure type to which the judgment node belongs, a first-generation test case population is generated. The first-generation test case population includes at least one initial test case, and the initial test case includes the configuration result corresponding to each judgment node. Based on the first-generation test case population and genetic algorithm, the final test case cluster is determined; The judgment node includes a first type of node and / or a second type of node, wherein the structure type of the first type of node is a cyclic structure, and the structure type of the second type of node is a non-cyclic structure; the step of generating a first-generation test case population based on the output result of the judgment node and the structure type to which the judgment node belongs includes: Based on the number of iterations of the first type of node, determine the number of element configurations corresponding to the first type of node; Based on the number of element configurations corresponding to the first type of node, the judgment result of the first type of node and / or the judgment result of the second type of node, the initial test cases are generated to obtain the first generation test case population.
2. The test case generation method according to claim 1, characterized in that, The initial test cases are generated based on the number of elements configured for the first type of node, the judgment result of the first type of node, and / or the judgment result of the second type of node, including: For each initial test case, according to the number of elements corresponding to the first type of node, one of the judgment results of the first type of node is randomly selected as the configuration value of the first type of node to obtain the configuration result of the first type of node, and / or, one of the judgment results of the second type of node is randomly selected as the configuration result of the second type of node. The initial test cases are generated based on the configuration results of the first type of nodes and / or the configuration results of the second type of nodes.
3. The test case generation method according to any one of claims 1-2, characterized in that, The determination of the final test case cluster based on the first-generation test case population and genetic algorithm includes: At least one target test case is determined based on the nth generation test case population, where the initial value of n is 1 and n is a positive integer; Based on the coverage of the nodes in the target requirement structure by the at least one target test case in each generation of the test case population in the previous n generations, a test case population of generation n+1 is generated, wherein the test case population of generation n+1 contains at least one initial test case. Update the n+1 generation test case population to the nth generation test case population, iteratively determine the at least one target test case corresponding to the n+1 generation test case population, until a preset condition is met, and stop iterating; The final test case cluster is obtained based on at least one target test case determined in each generation of test case population.
4. The test case generation method according to claim 3, characterized in that, The step of determining at least one target test case based on the nth generation test case population includes: For each initial test case in the nth generation test case population, the configuration result in the initial test case is assigned to the corresponding judgment node. After each judgment node executes the instruction corresponding to the configuration result, the fitness of the initial test case is calculated. The fitness of the initial test case is used to characterize the degree of coverage of the nodes in the target requirement structure by the initial test case. Based on the fitness of each initial test case, the initial test cases in the nth generation test case population are selected, crossovered, and mutated to obtain at least one sub-test case. For each sub-test case, the configuration results in the sub-test case are assigned to the corresponding judgment nodes. After each judgment node executes the instruction corresponding to the configuration result, the fitness of the sub-test case is calculated. Based on the fitness of at least one initial test case and the fitness of at least one sub-test case in the nth generation test case population, at least one target test case corresponding to the nth generation test case population is determined.
5. The test case generation method according to claim 4, characterized in that, The step of determining at least one target test case corresponding to the nth generation test case population based on the fitness of at least one initial test case and the fitness of at least one sub-test case in the nth generation test case population includes: In the nth generation test case population, among the at least one initial test case and the at least one sub-test case, the test case with the fitness ranked in the top x positions from largest to smallest is selected as the target test case.
6. The test case generation method according to claim 3, characterized in that, The preset conditions include: the number of iterations reaches a first threshold or the total coverage of the nodes in the target requirement structure by the obtained target test cases is greater than or equal to a second threshold.
7. A test case generation device, characterized in that, include: The acquisition module is used to determine the judgment nodes in the target requirement structure and the structure type to which the judgment nodes belong; The target requirement structure includes multiple nodes and the logical execution relationships between the nodes; The plurality of nodes includes the decision node; the structure type includes a cyclic structure and a non-cyclic structure; The processing module is used to generate a first-generation test case population based on the output result of the judgment node and the structure type to which the judgment node belongs. The first-generation test case population includes at least one initial test case, and the initial test case includes the configuration result corresponding to each judgment node. The determination module is used to determine the final test case cluster based on the first-generation test case population and the genetic algorithm; The judgment node includes a first type of node and / or a second type of node, wherein the structure type of the first type of node is a cyclic structure and the structure type of the second type of node is an acyclic structure; The step of generating a first-generation test case population based on the output of the judgment node and the structure type to which the judgment node belongs includes: Based on the number of iterations of the first type of node, determine the number of element configurations corresponding to the first type of node; Based on the number of element configurations corresponding to the first type of node, the judgment result of the first type of node and / or the judgment result of the second type of node, the initial test cases are generated to obtain the first generation test case population.
8. A computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the method as described in any one of claims 1-6.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the method as described in any one of claims 1-6.
Citation Information
Patent Citations
Rapid high-path coverage rate test case generation method
CN109918304A
Test case generation method, device and apparatus and computer readable storage medium
CN112597055A