Test case generation method and device, equipment and medium

By generating initial test cases through large models and combining them with automated coverage analysis and reinforcement learning mechanisms, the test case generation strategy is optimized, solving the problems of traditional automated testing being time-consuming, labor-intensive and having low coverage, and achieving efficient automated testing.

CN120653571APending Publication Date: 2025-09-16JINAN INSPUR DATA TECH CO LTD
View PDF 0 Cites 7 Cited by

Patent Information

Application Number
CN202510925751.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-04
Publication Date
2025-09-16

AI Technical Summary

Technical Problem

Traditional automated testing methods rely on manual design and writing of test cases, which consumes a lot of manpower and time, making it difficult to achieve comprehensive test scenario coverage. In particular, abnormal scenarios and boundary conditions are easily missed, resulting in low test coverage and difficulty in timely detection of potential deep-seated software defects.

Method used

Initial test cases are generated through large models, combined with structured data processing and automated coverage analysis, to optimize the test case generation strategy, use reinforcement learning mechanisms to improve test efficiency and quality, and achieve automated testing.

Benefits of technology

Generate a large number of high-quality test cases in a short period of time, save time and labor costs, speed up automated testing, improve test coverage and problem discovery capabilities, and shorten the software development cycle.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120653571A_ABST
    Figure CN120653571A_ABST
Patent Text Reader

Abstract

The invention discloses a test case generation method and device, equipment and a medium, and relates to the technical field of software testing, and the test case generation method comprises the following steps: storing request data subjected to structured processing into a seed case library; the request data are various types of request data in the operation process of the service system; determining a cue word according to the target information based on the large model, and generating an initial test case through the cue word and a generation rule; the target information comprises characteristics of request data in the seed case library, an interface document of the tested software and a business logic specification; executing the initial test case according to the test request of the tested software, performing statistical analysis on the code coverage rate of the tested software in the execution process, and screening the initial test case according to an analysis result to obtain a screened test case; and after the execution is finished, filtering the screened test cases according to the first execution result of each test case to obtain a target test case. Therefore, the testing efficiency and quality can be improved, and automatic testing is achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of software testing, and in particular to a test case generation method, device, equipment and medium. Background Art

[0002] As software systems continue to grow in size and complexity, software testing faces unprecedented challenges. Traditional automated testing methods rely heavily on manual design and writing of test cases, which not only consumes significant manpower and time, but also struggles to achieve comprehensive test scenario coverage. Abnormal scenarios and edge cases are particularly prone to being missed, resulting in low test coverage and difficulty uncovering potential deep-seated software defects.

[0003] While fuzzing technology can partially address the shortcomings of traditional testing methods, verifying program reliability through random data input and effectively identifying anomalies and vulnerabilities, it also has its limitations. Generating high-quality random test cases is a key challenge in fuzzing testing. This often requires testers to perform complex modeling and algorithm design to match the characteristics of the object under test, a tedious and costly process. Meanwhile, large models have demonstrated remarkable capabilities in text generation, offering new insights into automated testing. However, test cases generated directly from large models suffer from poor fit with business scenarios and insufficient data validity, requiring further optimization and adjustment to meet the needs of actual automated testing.

[0004] It can be seen that how to improve test efficiency and quality and realize automated testing is a problem that technical personnel in this field need to solve. Summary of the Invention

[0005] The purpose of the embodiments of the present invention is to provide a test case generation method, apparatus, device, and medium that can improve test efficiency and quality, enhance test coverage and problem discovery capabilities, and implement automated testing through innovative test case generation and optimization strategies. The specific solution is as follows:

[0006] In a first aspect, the present invention discloses a test case generation method, comprising:

[0007] The structured request data is stored in the seed use case library; the request data refers to various request data during the operation of the business system;

[0008] Based on the big model, prompt words are determined according to the target information to generate initial test cases through prompt words and generation rules; the target information includes the characteristics of the request data in the seed case library, the interface documentation of the tested software, and the business logic specifications;

[0009] Execute the initial test cases according to the test request of the software under test, and perform statistical analysis on the code coverage of the software under test during the execution process. Filter the initial test cases based on the corresponding analysis results to obtain filtered test cases;

[0010] After the execution is completed, the screened test cases are filtered according to the first execution result of each test case to obtain the target test cases.

[0011] Optionally, before storing the structured request data in the seed use case library, the following is also included:

[0012] Capture various request data during the operation of the business system through the traffic platform; request data includes any one or a combination of resource path, parameter structure, user identity information, request source, and content type;

[0013] Filter and clean the request data to obtain processed data;

[0014] The processed data is converted into structured data through regular expression matching and data type verification operations to obtain structured processed request data.

[0015] Optionally, prompt words are determined based on the target information based on the large model to generate initial test cases using the prompt words and generation rules, including:

[0016] Based on the big model, prompt words are determined according to the characteristics of the request data in the seed use case library, the interface documentation of the tested software, and the business logic specifications. The structure of the prompt words includes the format definition of the test case, the value range and legal format of the parameters determined according to the business scenario, and the description of the relationship between parameters in the specific business process, preconditions and postconditions.

[0017] Generate initial test cases using prompt words, user-provided interface information, and generation rules; the interface information includes parameter templates and the number of test cases generated;

[0018] Among them, the generation rules include that the length of the non-MVEL expression field is less than or equal to the target length; if there are only numbers in the string of the non-MVEL expression field, then any string that can be expressed as a pure number is generated, otherwise any string containing a combination of numbers, letters and characters is generated; if there is a field in the target format, then the corresponding value is generated according to the expression logic in the target format; and in the generated test cases, the test cases whose single field value repetition rate is greater than the target threshold are discarded, and new test cases are regenerated until the total number of test cases is equal to the number of generated test cases set in the interface information.

[0019] Optionally, before executing the initial test case according to the test request of the software under test, it also includes:

[0020] Extract key information of seed use cases from the seed use case library; key information includes any one or a combination of interface address, request method, request header, and request body;

[0021] Assemble key information according to the interface specification of the software under test to generate a test request for the software under test.

[0022] Optionally, during the execution process, statistical analysis is performed on the code coverage of the software under test, and initial test cases are screened based on the corresponding analysis results to obtain screened test cases, including:

[0023] During the execution process, the code coverage of the tested software is statistically analyzed to obtain the corresponding analysis results; code coverage includes line coverage and branch coverage;

[0024] Determine target test cases whose code coverage is greater than or equal to the preset coverage based on the analysis results, mark the target test cases, and save them to the seed test case library;

[0025] Send test cases whose code coverage is less than the preset coverage to the big model so that the big model can determine new generation conditions and constraints based on the test cases, regenerate new test cases, and execute the new test cases;

[0026] Perform statistical analysis on the code coverage of new test cases during execution;

[0027] If the code coverage of the new test case is less than the preset coverage, the process jumps back to the step of sending the test case with code coverage less than the preset coverage to the large model until the code coverage of the new test case is greater than or equal to the preset coverage.

[0028] Optionally, filter the screened test cases based on the first execution result of each test case to obtain target test cases, including:

[0029] Determine the first execution result of the test case as the test case benchmark assertion;

[0030] Compare and analyze the remaining execution results of the test case based on the use case benchmark assertion;

[0031] If the execution result is different from the test case benchmark assertion, it is determined that there is a problem with the test case;

[0032] If the execution result is the same as the test case benchmark assertion, it is determined that there is no problem with the test case;

[0033] Filter the test cases with problems to obtain target test cases without problems.

[0034] Optionally, the test case generation method further includes:

[0035] In the process of generating target test cases, a reward function is constructed based on the code coverage and the quality of the generated test cases. The quality of the generated test cases indicates whether there are any problems with the test cases.

[0036] Train the pre-built initial deep Q network using the reward function and the target number of initial test cases to obtain the target deep Q network;

[0037] Generate optimized test cases based on the prompt words through the target deep Q network.

[0038] In a second aspect, the present invention discloses a test case generating device, comprising:

[0039] The request data storage module is used to store the structured request data into the seed use case library; the request data refers to various request data during the operation of the business system;

[0040] The initial test case generation module is used to determine prompt words based on the target information based on the large model, and to generate initial test cases using the prompt words and generation rules; the target information includes the characteristics of the request data in the seed case library, the interface documentation of the software under test, and the business logic specifications;

[0041] The screening module is used to execute the initial test cases according to the test request of the software under test, and perform statistical analysis on the code coverage of the software under test during the execution process, and screen the initial test cases according to the corresponding analysis results to obtain the screened test cases;

[0042] The target test case acquisition module is used to filter the screened test cases according to the first execution results of each test case after the execution is completed to obtain the target test case.

[0043] In a third aspect, the present invention discloses an electronic device, comprising:

[0044] memory for storing computer programs;

[0045] A processor is used to execute a computer program to implement the test case generation method as described above.

[0046] In a fourth aspect, the present invention discloses a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the test case generation method as described above is implemented.

[0047] In the present invention, the structured request data is first stored in a seed case library; the request data is various request data during the operation of the business system; prompt words are determined based on the target information based on the large model, so as to generate initial test cases through the prompt words and generation rules; the target information includes the characteristics of the request data in the seed case library, the interface documents and business logic specifications of the tested software; the initial test cases are executed according to the test requests of the tested software, and the code coverage of the tested software is statistically analyzed during the execution process, and the initial test cases are screened according to the corresponding analysis results to obtain screened test cases; after the execution is completed, the screened test cases are filtered according to the first execution results of each test case to obtain the target test cases.

[0048] Beneficial effects: With the help of the efficient text generation capability of the large model, the present invention can generate a large number of test cases in a short period of time. Compared with the traditional method of manually writing test cases, it greatly saves time and labor costs, speeds up the execution speed and frequency of automated testing, and enables the testing team to discover defects and problems in the software more promptly, shortening the software development cycle. With the help of automated coverage acquisition tools or technologies, the code coverage of the tested software is monitored and counted in real time, and the weak links and uncovered code areas of the test are accurately located, providing data support and direction guidance for optimizing the test case generation strategy, and realizing the continuous improvement and perfection of the test cases. In this way, through innovative test case generation and optimization strategies, the test efficiency and quality are improved, the test coverage and problem discovery capabilities are enhanced, and automated testing is realized. BRIEF DESCRIPTION OF THE DRAWINGS

[0049] In order to more clearly illustrate the embodiments of the present invention, the following is a brief introduction to the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0050] Figure 1 A flow chart of a test case generation method provided by an embodiment of the present invention;

[0051] Figure 2 A schematic diagram of a test case generation method provided by an embodiment of the present invention;

[0052] Figure 3 A schematic diagram of the structure of a test case generation device provided by an embodiment of the present invention;

[0053] Figure 4 A structural diagram of an electronic device provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0054] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of them. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making any creative efforts shall fall within the scope of protection of the present invention.

[0055] The terms "including" and "having," as used in the present description and accompanying drawings, and any variations thereof, are intended to cover non-exclusive inclusions. For example, a process, method, system, product, or apparatus comprising a series of steps or elements is not limited to the listed steps or elements and may include steps or elements that are not listed.

[0056] In order to enable those skilled in the art to better understand the present invention, the present invention will be further described in detail below with reference to the accompanying drawings and specific implementation methods.

[0057] Traditional automated testing methods rely too much on manually designing and writing test cases, which not only consumes a lot of manpower and time, but also makes it difficult to achieve comprehensive test scenario coverage. In particular, abnormal scenarios and edge cases are easily missed, resulting in low test coverage and difficulty in timely uncovering potential deep-seated software defects. To address the above technical problems, the present invention discloses a test case generation method, device, equipment and medium. These methods can improve test efficiency and quality, enhance test coverage and problem discovery capabilities, and achieve automated testing through innovative test case generation and optimization strategies.

[0058] See also Figure 1 As shown, an embodiment of the present invention provides a test case generation method, comprising:

[0059] Step S11: storing the structured request data in the seed use case library; the request data refers to various request data during the operation of the business system.

[0060] Before storing the structured request data in the seed use case library, the present invention first needs to capture various request data during the operation of the business system through the traffic platform; the request data includes any one or a combination of resource path, parameter structure, user identity information, request source, and content type; the request data is filtered and cleaned to obtain processed data; and the processed data is converted into structured format data through regular expression matching and data type verification operations to obtain the structured request data. Specifically, the traffic platform comprehensively captures various request data during the operation of the real business system. This data covers different business scenarios and operation types and includes complete request details, such as the request URL (accurate to the specific resource path and parameter structure), the request header (including key fields such as user identity information, request source, content type), and the request method (clearly distinguishing between operation methods such as GET, POST, PUT, and DELETE). A series of predefined rules are used to strictly filter and clean the captured data. For example, duplicate requests are removed based on business rules, and data that does not conform to business logic (such as parameter values ​​that clearly exceed a reasonable range, illegal character encodings, etc.) is filtered out. Sensitive information (such as user passwords, ID numbers, etc.) is desensitized to ensure data security and validity. Through technical means such as regular expression matching and data type verification, each field is carefully checked, and key information that meets the requirements is retained. This information is organized into a structured data format and stored in a seed case library, providing high-quality initial material for subsequent test case generation. The seed case library is managed using a database or distributed storage system to facilitate data retrieval, updating, and maintenance, ensuring data integrity and availability. In this way, various types of request data during the operation of the real business system are captured through the traffic platform. After filtering and cleaning, the key information that meets the requirements is organized into a structured data format and stored in the seed case library, providing high-quality initial material for subsequent test case generation.

[0061] Step S12: Determine prompt words based on the target information based on the large model to generate initial test cases through the prompt words and generation rules; the target information includes the characteristics of the request data in the seed case library, the interface documentation and business logic specifications of the software under test.

[0062] In an embodiment of the present invention, after storing the structured request data in the seed use case library, a macro model can be used as a basis to conduct an in-depth analysis of the interface documentation, business logic specifications, and data features of the software under test in the seed use case library, and carefully design prompts. The macro model includes, but is not limited to, the DeepSeek model. Based on the macro model, prompts are determined based on the features of the request data in the seed use case library, the interface documentation, and business logic specifications of the software under test. The structure of the prompt includes the format definition of the test case, the range of parameter values ​​determined based on the business scenario, the legal format, and the description of the relationship between parameters in a specific business process, as well as preconditions and postconditions. In other words, the Prompt structure includes test case format definitions (such as the nested structure of JSON (JavaScript Object Notation, JS key-value data), field name and type specifications, etc.), data content requirements (determining the parameter value range and legal format based on the business scenario), business semantic constraints (for example, describing the relationship between parameters in a specific business process, preconditions and postconditions, etc.). It also introduces MVEL template language rules to make prompts more expressive and logical, and can accurately guide the DeepSeek model to generate random content input that meets expectations. Ultimately, the initial test case is generated through the prompt, user-provided interface information, and generation rules; the interface information includes parameter templates and the number of test cases generated. And among them, the generation rules include that the length of the non-MVEL expression field is less than or equal to the target length, if there are only numbers in the string of the non-MVEL expression field, then any string that can be expressed as a pure number is generated, otherwise any string containing a combination of numbers, letters and characters is generated, if there is a field in the target format, then the corresponding value is generated according to the expression logic in the target format, and in the generated test cases, the test cases whose single field value repetition rate is greater than the target threshold are discarded, and new test cases are regenerated until the total number of test cases is equal to the number of generated test cases set in the interface information.

[0063] Specifically, the prompt template provides the user with an interface specification and generates high-quality test data based on the specified interface information according to the following rules: The interface specification data format is {"paramTemplate":{}, "CasesNum":0}, where the fields represent the parameter template and the number of test cases to be generated. The paramTemplate content is used as the test parameter, and test data is generated accordingly. CasesNum is used as the number of test data items to be generated. The generation rules are prioritized according to the following conditions:

[0064] Repetition rate control: If the repetition rate of a single field value exceeds a threshold of 40% across all generated data, the data that currently exceeds the threshold is discarded and regenerated to ensure that the total number of use cases remains within the set {generateNum}. This approach prioritizes and emphasizes repetition rate control rules, ensuring that the core requirements of generated data quality are prioritized and met.

[0065] Non-MVEL expression field generation rules: {"type":"String","rule":["rule1. Length does not exceed 40 digits","rule2. If the string contains only numbers, generate any string that can be represented as a pure number","rule3. If rule 2 is not met, any string containing numbers, letters, or character combinations can be generated"]}. Other types (such as Int, Boolean, etc.) should also follow corresponding reasonable generation rules. For example, the Int type needs to generate different values ​​within a reasonable range. In this way, other types of non-MVEL expression fields (such as Int, Boolean, etc.) are supplemented with reasonable associations to make the rules more comprehensive and avoid generating illogical data.

[0066] Rule-free data generation rules: When there are no clear, specific rules, common values ​​that meet basic characteristics are generated based on the field type to ensure data diversity and validity. This clearly defines the triggering conditions and execution methods of the catch-all generation rules, ensuring that valid data can still be generated even in the absence of clear, specific rules.

[0067] MVEL expression field generation rules: If there is a field format of "value": "MVEL( )", the value range is considered to be all values ​​that meet the expression expression, and the corresponding value is generated strictly according to the logic of this expression. Test data output format: {"generatedParams":[{"param":{}},{"param":{}}]}. Test data output requirements: The generated test data is stored in the array generatedParams; only minified json, no explanatory text is allowed to appear, and the output content is ensured to be only JSON format data. The large model does not need to reply after understanding the above requirements. It waits for the user to provide valid interface information (including paramTemplate), and then generates accurate test data results based on this. In this way, the relevant rules of MVEL expressions are described more rigorously, emphasizing that the values ​​are generated strictly according to the expression logic to ensure data accuracy. And once again emphasize the purity of the output format and content to avoid usage problems caused by format or redundant text. In general, the present invention uses an automated execution platform to parse, adapt, assemble and execute the generated test cases, and uses the first execution result as a use case benchmark assertion to provide a reference basis for subsequent regression testing, etc. At the same time, the execution results are output through visualization tools, which is convenient for testers to intuitively observe and analyze the test situation and promptly discover potential problems and risks.

[0068] Step S13: Execute the initial test case according to the test request of the software under test, perform statistical analysis on the code coverage of the software under test during the execution process, filter the initial test case according to the corresponding analysis results, and obtain filtered test cases.

[0069] In an embodiment of the present invention, after obtaining the initial test case output by the large model, the initial test case can be executed. However, before executing the initial test case, key information of the seed case in the seed case library must be extracted. Key information includes any one or a combination of the interface address, request method, request header, and request body. This key information is assembled according to the interface specification of the software under test to generate a test request for the software under test. The present invention utilizes an automated execution platform to first conduct in-depth analysis of the generated test case, extracting key information such as the interface address, request method, request header, and request body. This information is then adapted and assembled according to the interface specification of the software under test to generate a complete test request. For example, for a RESTful interface, the request is constructed according to the standard HTTP (Hypertext Transfer Protocol) protocol format to ensure the correctness and standardization of the request. Simultaneously, the test case is parameterized, and dynamic parameters (such as timestamps and random numbers) are identified and managed. This allows for real-time replacement and updating during execution based on actual conditions, improving the flexibility and adaptability of the test case.

[0070] At the same time, during the execution process, the code coverage of the software under test is statistically analyzed to obtain corresponding analysis results; the code coverage includes line coverage and branch coverage; based on the analysis results, the target test cases with code coverage greater than or equal to the preset coverage are determined, the target test cases are marked, and saved to the seed case library; the test cases with code coverage less than the preset coverage are sent to the big model, so that the big model can determine new generation conditions and constraints based on the test cases, regenerate new test cases, and execute the new test cases; during the execution process, the code coverage of the new test cases is statistically analyzed; if the code coverage of the new test cases is less than the preset coverage, the process jumps back to the step of sending the test cases with code coverage less than the preset coverage to the big model, until the code coverage of the new test cases is greater than or equal to the preset coverage. The present invention introduces an automated coverage acquisition tool or technology to monitor and count the code coverage of the software under test in real time. By analyzing the coverage data, the coverage of the code by the current test case is understood, including important indicators such as line coverage and branch coverage, so as to find the weak links and uncovered code areas in the test process, and provide data support and direction guidance for the subsequent optimization of the test case generation strategy. According to the coverage analysis results, the generated test cases are screened and marked to find those test cases that can effectively improve the code coverage, as well as those that contribute less to the coverage improvement or are redundant. The effective test cases are marked and retained so that they can be executed as the focus in subsequent tests, while invalid or inefficient test cases are optimized or eliminated, thereby improving the utilization efficiency of test resources and ensuring that the test process is more efficient and accurate. Based on coverage feedback, a cyclic optimization mechanism is established to feed back information about code areas where coverage does not meet the target requirements to the large model. This information serves as new generation conditions and constraints, guiding the large model to regenerate test cases for these weak areas, execute the test again, and collect coverage data. This process is repeated until the code coverage approaches the preset target (such as 70%-80%). In this way, continuous optimization and improvement of test cases are achieved, so that test cases can better cover all functional points and code paths of the software under test, thereby improving the overall quality and reliability of software testing.

[0071] In addition, the present invention can also perform incremental coverage analysis, which only analyzes the coverage of changed code in continuous integration to reduce the amount of calculation. Incremental coverage analysis is an efficient method for optimizing test resources, and is particularly suitable for continuous integration environments. This technology compares changes in the code base with historical coverage reports, and only calculates coverage for newly added or modified code lines / branches, rather than a full scan. For example, in a Java project, JaCoCo's diff-coverage plug-in can be integrated with Maven / Gradle to automatically filter coverage data for unchanged files, reducing analysis time from hours to minutes. In practice, it is necessary to combine code version management tools (such as Git) to identify the scope of changes, and implement card point interception through threshold control (such as the coverage of new code lines must be ≥80%). This focused analysis can not only quickly feedback code quality, but also avoid the waste of resources of traditional full statistics, and is particularly suitable for agile development scenarios with high-frequency iterations.

[0072] Step S14: After the execution is completed, the screened test cases are filtered according to the first execution result of each test case to obtain the target test case.

[0073] In an embodiment of the present invention, after executing a test case, the first execution result of the test case is determined as the test case benchmark assertion; the remaining execution results of the test case are compared and analyzed based on the test case benchmark assertion; if the execution result is different from the test case benchmark assertion, the test case is determined to have a problem; if the execution result is the same as the test case benchmark assertion, the test case is determined to have no problem; and the test cases with problems are filtered to obtain target test cases without problems. In other words, a preliminary analysis and judgment is performed based on the results, and the result of the first execution of each test case is used as the test case benchmark assertion to provide a reference for subsequent regression testing, etc. At the same time, the execution results are output to a visualization tool, which facilitates testers to intuitively observe and analyze the test situation and promptly identify potential problems and risks. To address the uncertainty of test execution results, the first execution result is written back as the use case benchmark assertion. Subsequent executions can be compared and analyzed based on this. Differences found may indicate potential problems. Test results are filtered according to system-defined rules to screen out potential risk issues, reduce the workload of manual inspection, improve the efficiency and accuracy of problem discovery, and enable testers to focus more on in-depth analysis and resolution of valid issues.

[0074] Beneficial effects: With the help of the efficient text generation capability of the large model, the present invention can generate a large number of test cases in a short period of time. Compared with the traditional method of manually writing test cases, it greatly saves time and labor costs, speeds up the execution speed and frequency of automated testing, and enables the testing team to discover defects and problems in the software more promptly, shortening the software development cycle. With the help of automated coverage acquisition tools or technologies, the code coverage of the tested software is monitored and counted in real time, and the weak links and uncovered code areas of the test are accurately located, providing data support and direction guidance for optimizing the test case generation strategy, and realizing the continuous improvement and perfection of the test cases. In this way, through innovative test case generation and optimization strategies, the test efficiency and quality are improved, the test coverage and problem discovery capabilities are enhanced, and automated testing is realized.

[0075] Based on the above embodiment, the present invention discloses a test case generation method, such as Figure 2 As shown, the traffic platform first captures all types of request data from real business systems. This captured data is then rigorously filtered and cleaned using a series of predefined rules. Using techniques such as regular expression matching and data type verification, each field is meticulously checked, retaining key information that meets the requirements. This information is then organized into a structured data format and stored in a seed case library, providing high-quality initial material for subsequent test case generation.

[0076] Next, through continuous design and optimization of prompts, we adopted a structured, concise description method that aligns with the logic of the large model, such as introducing MVEL template language rules. By optimizing prompts, we accurately guide the large model to generate test cases that meet expectations, covering elements such as format, content, data type, and business semantics. This ensures that the generated test cases precisely align with the software interfaces or functional modules under test. This is the core key to achieving high-quality automatic test case generation, effectively addressing the time-consuming and labor-intensive manual test case writing of traditional testing methods, which is prone to poor business scenario fit. We also combined the randomness of fuzzing with the content generation capabilities of the large model. Using the large model, we generate a large number of random but valid test cases as input data for fuzzing testing, overcoming the bottleneck of traditional fuzzing testing in random case generation, achieving deep and multi-faceted test coverage of the software, and improving testing efficiency and effectiveness.

[0077] Furthermore, by introducing an automated coverage collection and feedback mechanism, using automated coverage collection tools or techniques, the code coverage of the software under test can be monitored and calculated in real time, including key metrics such as line coverage and branch coverage. Through in-depth analysis of coverage data, weak links and uncovered code areas in the testing process can be accurately identified, providing data support and guidance for optimizing test case generation strategies. This allows testers to clearly understand the current status of test coverage and strengthen testing efforts in a targeted manner. Based on the coverage analysis results, generated test cases are screened and marked to distinguish high-quality cases that can effectively improve code coverage from those that contribute less or are redundant. Based on positive coverage feedback, a loop optimization mechanism is established. Information about code areas that fail to achieve the target coverage is fed back to the large model as new generation conditions and constraints, guiding it to regenerate test cases targeting weak areas, re-execute the test, and collect coverage data. This process is repeated until the code coverage approaches the preset target (e.g., 70%-80%). Through this cyclical optimization approach, test cases are continuously improved and refined, ensuring comprehensive coverage of the functional points and code paths of the software under test, comprehensively enhancing the quality and reliability of software testing. Finally, a reinforcement learning mechanism is introduced into the test case generation process, carefully designing reward functions based on key indicators such as the quality, coverage, and execution efficiency of generated test cases. This allows the system to automatically learn and optimize test case generation strategies based on reward signals during the continuous generation and execution process. The reinforcement learning mechanism adjusts the parameters and behavior of the generation model in real time based on test result feedback, continuously trialing and improving, and gradually mastering the rules and methods for generating high-quality, high-coverage, and high-efficiency test cases, thereby further improving the quality and effectiveness of test cases.

[0078] Specifically, during the process of generating target test cases, the present invention constructs a reward function based on code coverage and the quality of generated test cases. The quality of generated test cases indicates whether the test cases have issues. A pre-built initial deep Q-network is trained using the reward function and a target number of initial test cases to obtain a target deep Q-network. The target deep Q-network then generates optimized test cases based on prompts. This invention introduces a reinforcement learning mechanism, enabling the entire system to automatically learn and optimize test case generation strategies based on test result feedback. Specifically, a carefully designed reward function comprehensively considers key metrics such as the quality, coverage, and execution efficiency of generated test cases. For example, a high positive reward is awarded when a generated test case successfully discovers a new vulnerability in the software, significantly improves code coverage, or completes a large number of valid tests in a short execution time. Conversely, a negative reward is awarded when the generated test case is of poor quality, contributes little to coverage, or has low execution efficiency. The Deep Q-Network (DQN) algorithm is used as the core reinforcement learning algorithm. The Deep Q Network is trained by continuously having the agent (i.e., the test case generation system) perform actions (i.e., adjusting prompts to generate test cases and executing tests) in the environment (i.e., throughout the entire software testing process), collecting state transition data and corresponding reward signals. Initially, the system generates and executes test cases based on pre-designed prompt templates and some basic rules, collecting initial data samples. As testing progresses, the agent selects actions based on the current state, adjusting prompt parameters to generate new test cases. The test is then executed again to obtain new states and reward feedback, which are then added to the experience replay pool. During training, small batches of data samples are periodically randomly sampled from the experience replay pool to update the parameters of the Deep Q Network. This allows the network to gradually learn the optimal action selection under different states, i.e., the optimal prompt adjustment strategy, thereby generating higher-quality, higher-coverage, and more efficient test cases.

[0079] Beneficial effects: The present invention introduces a reinforcement learning mechanism in the test case generation process, and carefully designs a reward function based on key indicators such as the quality, coverage, and execution efficiency of the generated test cases. During the continuous generation and execution process, the system automatically learns and optimizes the test case generation strategy based on the reward signal, further improving the quality and effectiveness of the test cases.

[0080] See also Figure 3 As shown, an embodiment of the present invention provides a test case generation device, comprising:

[0081] The request data storage module 11 is used to store the structured request data into the seed use case library; the request data is various request data during the operation of the business system;

[0082] The initial test case generation module 12 is used to determine prompt words based on the target information based on the large model, and generate initial test cases through the prompt words and generation rules; the target information includes the characteristics of the request data in the seed case library, the interface documentation of the tested software, and the business logic specifications;

[0083] The screening module 13 is used to execute the initial test cases according to the test request of the software under test, and perform statistical analysis on the code coverage of the software under test during the execution process, and screen the initial test cases according to the corresponding analysis results to obtain screened test cases;

[0084] The target test case acquisition module 14 is used to filter the screened test cases according to the first execution results of each test case after the execution is completed to obtain the target test case.

[0085] Since the embodiments of the device part correspond to the above embodiments, the embodiments of the device part please refer to the description of the embodiments of the method part, and will not be repeated here.

[0086] Beneficial effects: With the help of the efficient text generation capability of the large model, the present invention can generate a large number of test cases in a short period of time. Compared with the traditional method of manually writing test cases, it greatly saves time and labor costs, speeds up the execution speed and frequency of automated testing, and enables the testing team to discover defects and problems in the software more promptly, shortening the software development cycle. With the help of automated coverage acquisition tools or technologies, the code coverage of the tested software is monitored and counted in real time, and the weak links and uncovered code areas of the test are accurately located, providing data support and direction guidance for optimizing the test case generation strategy, and realizing the continuous improvement and perfection of the test cases. In this way, through innovative test case generation and optimization strategies, the test efficiency and quality are improved, the test coverage and problem discovery capabilities are enhanced, and automated testing is realized.

[0087] Furthermore, the embodiment of the present application also discloses an electronic device, Figure 4 This is a structural diagram of an electronic device according to an exemplary embodiment. The content in the diagram should not be considered as any limitation on the scope of use of this application. The electronic device may specifically include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 is used to store a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the test case generation method disclosed in any of the aforementioned embodiments. In addition, the electronic device in this embodiment may specifically be an electronic computer.

[0088] In this embodiment, the power supply 23 is used to provide operating voltage for various hardware devices on the electronic device; the communication interface 24 can create a data transmission channel between the electronic device and external devices. The communication protocol it follows is any communication protocol that can be applied to the technical solution of this application and is not specifically limited here; the input and output interface 25 is used to obtain external input data or output data to the outside world. Its specific interface type can be selected according to specific application needs and is not specifically limited here.

[0089] In addition, the memory 22, as a carrier for resource storage, can be a read-only memory, random access memory, disk or CD, etc. The resources stored thereon can include an operating system 221, a computer program 222, etc., and the storage method can be temporary storage or permanent storage.

[0090] The operating system 221 is used to manage and control the hardware devices on the electronic device and the computer program 222, which can be Windows Server, Netware, Unix, Linux, etc. In addition to including a computer program capable of implementing the test case generation method executed by the electronic device disclosed in any of the aforementioned embodiments, the computer program 222 can further include a computer program capable of implementing other specific tasks.

[0091] Furthermore, this application also discloses a computer-readable storage medium for storing a computer program; wherein, when executed by a processor, the computer program implements the test case generation method disclosed above. The specific steps of this method can be referred to the corresponding content disclosed in the above embodiments and will not be repeated here.

[0092] Furthermore, this application also discloses a computer program product, including a computer program / instructions; wherein, when executed by a processor, the computer program / instructions implement the aforementioned test case generation method. The specific steps of this method can be referred to the corresponding contents disclosed in the aforementioned embodiments and will not be repeated here.

[0093] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from the other embodiments. Reference can be made to the descriptions of the identical or similar parts between the various embodiments. For the devices disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the descriptions are relatively simple, and the relevant parts can be referred to the descriptions of the methods.

[0094] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the above description has generally described the components and steps of each example according to their functions. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0095] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in random access memory (RAM), internal memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.

[0096] Finally, it should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of additional identical elements in the process, method, article, or device comprising the element.

[0097] The above is a detailed introduction to the technical solution provided by the present application. Specific examples are used herein to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for those skilled in the art, according to the ideas of the present application, there may be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.

Claims

1. A test case generation method, characterized in that: include: Store the structured request data into the seed use case library; The request data refers to various request data during the operation of the business system; Determining prompt words according to target information based on the large model, so as to generate initial test cases through the prompt words and generation rules; The target information includes the characteristics of the request data in the seed use case library, the interface documentation and business logic specifications of the software under test; Executing the initial test cases according to the test request of the software under test, and performing statistical analysis on the code coverage of the software under test during the execution process, screening the initial test cases according to the corresponding analysis results, and obtaining screened test cases; After the execution is completed, the screened test cases are filtered according to the first execution result of each test case to obtain the target test case.

2. The test case generation method according to claim 1, characterized in that: Before storing the structured request data into the seed use case library, the method further includes: Capture various request data during the operation of the business system through the traffic platform; the request data includes any one or a combination of resource path, parameter structure, user identity information, request source, and content type; Filtering and cleaning the request data to obtain processed data; The processed data is converted into structured format data through regular expression matching and data type verification operations to obtain structured processed request data.

3. The test case generation method according to claim 1, wherein: The step of determining prompt words based on the target information based on the large model, and generating initial test cases using the prompt words and generation rules, includes: Based on the large model, prompt words are determined according to the characteristics of the request data in the seed use case library, the interface documentation of the tested software, and the business logic specifications; wherein the structure of the prompt words includes the format definition of the test case, the value range and legal format of the parameter determined according to the business scenario, and the description of the relationship between the parameters in the specific business process, preconditions and postconditions; Generate an initial test case using the prompt word, user-provided interface information, and generation rules; the interface information includes a parameter template and the number of test cases generated; Among them, the generation rules include that the length of the non-MVEL expression field is less than or equal to the target length, if there are only numbers in the string of the non-MVEL expression field, then any string that can be expressed as a pure number is generated, otherwise any string containing a combination of numbers, letters and characters is generated, if there is a field in the target format, then the corresponding value is generated according to the expression logic in the target format, and in the generated test cases, the test cases whose single field value repetition rate is greater than the target threshold are discarded, and new test cases are regenerated until the total number of test cases is equal to the number of generated test cases set in the interface information.

4. The test case generation method according to claim 1, wherein: Before executing the initial test case according to the test request of the software under test, the method further includes: Extracting key information of the seed use case from the seed use case library; the key information includes any one or a combination of the interface address, request method, request header, and request body; The key information is assembled according to the interface specification of the software under test to generate the test request of the software under test.

5. The test case generation method according to claim 1, wherein: The step of performing statistical analysis on the code coverage of the software under test during the execution process, screening the initial test cases according to the corresponding analysis results, and obtaining screened test cases includes: During the execution process, statistical analysis is performed on the code coverage of the tested software to obtain corresponding analysis results; the code coverage includes line coverage and branch coverage; Determine target test cases whose code coverage is greater than or equal to a preset coverage based on the analysis results, mark the target test cases, and save them to the seed test case library; Sending the test cases whose code coverage is less than the preset coverage to the large model, so that the large model determines new generation conditions and constraints based on the test cases, regenerates new test cases, and executes the new test cases; Performing statistical analysis on the code coverage of the new test case during execution; If the code coverage of the new test case is less than the preset coverage, the process jumps back to the step of sending the test case with a code coverage less than the preset coverage to the large model until the code coverage of the new test case is greater than or equal to the preset coverage.

6. The test case generation method according to any one of claims 1 to 5, characterized in that: The filtering of the screened test cases according to the first execution results of each test case to obtain a target test case includes: Determining a first execution result of the test case as a use case benchmark assertion; performing comparative analysis on the remaining execution results of the test case based on the use case benchmark assertion; If the execution result is different from the test case benchmark assertion, it is determined that there is a problem with the test case; If the execution result is the same as the test case benchmark assertion, it is determined that there is no problem with the test case; Filter the test cases with problems to obtain target test cases without problems.

7. The test case generation method according to claim 1, characterized in that: Also includes: In the process of generating target test cases, a reward function is constructed based on code coverage and the quality of generated test cases; The quality of the generated test case indicates whether there is a problem with the test case; Training a pre-built initial deep Q network using the reward function and the target number of initial test cases to obtain a target deep Q network; Generate optimized test cases based on the prompt words through the target deep Q network.

8. A test case generating device, characterized in that: include: A request data storage module is used to store the structured request data into the seed use case library; The request data refers to various request data during the operation of the business system; An initial test case generation module is configured to determine prompt words based on target information based on the large model, and to generate initial test cases using the prompt words and generation rules; the target information includes characteristics of request data in the seed case library, interface documentation of the software under test, and business logic specifications; A screening module is used to execute the initial test cases according to the test request of the software under test, and perform statistical analysis on the code coverage of the software under test during the execution process, and screen the initial test cases according to the corresponding analysis results to obtain screened test cases; The target test case acquisition module is used to filter the screened test cases according to the first execution result of each test case after the execution is completed to obtain the target test case.

9. An electronic device, characterized in that: include: memory for storing computer programs; A processor, configured to execute the computer program to implement the steps of the test case generation method according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, which, when executed by a processor, implements the steps of the test case generation method according to any one of claims 1 to 7.

Citation Information

Cited By

  • Interface testing method and electronic equipment

    CN120892354A

  • An interface testing method and electronic device

    CN120892354B

  • Service test case generation method, storage medium and electronic equipment

    CN121092463A

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

    CN121636361A

  • Vehicle-mounted interaction large model test case generation enhancement method and system

    CN121743225A