A method and system for intelligent generation of software test cases based on generative AI
By integrating multi-source data to generate standardized test element feature representations, and using an interactive test case generation network for correlation reasoning and feature fusion, key test scenarios are identified, concurrent test case drafts are generated, and multiple rounds of optimization are performed. This solves the problem of insufficient logical depth of test scenarios in existing technologies and achieves a systematic improvement in the quality of test cases.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- BEIJING HUAXIN MEASUREMENT & CONTROL TECH CO LTD
- Filing Date
- 2026-02-25
- Publication Date
- 2026-05-26
AI Technical Summary
Existing technologies lack the ability to deeply analyze and model the inherent relationships between multi-source heterogeneous test elements in software testing, resulting in insufficient logical depth of the generated test scenarios, making it difficult to cover complex interactions and abnormal processes, and lacking a systematic, multi-dimensional quantitative feedback automated iterative optimization framework.
By receiving and integrating data from software requirements specifications, system design documents, and historical defect databases, standardized test element feature representations are generated. An interactive test case generation network is used to perform element association reasoning and feature cross-fusion to identify key test scenarios, generate concurrent test case drafts, conduct completeness assessments and defect pattern annotations using a historical test case library, construct a test case optimization decision space for multiple rounds of evolution, and finally generate an executable test instruction sequence that conforms to the target test framework.
It achieves in-depth modeling of the inherent logical relationship between requirements, design and historical defects, enhances the logical depth of test scenarios and the directionality of potential failure modes, optimizes the coverage completeness and error detection capability of test cases, and realizes a systematic iterative improvement in test case quality.
Smart Images

Figure CN122086779A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of software test automation technology, specifically a method and system for intelligent generation of software test cases based on generative AI. Background Technology
[0002] Currently, the software testing field is actively exploring the use of generative artificial intelligence technology to automatically create test cases. Existing mainstream solutions typically take textual materials such as software requirements specifications and design documents as input, and directly output test case text through prompting engineering guidance to a large language model. Another common approach is to use historical defect reports as an independent data source to generate test scenarios targeting known error patterns. These methods are essentially pattern-based matching or end-to-end text generation.
[0003] These existing technical solutions have shortcomings. They generally lack the ability to deeply analyze and model the inherent relationships between multi-source heterogeneous test elements. Requirements, designs, and historical defects are treated in isolation or simply pieced together. The generation process cannot effectively reason about the complex causal relationships between business rules, system architecture, and potential faults, resulting in insufficient logical depth in the generated test scenarios and an inability to cover complex interactions and abnormal processes. The optimization process relies on post-generation, manually-led review and screening, or simple filtering based on a single indicator, lacking a systematic, automated iterative optimization framework based on multi-dimensional quantitative feedback. This makes it difficult to achieve a balance between the completeness of functional coverage and the effectiveness of defect detection in the final test case set.
[0004] There is a need for a method that enables deep correlation reasoning and fusion between test elements, and to establish a self-evolving test case optimization mechanism to systematically improve the quality and usability of intelligently generated test cases. Summary of the Invention
[0005] This invention aims to solve at least one of the technical problems existing in the prior art; Therefore, this invention proposes an intelligent method for generating software test cases based on generative AI, comprising: It receives and integrates raw input data from software requirements specifications, software system design documents, and historical defect databases, and decomposes and extracts the data to generate standardized test element feature representations. All the standardized test element feature representations are input into an interactive test case generation network for element association reasoning and feature cross-fusion. Based on the output of the interactive test case generation network, a set of key test scenarios in software functions and business rules is identified; For each scenario in the set of key test scenarios, a concurrent test case generation process is initiated to generate multiple candidate test case drafts; The completeness of each candidate test case draft is evaluated and defect patterns are marked using a historical test case library. By integrating the results of the completeness assessment and defect pattern annotation, a use case optimization decision space is constructed, and multiple rounds of use case evolution are performed within the use case optimization decision space; Based on the results of the test case evolution, a final set of test cases is selected and transformed into an executable test instruction sequence that meets the requirements of the target test framework. The executable test instruction sequence is imported into the software system's automated test management platform.
[0006] Furthermore, the generation of standardized test element feature representations includes: Receive and integrate raw input data from software requirements specification documents, software system design documents, and historical defect databases to build an initial test information knowledge base; Based on the preset test dimension division strategy, the initial test information knowledge base is decomposed and information is extracted in multiple levels to form several sets of interrelated test focus points. Semantic standardization and structured coding are performed on each set of test concerns to generate standardized test element feature representations; The initial test information knowledge base is decomposed and information extracted at multiple levels according to a preset test dimension division strategy, forming several sets of interrelated test focus points, including: Extract test dimension partitioning templates that match the current software architecture from the preset test strategy library. The test dimension partitioning templates define the functional module partitioning logic, business path traversal logic, and abnormal condition combination logic. The initial test information knowledge base is functionally divided into functional domains using the aforementioned functional module partitioning logic to generate a set of functional module test concerns. The business path traversal logic is used to extract the business process from the initial test information knowledge base, generating a set of business process test concerns. The abnormal condition combination logic is used to enumerate abnormal states in the initial test information knowledge base to generate a set of abnormal condition test concerns. A dynamic semantic association is established in the knowledge graph between the functional module test concern set, the business process test concern set, and the abnormal condition test concern set, to ensure that any change in test requirements can be synchronously updated in all relevant test concern sets.
[0007] Furthermore, the step of performing semantic standardization and structured encoding processing on each set of test concerns to generate standardized test element feature representations includes: Each set of test concerns is assigned an independent semantic parser, which transforms the natural language descriptions and semi-structured information within the set into a formal intermediate representation. In each set of test concerns, all test requirement items contained therein are traversed, and the original semantic features are extracted. The pre-built standardized dictionary of software engineering terminology is invoked to perform terminology normalization and ambiguity elimination on the extracted original semantic features; The normalized semantic features are input into a structured encoding pipeline, which embeds the features into context and links relationships by introducing the interface contract and state model of the software system components. The output feature vector, after semantic standardization and structured encoding, serves as the feature representation of the standardized test elements.
[0008] Furthermore, the step of inputting all the standardized test element feature representations into an interactive test case generation network for element association reasoning and feature cross-fusion includes: The interactive test case generation network is initialized, which includes a shared working area for feature co-occurrence learning and multiple private generators that correspond one-to-one with the set of test concerns. Each of the private generators reads the corresponding standardized test element feature representation and preliminarily derives the local test conditions and expected results from it; All of the private generators write their respective test conditions and expected results into the shared workspace, and trigger a round of scenario completeness calculation based on causal reasoning within the shared workspace; Based on the result of the scenario completeness calculation, scenario supplementary signals and logical conflict signals are generated, and the scenario supplementary signals and logical conflict signals are broadcast to each of the private generators; Each of the private generators iteratively corrects the content derived from its standardized test element feature representation based on the received scenario supplementary signal and logical conflict signal. The process of repeatedly writing features, calculating completeness, broadcasting signals, and iteratively correcting them continues until a consensus is reached on the logical state within the shared work area, ultimately outputting a set of fully correlated and integrated global test scenario descriptions.
[0009] Furthermore, based on the output of the interactive use case generation network, the set of key test scenarios identified in the software functions and business rules includes: The interactive test cases are parsed to generate a global test scenario description from the network output, which is then reconstructed into a virtual software behavior space. In the virtual software behavior space, a scenario complexity and change impact analysis algorithm is used to evaluate the number of logical branches, state combination complexity, and impact weight on core business for each scenario. Based on the evaluation results, all scenarios are sorted, and scenarios with high complexity and high impact weight are selected and marked as high-priority candidate scenarios. Dependency analysis is performed on the high-priority candidate scenarios to trace their dependent basic functional scenarios and associated abnormal scenarios, thereby determining a complete set of key test scenarios that includes core logic and boundaries.
[0010] Furthermore, for each scenario in the set of key test scenarios, a concurrent test case generation process is initiated to generate multiple candidate test case drafts, including: For each scenario in the set of key test scenarios, create an independent generation sandbox environment. Each generation sandbox environment contains a complete formal description of the scenario and related constraint rules. In each generated sandbox environment, a series of basic test operations are selected from a predefined library of test action atoms according to a strategy; The selected basic test operations are arranged and combined according to different combinations of input data, execution order and preconditions to form an initial test step sequence; The initial test step sequence is simulated and run in the generated sandbox environment, and a built-in software behavior simulator is driven to deduce the state transition of the software system after the execution of the initial test step sequence. Record the final system state, intermediate outputs and triggering logic paths generated at the end of the simulation, and package the simulation process, the sequence of initial test steps used and the simulation results to form a draft of the candidate test cases.
[0011] Furthermore, the step of using a historical test case library to perform a completeness assessment and defect pattern annotation on each candidate test case draft includes: Extract the structural features of each candidate test case draft, including the coverage of test steps, the boundary values of input data, and the depth of state transitions; The structural features are vectorized and pattern matching is performed in the historical test case library to find all historically executed test case records that are structurally similar and have known execution results. For each of the retrieved executed test case records, extract the code paths covered during its actual execution, the types of defects discovered, and the information on any missing defects. The path coverage sufficiency index of the candidate test case draft is calculated by comparing the inferred coverage path of the candidate test case draft with the actual coverage path of the executed test case record. By analyzing the defect information found and missed in the executed test case records, the test blind spots and potential defect patterns of the candidate test case drafts are identified. The path coverage sufficiency index, along with the test blind spots and potential defect patterns, are used as tags and attached to the corresponding candidate test case drafts to complete the completeness assessment and defect pattern labeling.
[0012] Furthermore, by fusing the results of the completeness assessment and defect pattern annotation, a use case optimization decision space is constructed, and multiple rounds of use case evolution are performed within the use case optimization decision space, including: Each candidate test case draft is treated as an optimization individual, with its path coverage sufficiency index as the quality dimension and its number of test blind spots and the inverse of the severity of potential defect patterns as the robustness dimension, to construct a two-dimensional test case optimization decision space. In the use case optimization decision space, the quality dimension and robustness dimension are dynamically weighted according to the priority strategy of the current testing phase, and the fitness score of each optimization individual is calculated. Based on the fitness score, a genetic evolution mechanism is used to carry out multiple rounds of evolution: in each round, a certain proportion of the optimized individuals with the lowest scores are eliminated, and the remaining optimized individuals are subjected to step crossover and mutation operations to generate new optimized individuals to supplement the use case optimization decision space. Repeat the elimination and generation iterative process until the average fitness score of the optimized individuals in the use case optimization decision space reaches a stable state, or reaches a preset number of evolutionary generations; From the final generation of optimized individuals, select the test case drafts corresponding to the multiple optimized individuals with the highest fitness scores to form a final set of test cases.
[0013] Further, the selection of a final set of test cases and the transformation of them into an executable sequence of test instructions that conforms to the requirements of the target testing framework includes: Each test case draft in the final test case set is parsed, and its natural language description and formalization steps are transformed into script language primitives supported by the target testing framework. For each of the scripting language primitives, match the corresponding assertion library function and driver library function in the target testing framework, and verify the parameter format and data type of the function call; Based on the execution logic and dependencies of the test cases, add necessary test fixture initialization and data cleanup instructions to each of the scripting language primitives; The script language primitives, which consist of assertion library functions, driver library functions, test fixture initialization, and data cleanup instructions, are encoded into specific test script files in the order of the test steps. All generated test script files undergo syntax checks and dependency resolution to ensure that the scripts can be correctly loaded and executed by the target testing framework, ultimately forming the executable test instruction sequence.
[0014] Furthermore, the present invention also includes a software test case intelligent generation system based on generative AI, the system including a memory, a processor, and a computer program stored in the memory and running on the processor, wherein when the processor executes the computer program, it implements the steps of the above-described software test case intelligent generation method based on generative AI.
[0015] Compared with the prior art, the beneficial effects of the present invention are: By constructing an interactive test case generation network, element association reasoning and feature cross-fusion are performed on multi-source standardized test elements, achieving deep modeling of the inherent logical relationships between requirements, design, and historical defects. This network can parse and establish nonlinear relationships between different element features, transforming discrete input information into a feature representation with rich contextual relationships. This processing ensures that the set of key test scenarios output by the network is not only based on the surface semantics of the input text, but also includes test conditions generated through feature interaction and reasoning, reflecting the complex dependencies between the system's internal states and behaviors. This enhances the logical depth of the identified scenarios and the directional indication of potential failure modes.
[0016] By leveraging a historical test case library, candidate test case drafts are evaluated for completeness and defect pattern annotation. Based on this, a multi-dimensional test case optimization decision space is constructed, within which multiple rounds of test case evolution are performed. Completeness evaluation, based on the historical knowledge base, quantifies the differences in functional and logical coverage between the drafts. Defect pattern annotation compares the draft content with historical defect characteristics to identify potential error detection tendencies. The decision space constructed based on these structured evaluation metrics provides clear optimization objectives and constraints for the evolutionary algorithm. The multi-round evolutionary process dynamically adjusts the composition and content of the candidate set based on evaluation feedback, enabling the final output test case set to achieve an optimized balance across multiple dimensions, including coverage completeness, error detection capability, and execution cost, thus achieving a systematic iterative improvement in test case quality. Attached Figure Description
[0017] Figure 1This is a flowchart illustrating the steps of the intelligent generation method for software test cases based on generative AI described in this invention. Figure 2 A flowchart for semantic standardization and structured encoding processing; Figure 3 A flowchart for identifying the set of key test scenarios; Figure 4 A line graph showing the changes in core metrics of software test cases across multiple generations of evolutionary iterations; Figure 5 An evolution trend diagram of test cases executed in multiple rounds within the decision space for optimizing software test cases. Detailed Implementation
[0018] The technical solution of the present invention will be clearly and completely described below with reference to the embodiments. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0019] See Figure 1 The system receives and integrates raw input data from software requirements specifications, software system design documents, and historical defect databases. This data is decomposed and extracted to generate standardized test element feature representations. All standardized test element feature representations are input into an interactive test case generation network, where element association reasoning and feature cross-fusion are performed. Based on the output of the interactive test case generation network, a set of key test scenarios in software functions and business rules is identified. For each scenario in the key test scenario set, a concurrent test case generation process is initiated to generate multiple candidate test case drafts. The completeness of each candidate test case draft is evaluated and defect pattern is labeled using a historical test case library. The results of the completeness evaluation and defect pattern labeling are combined to construct a test case optimization decision space, within which multiple rounds of test case evolution are performed. Based on the results of the test case evolution, a final set of test cases is selected and transformed into an executable test instruction sequence that meets the requirements of the target testing framework. Finally, the executable test instruction sequence is imported into the software system's automated test management platform.
[0020] See Figure 2In one embodiment of the present invention, the implementation of generating standardized test element feature representations begins with the system receiving and integrating raw input data from software requirements specifications, software system design documents, and a historical defect database. This input data is uniformly parsed and stored to construct an initial test information knowledge base. The initial test information knowledge base contains text descriptions, data tables, flowcharts, and defect record entries from various sources. Based on a preset test dimension segmentation strategy, the initial test information knowledge base undergoes multi-level decomposition and information extraction. The system extracts a test dimension segmentation template matching the current software architecture from a preset test strategy library. This template explicitly defines the functional module segmentation logic, business path traversal logic, and exception condition combination logic. The functional module segmentation logic is used to perform functional domain segmentation on the initial test information knowledge base. For example, descriptions involving user management, order processing, and payment settlement are categorized separately, thereby generating a set of functional module test concerns. The business path traversal logic is used to extract business processes from the initial test information knowledge base. For example, continuous steps are extracted from the complete path description from "user login" to "product selection" to "payment and order placement," thereby generating a set of business process test concerns. Anomaly condition combination logic is used to enumerate abnormal states in the initial test information knowledge base, such as listing conditions for scenarios like input validation, network timeouts, and data consistency conflicts, thereby generating a set of abnormal condition test concerns. Dynamic semantic relationships are established in the knowledge graph between the functional module test concern set, the business process test concern set, and the abnormal condition test concern set. When the interface of a functional module changes, the associated semantic links trigger update prompts for related business processes and abnormal conditions, ensuring that any change in test requirements is synchronously updated in all relevant test concern sets.
[0021] In some embodiments, semantic standardization and structured coding are performed on each set of test concerns to generate standardized test element feature representations. The system assigns an independent semantic parser to each set of test concerns, which is responsible for uniformly transforming the natural language descriptions and semi-structured information within the set into a formal intermediate representation. Within each set of test concerns, all test requirement entries are traversed, and raw semantic features are extracted. These raw semantic features include keywords, entities, actions, and constraints. A pre-built software engineering terminology standardization dictionary is invoked to perform terminology normalization and ambiguity resolution on the extracted raw semantic features.
[0022] It is understandable that normalized semantic features are input into a structured encoding pipeline, which then embeds these features into context and links relationships by introducing interface contracts and state models of software system components. For example, for the semantic feature "submit order," the structured encoding pipeline associates it with its preceding state "shopping cart not empty," the called application interface "OrderService.submit()," and the possible subsequent state "order pending payment." The structured encoding pipeline maps semantic features to numerical vectors through feature vector transformation. In specific implementations, after performing term mapping and context linking, the structured encoding pipeline can use a semantic distance-based quantization method to generate feature vectors. This process involves calculating the semantic distance between the processed features and the benchmark concepts in the standardized dictionary. In some embodiments, the semantic distance can be quantized based on the following relationship: in: Indicates the standardized distance of terms. This represents the preprocessed term feature vector. This represents the feature vector of the corresponding benchmark term in the standardized dictionary of software engineering terminology. The terminology standardization distance is used to help determine the matching degree of terminology normalization and affects the generation of the final feature vector. The output is the feature vector after semantic standardization and structured encoding. This feature vector is the standardized test element feature representation, which is used for subsequent element association reasoning.
[0023] In one embodiment of the invention, all standardized test element feature representations are input into an interactive test case generation network for element association reasoning and feature cross-fusion. This process begins with initializing the interactive test case generation network. The interactive test case generation network includes a shared workspace for feature co-occurrence learning and multiple private generators corresponding one-to-one with a set of test concerns. The number of private generators is strictly equal to the number of test concern sets. Each private generator reads the corresponding standardized test element feature representation and initially derives local test conditions and expected results from it. For example, a private generator based on the test concern set of the "payment" function module may derive the test condition "payment amount must be positive" and the expected result "payment successful".
[0024] In some embodiments, all private generators write their respective test conditions and expected results into a shared workspace, triggering a round of scenario completeness calculation based on causal reasoning within the shared workspace. The scenario completeness calculation analyzes the logical dependencies and potential conflicts between all test conditions and expected results written into the shared workspace. Based on the results of the scenario completeness calculation, scenario supplementary signals and logical conflict signals are generated. For example, a scenario supplementary signal is generated when the expected result of "payment successful" lacks the corresponding precondition of "payment channel available," and a logical conflict signal is generated when "order status is completed" and "payment status is pending payment" occur simultaneously. The system broadcasts the scenario supplementary signals and logical conflict signals to each private generator.
[0025] It is understandable that each private generator iteratively corrects the content derived from its standardized test element feature representation based on the received scene supplement signals and logical conflict signals. Private generators receiving logical conflict signals adjust their derivation logic to eliminate contradictions, while those receiving scene supplement signals retrieve their own standardized test element feature representations to complete missing conditions. The process of feature writing, completeness calculation, signal broadcasting, and iterative correction is repeated, and the shared workspace updates its internal logical state set after each iteration. This iterative process continues until the logical states within the shared workspace reach a consensus. Consensus means that no new logical conflict signals are generated within the preset iteration rounds, and the number of scene supplement signals is below a set threshold.
[0026] In practice, determining whether a consensus has been reached on the logical states within the shared workspace requires a quantifiable integration metric. The calculation of this metric involves measuring the consistency of all logical states within the shared workspace. Optionally, the consensus state can be determined using the following formula: in: Indicators representing consensus integration This indicates the total number of logical state entries maintained within the shared workspace. Indicates the number of iterations in the current iteration round. The feature set of logical states, Indicates the th iteration in the previous iteration. The feature set of logical states, symbols This represents the symmetric difference operation of sets. When the consensus convergence index... The value exceeds the preset consensus threshold for three consecutive rounds. At this point, the iteration loop terminates. The interactive test case generation network ultimately outputs a set of fully correlated and integrated global test scenario descriptions, which integrate the derivations corrected by all private generators.
[0027] See Figure 3 In one embodiment of the present invention, a set of key test scenarios in software functions and business rules is identified based on the output of the interactive test case generation network. The implementation process first parses the global test scenario description output by the interactive test case generation network. The global test scenario description includes a series of scenario definitions, preconditions, operation steps, and post-assertions expressed in formal language. After parsing the global test scenario description, the system reconstructs it into a virtual software behavior space. The virtual software behavior space is a computational model containing all possible system states, state transitions, and triggering events. This model maps each global test scenario description to one or more executable paths in the virtual software behavior space.
[0028] In some embodiments, a scenario complexity and change impact analysis algorithm is used in a virtual software behavior space to evaluate the number of logical branches, state combination complexity, and impact weight on core business for each scenario. The scenario complexity and change impact analysis algorithm traverses each path mapped from a scenario in the virtual software behavior space, counts the number of condition judgment nodes on the path to determine the number of logical branches, and simultaneously calculates the number of different system states traversed by the path and their combination relationships to quantify state combination complexity. The impact weight on core business is obtained by querying a preset business rule importance mapping table, which assigns weight values between 0 and 1 to different business operations.
[0029] It is understandable that ranking all scenarios based on the evaluation results requires considering three dimensions: the number of logical branches, the complexity of state combinations, and the weight of their impact on core business. Optionally, the system calculates a comprehensive priority score for each scenario, which can be performed according to the following formula: in: This indicates the scenario priority score. Indicates the number of logical branches in the scene. This represents the normalized numerical value of the state combinatorial complexity of the scenario. The coefficient represents the weight of the impact of a scenario on the core business. , and These are preset weighting parameters used to balance the contributions of different dimensions in the ranking. The system scores based on scenario priority. All scenarios are sorted in descending order. Scenarios with high complexity and significant impact weight are selected from the sorted list, meaning scenarios with priority scores higher than a preset threshold are marked as high-priority candidate scenarios.
[0030] In practical implementation, dependency analysis is performed on high-priority candidate scenarios to trace their dependent basic functional scenarios and associated abnormal scenarios. This analysis is conducted by querying a state dependency graph in a virtual software behavior space. For each high-priority candidate scenario, the system reverse-engineers all its preceding states to identify the basic functional scenarios that must be satisfied first. Simultaneously, the system forward-engineers all possible abnormal state transitions from this scenario to identify all associated abnormal scenarios. Optionally, dependency analysis also considers data flow dependencies between scenarios; for example, the output of one scenario may be the input of another. Based on this analysis, the system merges the high-priority candidate scenarios and their traced basic functional scenarios and associated abnormal scenarios to determine a complete set of key test scenarios containing core logic and boundaries. This set of key test scenarios serves as the direct input for the subsequent concurrent test case generation process.
[0031] In one embodiment of the present invention, a concurrent test case generation process is initiated for each scenario in the set of key test scenarios. The system creates an independent generation sandbox environment for each scenario in the set of key test scenarios. Each generation sandbox environment contains a complete formal description of the scenario and related constraint rules. The formal description defines the initial state, triggering events, and expected results, while the constraint rules limit the range of input data values and the relationships between objects. In each generation sandbox environment, the system selects a series of basic test operations from a predefined test action atom library according to a strategy. The test action atom library stores indivisible basic operation instructions such as "input text", "click button", "verify element existence", and "call application programming interface". The selected basic test operations are arranged and combined according to different combinations of input data, execution order, and preconditions to form multiple differentiated initial test step sequences. Input data combinations include boundary values, special characters, and null values, etc., and the execution order involves the parallel, serial, and conditional branching arrangements of the operation steps.
[0032] In some embodiments, an initial test step sequence is simulated and run in a generated sandbox environment. The system drives a built-in software behavior simulator to deduce the state transitions of the software system after the execution of the initial test step sequence. The software behavior simulator calculates the impact of each operation step on the internal state of the system, the database, and external service calls, based on the system's design specifications and application interface contracts. The final system state, intermediate outputs, and triggering logical paths generated at the end of the simulation are recorded. The simulation process, the initial test step sequence used, and the simulation results are packaged into a candidate test case draft. The candidate test case draft contains all the necessary information to reproduce the simulation. It can be understood that the system uses a historical test case library to perform a completeness evaluation and defect pattern annotation on each candidate test case draft. The system first extracts the structural features of each candidate test case draft, including the coverage of test steps, the boundary values of input data, and the depth of state transitions. The coverage of test steps refers to the proportion of scenario steps covered by the operation sequence; the boundary values of input data indicate whether extreme values were used; and the depth of state transitions reflects the hierarchical changes in system state caused by the operation.
[0033] Optionally, the structural features are vectorized and pattern matching is performed in the historical test case library to find all historically executed test case records that are structurally similar and have known execution results. Pattern matching calculates the similarity between the feature vectors of the candidate test case draft and the feature vectors of the historical records. The similarity calculation can be based on weighted cosine similarity. See Table 1 for examples of matching two candidate drafts with historical records.
[0034] Table 1: Examples of Structural Feature Vector Matching In practice, for each retrieved executed test case record, the code paths covered during actual execution, the types of defects discovered, and any missing defect information are extracted. By comparing the projected coverage paths of the candidate test case draft with the actual coverage paths of the executed test case records, a path coverage sufficiency index for the candidate test case draft is calculated. This index reflects the comprehensiveness of the path set projected by the candidate draft relative to the historical actual execution path set. The calculation can be performed based on the following relationship: in: Indicators representing path coverage adequacy This represents the set of paths derived from the candidate test case drafts using a software behavior simulator. This represents the set of actual coverage paths extracted from the matched historical records of executed test cases. (Symbol) This indicates the number of elements in the set. By analyzing the defect information found and missed in the executed test case records, the system identifies test blind spots and potential defect patterns in candidate test case drafts. For example, if historical records show that a certain combination of boundary values frequently triggers a null pointer exception, and the candidate draft does not cover this combination, then this is marked as a test blind spot. Path coverage sufficiency indicators, test blind spots, and potential defect patterns are attached as tags to the corresponding candidate test case drafts to complete the completeness assessment and defect pattern labeling. These tags are used for subsequent construction of the test case optimization decision space.
[0035] See Figure 4 This is a line graph showing the changes in key metrics of software test cases across multiple generations of evolutionary iterations. The two lines are highly synchronized, indicating a positive correlation between the improvement in test case quality and the optimization of path coverage, validating the effectiveness of the multi-round evolutionary strategy. The synchronized growth of average fitness score and path coverage improvement rate quantitatively demonstrates that the multi-round evolutionary strategy can continuously improve the quality and coverage of test cases. Clear trend changes serve as a core criterion for judging whether the evolution has converged; when the curve flattens, iteration can be stopped to avoid inefficient computational investment. The increase in path coverage improvement rate directly corresponds to a reduction in test blind spots, providing a traceable predictive basis for subsequent defect rate reductions. By observing the improvement rate of metrics in each generation, bottlenecks in evolutionary efficiency can be identified. For example, if the improvement rate of a certain generation drops sharply, the elimination ratio or mutation strategy can be adjusted accordingly.
[0036] In one embodiment of the invention, a use case optimization decision space is constructed by integrating the results of completeness assessment and defect pattern annotation. Multiple rounds of use case evolution are then performed within this decision space, with each candidate test case draft treated as an optimization individual. The path coverage sufficiency metric for each optimization individual is used as the quality dimension. The number of test blind spots and the inverse of the severity of potential defect patterns are combined to calculate the robustness dimension. A two-dimensional use case optimization decision space is constructed based on the quality and robustness dimensions. Within this decision space, the quality and robustness dimensions are dynamically weighted according to the priority strategy of the current testing phase, and a fitness score is calculated for each optimization individual. If the priority strategy of the current testing phase emphasizes defect discovery, the weight of the robustness dimension is increased; if it emphasizes path coverage, the weight of the quality dimension is increased. (Fitness score) The calculation can be performed based on the following relationship: in: Indicates the first The fitness score of each optimized individual Indicates the first The quality dimension value of each optimized individual is the path coverage sufficiency index. Indicates the first The robustness dimension value of each optimized individual (calculated by normalizing the number of test blind spots and the inverse of the severity of potential defect modes). and The dynamic weight coefficients are determined based on the priority strategy of the current testing phase and satisfy the following conditions: , Based on the current generation A dynamic adjustment factor is introduced to simulate annealing selection pressure.
[0037] In some embodiments, a genetic evolution mechanism is used to perform multiple rounds of evolution based on fitness scores. In each round, a certain proportion of the lowest-scoring optimized individuals are eliminated; this elimination proportion is determined by a preset selection pressure parameter. The remaining high-performing optimized individuals undergo step crossover and mutation operations. Step crossover randomly swaps parts of the test case drafts corresponding to two optimized individuals, while step mutation randomly replaces an input data value or adjusts the operation order in the test case draft of an optimized individual. New optimized individuals are generated through crossover and mutation operations to supplement the test case optimization decision space. This elimination and generation iterative process is repeated, and the fitness scores of all optimized individuals in the new dimension are recalculated after each generation. The iterative process continues until the average fitness score of the optimized individuals in the test case optimization decision space reaches a stable state. A stable state is defined as the fluctuation range of the average fitness score over three consecutive rounds of evolution being less than a preset threshold, or the iterative process reaching a preset upper limit for the number of generations. From the final generation of optimized individuals, the test case drafts corresponding to the highest-scoring optimized individuals are selected to form a final test case set. The number of selected individuals is preset based on test resource constraints.
[0038] The process involves selecting a final set of test cases and transforming it into an executable sequence of test instructions that conforms to the requirements of the target testing framework. The implementation process involves parsing each draft test case in the final test case set. The parsing operation extracts the natural language descriptions and formalized steps from the draft test cases. The natural language descriptions include the test objective statement, and the formalized steps include specific operations, inputs, and expected results. These descriptions and steps are then transformed into scripting language primitives supported by the target testing framework. For example, for Python's pytest framework, primitives might include function definitions, decorators, and assert statements; for Java's JUnit framework, primitives might include the @Test annotation and method calls. For each scripting language primitive, the corresponding assertion library function and driver library function in the target testing framework are matched. The assertion library function verifies whether the actual results match the expected results, while the driver library function simulates user operations or calls to system interfaces.
[0039] Optionally, the parameter format and data type of the function call are verified to ensure full compatibility with the input data and expected output types defined in the test case draft. Necessary test fixture initialization and data cleanup instructions are added to each scripting language primitive according to the execution logic and dependencies of the test cases. Test fixture initialization instructions are used to prepare the test environment and data, while data cleanup instructions are used to restore the environment state after test execution. The scripting language primitives, which assemble assertion library functions, driver library functions, test fixture initialization, and data cleanup instructions, are encoded into specific test script files according to the order of the test steps. Each test case draft corresponds to an independent test script file. Syntax checks and dependency resolution are performed on all generated test script files. Syntax checks ensure that the scripts conform to the language specifications of the target testing framework, and dependency resolution ensures that all external libraries and modules referenced in the scripts are correctly declared. In practice, this ultimately forms an executable test instruction sequence, which consists of a series of test script files that have passed syntax and dependency checks, and can be directly loaded by the target testing framework to drive automated test execution.
[0040] See Figure 5 This is a graph showing the evolutionary trend of test cases across multiple rounds within the decision space for software test case optimization. It clearly demonstrates the quality changes of test cases from initial to mature, with the average fitness increasing from 0.5 to 0.9, directly corresponding to a reduction in testing blind spots and enhanced defect discovery capabilities, providing quantifiable quality benefits to the business. The simultaneous increase in optimal and average fitness directly proves the effectiveness of the genetic evolution mechanism in test case optimization and can serve as a core basis for algorithm selection. A continuous decline in population diversity is a potential risk; excessive homogenization may cause the algorithm to get stuck in local optima. When diversity drops to a threshold, mutation strategies or new external test cases need to be introduced to maintain population vitality. When the optimal fitness curve flattens out, it can be determined that evolution has converged, and iteration should be stopped in time to avoid wasting computational power and balance optimization effects with resource investment.
[0041] The above embodiments are only used to illustrate the technical methods of the present invention and are not intended to limit it. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical methods of the present invention without departing from the spirit and scope of the technical methods of the present invention.
Claims
1. A method for intelligently generating software test cases based on generative AI, characterized in that, include: It receives and integrates raw input data from software requirements specifications, software system design documents, and historical defect databases, and decomposes and extracts the data to generate standardized test element feature representations. All the standardized test element feature representations are input into an interactive test case generation network for element association reasoning and feature cross-fusion. Based on the output of the interactive test case generation network, a set of key test scenarios in software functions and business rules is identified; For each scenario in the set of key test scenarios, a concurrent test case generation process is initiated to generate multiple candidate test case drafts; The completeness of each candidate test case draft is evaluated and defect patterns are marked using a historical test case library. By integrating the results of the completeness assessment and defect pattern annotation, a use case optimization decision space is constructed, and multiple rounds of use case evolution are performed within the use case optimization decision space; Based on the results of the test case evolution, a final set of test cases is selected and transformed into an executable test instruction sequence that meets the requirements of the target test framework. The executable test instruction sequence is imported into the software system's automated test management platform.
2. The intelligent generation method for software test cases based on generative AI according to claim 1, characterized in that, The generation of standardized test element feature representations includes: Receive and integrate raw input data from software requirements specification documents, software system design documents, and historical defect databases to build an initial test information knowledge base; Based on the preset test dimension division strategy, the initial test information knowledge base is decomposed and information is extracted in multiple levels to form several sets of interrelated test focus points. Semantic standardization and structured coding are performed on each set of test concerns to generate standardized test element feature representations; The initial test information knowledge base is decomposed and information extracted at multiple levels according to a preset test dimension division strategy, forming several sets of interrelated test focus points, including: Extract test dimension partitioning templates that match the current software architecture from the preset test strategy library. The test dimension partitioning templates define the functional module partitioning logic, business path traversal logic, and abnormal condition combination logic. The initial test information knowledge base is functionally divided into functional domains using the aforementioned functional module partitioning logic to generate a set of functional module test concerns. The business path traversal logic is used to extract the business process from the initial test information knowledge base, generating a set of business process test concerns. The abnormal condition combination logic is used to enumerate abnormal states in the initial test information knowledge base to generate a set of abnormal condition test concerns. A dynamic semantic association is established in the knowledge graph between the functional module test concern set, the business process test concern set, and the abnormal condition test concern set, to ensure that any change in test requirements can be synchronously updated in all relevant test concern sets.
3. The intelligent generation method for software test cases based on generative AI according to claim 2, characterized in that, The step of performing semantic standardization and structured encoding on each set of test concerns to generate standardized test element feature representations includes: Each set of test concerns is assigned an independent semantic parser, which transforms the natural language descriptions and semi-structured information within the set into a formal intermediate representation. In each set of test concerns, all test requirement items contained therein are traversed, and the original semantic features are extracted. The pre-built standardized dictionary of software engineering terminology is invoked to perform terminology normalization and ambiguity elimination on the extracted original semantic features; The normalized semantic features are input into a structured coding pipeline, which embeds the features into context and links relationships by introducing the interface contracts and state models of software system components. The output feature vector, after semantic standardization and structured encoding, serves as the feature representation of the standardized test elements.
4. The intelligent generation method for software test cases based on generative AI according to claim 3, characterized in that, The step of inputting all the standardized test element feature representations into an interactive test case generation network for element association reasoning and feature cross-fusion includes: The interactive test case generation network is initialized, which includes a shared working area for feature co-occurrence learning and multiple private generators that correspond one-to-one with the set of test concerns. Each of the private generators reads the corresponding standardized test element feature representation and preliminarily derives the local test conditions and expected results from it; All of the private generators write their respective test conditions and expected results into the shared workspace, and trigger a round of scenario completeness calculation based on causal reasoning within the shared workspace; Based on the result of the scenario completeness calculation, scenario supplementary signals and logical conflict signals are generated, and the scenario supplementary signals and logical conflict signals are broadcast to each of the private generators; Each of the private generators iteratively corrects the content derived from its standardized test element feature representation based on the received scenario supplementary signal and logical conflict signal. The process of repeatedly writing features, calculating completeness, broadcasting signals, and iteratively correcting them continues until a consensus is reached on the logical state within the shared work area, ultimately outputting a set of fully correlated and integrated global test scenario descriptions.
5. The intelligent generation method for software test cases based on generative AI according to claim 4, characterized in that, The output of the interactive test case generation network identifies a set of key test scenarios in software functions and business rules, including: The interactive test cases are parsed to generate a global test scenario description from the network output, which is then reconstructed into a virtual software behavior space. In the virtual software behavior space, a scenario complexity and change impact analysis algorithm is used to evaluate the number of logical branches, state combination complexity, and impact weight on core business for each scenario. Based on the evaluation results, all scenarios are sorted, and scenarios with high complexity and high impact weight are selected and marked as high-priority candidate scenarios. Dependency analysis is performed on the high-priority candidate scenarios to trace their dependent basic functional scenarios and associated abnormal scenarios, thereby determining a complete set of key test scenarios that includes core logic and boundaries.
6. The intelligent generation method for software test cases based on generative AI according to claim 5, characterized in that, For each scenario in the set of key test scenarios, a concurrent test case generation process is initiated to generate multiple candidate test case drafts, including: For each scenario in the set of key test scenarios, create an independent generation sandbox environment. Each generation sandbox environment contains a complete formal description of the scenario and related constraint rules. In each generated sandbox environment, a series of basic test operations are selected from a predefined library of test action atoms according to a strategy; The selected basic test operations are arranged and combined according to different combinations of input data, execution order and preconditions to form an initial test step sequence; The initial test step sequence is simulated and run in the generated sandbox environment, and a built-in software behavior simulator is driven to deduce the state transition of the software system after the execution of the initial test step sequence. Record the final system state, intermediate outputs and triggering logic paths generated at the end of the simulation, and package the simulation process, the sequence of initial test steps used and the simulation results to form a draft of the candidate test cases.
7. The intelligent generation method for software test cases based on generative AI according to claim 6, characterized in that, The step of using a historical test case library to perform a completeness assessment and defect pattern annotation on each candidate test case draft includes: Extract the structural features of each candidate test case draft, including the coverage of test steps, the boundary values of input data, and the depth of state transitions; The structural features are vectorized and pattern matching is performed in the historical test case library to find all historically executed test case records that are structurally similar and have known execution results. For each of the retrieved executed test case records, extract the code paths covered during its actual execution, the types of defects discovered, and the information on any missing defects. The path coverage sufficiency index of the candidate test case draft is calculated by comparing the inferred coverage path of the candidate test case draft with the actual coverage path of the executed test case record. By analyzing the defect information found and missed in the executed test case records, the test blind spots and potential defect patterns of the candidate test case drafts are identified. The path coverage sufficiency index, along with the test blind spots and potential defect patterns, are used as tags and attached to the corresponding candidate test case drafts to complete the completeness assessment and defect pattern labeling.
8. The intelligent generation method for software test cases based on generative AI according to claim 7, characterized in that, The results of the completeness assessment and defect pattern annotation are integrated to construct a use case optimization decision space, and multiple rounds of use case evolution are performed within the use case optimization decision space, including: Each candidate test case draft is treated as an optimization individual, with its path coverage sufficiency index as the quality dimension and its number of test blind spots and the inverse of the severity of potential defect patterns as the robustness dimension, to construct a two-dimensional test case optimization decision space. In the use case optimization decision space, the quality dimension and robustness dimension are dynamically weighted according to the priority strategy of the current testing phase, and the fitness score of each optimization individual is calculated. Based on the fitness score, a genetic evolution mechanism is used to carry out multiple rounds of evolution: in each round, a certain proportion of the optimized individuals with the lowest scores are eliminated, and the remaining optimized individuals are subjected to step crossover and mutation operations to generate new optimized individuals to supplement the use case optimization decision space. Repeat the elimination and generation iterative process until the average fitness score of the optimized individuals in the use case optimization decision space reaches a stable state, or reaches a preset number of evolutionary generations; From the final generation of optimized individuals, select the test case drafts corresponding to the multiple optimized individuals with the highest fitness scores to form a final set of test cases.
9. The intelligent generation method for software test cases based on generative AI according to claim 8, characterized in that, The process of selecting a final set of test cases and converting it into an executable sequence of test instructions that conforms to the requirements of the target testing framework includes: Each test case draft in the final test case set is parsed, and its natural language description and formalization steps are transformed into script language primitives supported by the target testing framework. For each of the scripting language primitives, match the corresponding assertion library function and driver library function in the target testing framework, and verify the parameter format and data type of the function call; Based on the execution logic and dependencies of the test cases, add necessary test fixture initialization and data cleanup instructions to each of the scripting language primitives; The script language primitives, which consist of assertion library functions, driver library functions, test fixture initialization, and data cleanup instructions, are encoded into specific test script files in the order of the test steps. All generated test script files undergo syntax checks and dependency resolution to ensure that the scripts can be correctly loaded and executed by the target testing framework, ultimately forming the executable test instruction sequence.
10. A software test case intelligent generation system based on generative AI, comprising a memory, a processor, and a computer program stored in the memory and running on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the intelligent generation method for software test cases based on generative AI as described in any one of claims 1 to 9.