Test case generation method and device based on reinforcement learning, equipment and medium

By acquiring the problem description text and standard answer code, a test case generator is generated using a large language model and consistency verification is performed in a sandbox environment. This solves the problems of poor automation and scalability in test case generation, and achieves efficient and high-quality test case generation.

CN121880200APending Publication Date: 2026-04-17PING AN TECH (SHENZHEN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
PING AN TECH (SHENZHEN) CO LTD
Filing Date
2026-01-07
Publication Date
2026-04-17

AI Technical Summary

Technical Problem

Existing technologies for test case generation suffer from poor automation and scalability in the financial and healthcare sectors, resulting in low generation efficiency and quality. In particular, the lack of standardized answer procedures makes it difficult to generate high-quality test cases.

Method used

By acquiring the problem description text and standard answer code, an executable test case generator is generated using a large language model. Consistency verification is performed in a sandbox environment to ensure the high quality and reliability of the test cases. This includes generating candidate test inputs and performing consistency verification on multiple standard answer codes, marking valid test inputs, and building test cases.

Benefits of technology

It achieves automated test case generation and high-quality output, improves generation efficiency and coverage, ensures the reliability and effectiveness of test cases, and solves the problems of poor automation and scalability in existing technologies.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121880200A_ABST
    Figure CN121880200A_ABST
Patent Text Reader

Abstract

The invention provides a test case generation method and device based on reinforcement learning, equipment and a medium, and relates to the technical field of test development. According to the method, the problem description text and the standard answer code are obtained, and the executable test case generator is generated by utilizing the large language model, so that the automation of test case generation is realized, and the tedious work of manually compiling the test case is reduced. A generator is driven to generate candidate test input through a preset test case demand, consistency verification is carried out in a sandbox environment by utilizing a plurality of standard answer codes, the generation efficiency and quality of the test case are further improved by marking effective test input and constructing the test case, and through consistency verification and a dynamic optimization mechanism, the generation efficiency and quality of the test case are improved. The quality and the coverage rate of the test case are remarkably improved, so that the generation efficiency of the test case is greatly improved while high-quality output is ensured in financial insurance application development and medical diagnosis application development scenes.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of test development technology, and in particular to a method, apparatus, device and medium for generating test cases based on reinforcement learning. Background Technology

[0002] With the increasing demand for software development automation, large language models have demonstrated significant advantages in code generation tasks, efficiently producing executable code based on natural language descriptions. Within the code reinforcement learning framework, the model obtains feedback signals through interaction with the execution environment, with the execution results of test cases serving as the core reward mechanism, directly driving the model to optimize its generation strategy. High-quality test cases must simultaneously meet the triple standards of accuracy, coverage, and discrimination to ensure effective identification of code defects and coverage of various execution scenarios. In fields with extremely high software quality requirements, such as finance and healthcare, high-quality test cases are crucial for ensuring system stability and reliability.

[0003] However, current test case generation technologies face multiple bottlenecks in the financial and medical fields: manual coding relies on expert experience, is time-consuming, and struggles to systematically handle complex boundary conditions; web scraping is limited by the scarcity and quality fluctuations of publicly available resources, failing to provide sufficient and reliable test data; generation methods based on simple mutation only randomly perturb the input, failing to meet the deep logical constraints of programming problems, resulting in low validity of the generated results; and when directly calling large language models to generate test input, the inherent uncertainty of the model often leads to format errors or constraint violations, making it difficult to guarantee output reliability. The oracle problem is particularly prominent, where the absence of a standard answer program makes it impossible to determine the expected output corresponding to the test input, causing difficulties in the test case verification process. This is especially evident in the financial and medical fields, where the complexity makes obtaining a standard answer even more challenging.

[0004] These shortcomings collectively result in a lack of automation and scalability in the test case generation process, severely hindering the improvement of efficiency and widespread application of code reinforcement learning in critical fields such as finance and healthcare. Therefore, how to improve test case generation efficiency while ensuring high-quality test case output has become an urgent technical problem to be solved. Summary of the Invention

[0005] This application provides a method, apparatus, device, and storage medium for generating test cases based on reinforcement learning, aiming to solve the technical problems of poor automation and scalability in the existing test case generation process, which leads to low efficiency and quality of test case generation, so as to improve the efficiency of test case generation while ensuring high-quality test case output.

[0006] Firstly, this application provides a test case generation method based on reinforcement learning, which includes the following steps: Obtain the problem description text of the programming problem to be tested, and at least two different standard answer codes corresponding to the problem description text; Based on the problem description text, an executable test case generator is generated using a large language model; Based on the preset test case requirements, at least one candidate test input is generated through the test case generator; In a pre-defined sandbox environment, the candidate test input is validated for consistency using at least two different standard answer codes to obtain the consistency validation result of the candidate test input. When the consistency verification result of the candidate test input is successful, the candidate test input is marked as a valid test input, and the consistency execution result corresponding to the valid test input is obtained; Based on the valid test input and the consistent execution results corresponding to the valid test input, at least one test case is constructed.

[0007] Secondly, this application also provides a test case generation device based on reinforcement learning, the test case generation device based on reinforcement learning comprising: The programming problem acquisition module is used to acquire the problem description text of the programming problem to be tested, and at least two different standard answer codes corresponding to the problem description text; The generator generation module is used to generate an executable test case generator based on the problem description text and using a large language model. The candidate test input generation module is used to generate at least one candidate test input based on preset test case requirements through the test case generator. The consistency verification module is used to perform consistency verification on the candidate test input in a preset sandbox environment using at least two different standard answer codes, and obtain the consistency verification result of the candidate test input. The valid test input determination module is used to mark the candidate test input as a valid test input when the consistency verification result of the candidate test input is that the verification is passed, and to obtain the consistency execution result corresponding to the valid test input; The test case generation module is used to construct at least one test case based on the valid test input and the consistent execution result corresponding to the valid test input.

[0008] Thirdly, this application also provides a computer device, the computer device including a processor, a memory, and a computer program stored in the memory and executable by the processor, wherein when the computer program is executed by the processor, it implements the steps of the reinforcement learning-based test case generation method described above.

[0009] Fourthly, this application also provides a computer-readable storage medium storing a computer program, wherein when the computer program is executed by a processor, it implements the steps of the reinforcement learning-based test case generation method described above.

[0010] This application provides a method, apparatus, computer device, and storage medium for generating test cases based on reinforcement learning. The method acquires problem description text and standard answer code, and uses a large language model to generate an executable test case generator, thus automating test case generation and reducing the tedious work of manually writing test cases. The generator generates candidate test inputs by driving the generation through preset test case requirements, and performs consistency verification using multiple standard answer codes in a sandbox environment, ensuring the high quality and reliability of the generated test cases. By marking valid test inputs and constructing test cases, the efficiency and quality of test case generation are further improved. This application effectively solves the problems of poor automation and scalability in the test case generation process in existing technologies by constructing a complete automated test case generation and verification framework. It not only improves the automation level of test case generation but also significantly improves the quality and coverage of test cases through consistency verification and dynamic optimization mechanisms, thereby greatly improving the efficiency of test case generation while ensuring high-quality output. Attached Figure Description

[0011] To more clearly illustrate the technical solutions of the embodiments of this application, the drawings used in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0012] Figure 1 This is a schematic diagram of an application environment for a test case generation method based on reinforcement learning in one embodiment of the present invention; Figure 2 A flowchart illustrating an embodiment of a reinforcement learning-based test case generation method provided in this application; Figure 3 A flowchart illustrating the execution of the reinforcement learning-based test case generation method provided in this application embodiment; Figure 4A schematic diagram of the structure of a test case generation system provided in an embodiment of this application; Figure 5 This is a schematic diagram of the structure of an embodiment of a test case generation device based on reinforcement learning provided in this application. Figure 6 This is a schematic block diagram of the structure of a computer device provided in an embodiment of this application.

[0013] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation

[0014] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0015] The flowchart shown in the attached diagram is for illustrative purposes only and does not necessarily include all content and operations / steps, nor does it necessarily have to be performed in the described order. For example, some operations / steps can be broken down, combined, or partially merged, so the actual execution order may change depending on the actual situation.

[0016] The following detailed description of some embodiments of this application is provided in conjunction with the accompanying drawings. Unless otherwise specified, the following embodiments and features can be combined with each other.

[0017] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. 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.

[0018] The reinforcement learning-based test case generation method provided in this invention can be applied to, for example... Figure 1In this application environment, the client communicates with the server via a network. After receiving a test case generation request from the client, the server obtains the problem description text of the programming problem to be tested, and at least two different standard answer codes corresponding to the problem description text. Based on the problem description text, it uses a large language model to generate an executable test case generator. According to preset test case requirements, it generates at least one candidate test input using the test case generator. In a preset sandbox environment, it performs consistency verification on the candidate test input using at least two different standard answer codes, obtaining a consistency verification result for the candidate test input. When the consistency verification result of the candidate test input is successful, it marks the candidate test input as a valid test input and obtains the consistent execution result corresponding to the valid test input. Based on the valid test input and the consistent execution result corresponding to the valid test input, it constructs at least one test case.

[0019] This invention addresses the technical problem of low efficiency and quality in test case generation in application development scenarios in the financial and medical fields, where existing technologies suffer from poor automation and scalability in the test case generation process. By acquiring problem description text and standard answer code, and utilizing a large language model to generate an executable test case generator, the invention automates test case generation, reducing the tedious work of manually writing test cases. The generator generates candidate test inputs driven by preset test case requirements, and performs consistency verification using multiple standard answer codes in a sandbox environment, ensuring the high quality and reliability of the generated test cases. Further improvements are made by marking valid test inputs and constructing test cases. This application effectively solves the problem of poor automation and scalability in the test case generation process in existing technologies by constructing a complete automated test case generation and verification framework. It not only improves the automation level of test case generation but also significantly enhances the quality and coverage of test cases through consistency verification and dynamic optimization mechanisms, thereby greatly improving the efficiency of test case generation while ensuring high-quality output.

[0020] The client can be, but is not limited to, various personal computers, laptops, smartphones, tablets, and portable wearable devices. The server can be implemented using a standalone server or a server cluster consisting of multiple servers. The invention will now be described in detail through specific embodiments.

[0021] Please refer to Figure 2 , Figure 2 This is a flowchart illustrating an embodiment of a reinforcement learning-based test case generation method provided in this application.

[0022] like Figure 2 As shown, the reinforcement learning-based test case generation method includes steps S101 to S106.

[0023] S101. Obtain the problem description text of the programming problem to be tested, and at least two different standard answer codes corresponding to the problem description text.

[0024] In one embodiment, the first step is to obtain a description of the programming problem to be tested and at least two different standard answer codes corresponding to that problem. These standard answer codes are different implementations that have been verified to correctly solve the programming problem. The diversity of the standard answer codes ensures that the generated test cases accurately reflect the correct solution to the problem.

[0025] In practical applications, programming competition problems can be obtained from publicly available programming competition problem sets, online code platforms, or verified code datasets. Each problem includes a detailed problem description text, such as input / output formats, constraints, background information, and verified standard answer code (also known as the golden answer) for each programming problem. To ensure the reliability of subsequent verification, programming problems with at least two or more standard answer codes are selected.

[0026] For example, in the financial field, suppose we need to develop a program to calculate loan repayment plans. The problem description might include: inputs (such as loan amount, loan term, annual interest rate, etc.), outputs (monthly repayment amount, total interest, repayment details, etc.), constraints (such as loan amount ranging from 10,000 to 1,000,000 yuan, loan term from 1 to 30 years, annual interest rate from 3% to 15%), and standard answer codes for multiple different implementation methods (e.g., standard answer code 1 uses the equal principal and interest repayment formula; standard answer code 2 uses the equal principal repayment formula).

[0027] S102. Based on the problem description text, generate an executable test case generator using a large language model.

[0028] Using a trained Large Language Model (LLM), a runnable program (such as Python or C++ code) is generated based on the programming problem description. This program can generate candidate test inputs that conform to the specified format and constraints on a large scale as needed (such as regular test cases and boundary test cases), thus functioning as an executable test case generator program. Generally, the test case generator program can be executable code written in Python, C++, or other programming languages, and its output is test input data that meets the problem requirements.

[0029] Specifically, a description of a programming problem (including problem description, input format, constraints, etc.) is input into a large language model (as the first preset model). Unlike existing technologies that allow the LLM to directly generate test input, this invention guides the LLM to generate an executable program in Python or C++, called a "test case generator program." The test case generator program is configured to generate standardized test input data based on the input constraints and format requirements of the programming problem.

[0030] In one embodiment, when the problem description contains non-textual information (such as input sample images or flowcharts), the image can be converted into a vector representation using a multimodal encoder (such as a CLIP model) and used as input to the LLM along with the text description.

[0031] To improve test coverage, two or more different prompts can be used to guide the LLM. These prompts contain explicit descriptions of test case types, number of test cases generated, and issue constraints, such as regular test case prompts and boundary test case prompts.

[0032] In one embodiment, the test case generator includes a first generator and a second generator. Specifically, a first hint for generating regular test cases and a second hint for generating boundary test cases are obtained; the first hint and the second hint are respectively input into the large language model, so that the large language model is used to generate the first generator based on the first hint and the second generator based on the second hint.

[0033] The standard test case prompt requires the LLM to write a generator program to generate test inputs that meet the basic requirements and typical scenarios of the problem, for example, to generate 80 standard test inputs.

[0034] In one embodiment, the test case generator may include a first generator for generating regular test cases. Specifically, a first prompt for generating regular test cases is input into a Large Language Model (LLM), and the LLM generates the program code for the first generator based on the content of the first prompt.

[0035] The construction of the first hint is not a simple restatement of requirements, but rather requires the transformation of abstract test requirements into deterministic instructions executable by a large language model through a structured template. The first hint includes a declaration of the test case type (explicitly marked as a common scenario test case), quantity specifications (e.g., precisely requiring the generation of 80 valid test cases), input format pattern (providing a standard input template for the target programming language), a mathematical formalization of the problem constraints (converting constraints described in natural language into a system of inequalities or regular expressions), and sampling strategies for typical scenarios (defining common value ranges, common data distributions, etc.) to ensure that the generated test cases can cover typical scenarios.

[0036] Boundary test case prompts require LLM to analyze the problem's constraint boundaries, special values ​​(such as 0, -1, maximum / minimum values), and special structures (such as chained trees, star diagrams), and to write a generator program specifically to generate test inputs for these boundary cases; for example, generating 20 boundary test inputs. The purpose of boundary test cases is to ensure that the software can still function properly under extreme conditions, thereby improving the software's robustness and reliability.

[0037] In one embodiment, the test case generator may further include a second generator for boundary test cases. Specifically, a second hint for generating boundary test cases is input into a Large Language Model (LLM), and the LLM generates the program code for the second generator based on the content of the second hint.

[0038] The second hint includes a description of the test case type, number of test cases to be generated, input format, and problem constraints to ensure that the generated test cases can cover boundary conditions. For example, for a problem involving numerical input, the second hint might require the LLM to generate a program that can generate 20 boundary test inputs, including minimum, maximum, 0, -1, and other special values.

[0039] Specifically, the Test Case Type explicitly indicates that the test cases to be generated are boundary test cases. The Number of Test Cases to Generate specifies the number of boundary test cases to be generated, for example, 20. The Input Format details the format requirements of the input data, including data type (e.g., integer, floating-point, string, etc.) and structure (e.g., array, tree, graph, etc.). The Problem Constraints list all constraints of the problem, including input range (e.g., minimum and maximum values), special values ​​(e.g., 0, -1, etc.), and any specific boundary conditions (e.g., chained trees, star graphs, etc.).

[0040] In one specific embodiment, in the medical field, for a drug dosage calculation program, the test case generator program can generate the following types of test cases: regular test cases, which generate typical inputs that conform to the range of patient weight, drug concentration, and medication frequency, such as a patient weight of 70kg, a drug concentration of 5mg / ml, and medication twice a day; and boundary test cases, which generate boundary value inputs, such as a patient weight of 30kg (minimum), a drug concentration of 1mg / ml (minimum), and medication three times a day (maximum).

[0041] By guiding LLM to generate generator programs that focus on routine or edge scenarios, test cases covering a wide range of situations can be generated systematically and on a large scale, effectively discovering deep and edge defects in the code.

[0042] S103. Based on the preset test case requirements, generate at least one candidate test input through the test case generator.

[0043] In one embodiment, test case requirements may include type identifiers, quantity constraints, quality thresholds, and domain-specific rules. Specifically, the type identifier is used to clarify the type of generated test cases, such as regular test cases or boundary test cases. Regular test cases may employ a uniform distribution sampling strategy to cover the main area of ​​the problem space; while boundary test cases employ an extreme point and critical region enhanced sampling strategy to cover the extreme and special values ​​of the constraints. Quantity constraints refer to setting the generation base and dynamic adjustment factors. Quality thresholds refer to embedding diversity indicators (such as requiring the information entropy value of the generated test case set to be ≥5.0) and complexity indicators (such as the input data scale needing to cover a logarithmic distribution from 10^1 to 10^5) to prevent the generation of homogeneous inputs. Domain-specific rules refer to injecting specific constraints for different domains; for example, in the financial field, "loan amounts must be positive integers and increase in units of ten thousand yuan," while in the medical field, "drug dosages must be retained to two decimal places and meet clinical safety limits."

[0044] Call and execute the test case generator program to generate a set of candidate test inputs. These candidate test inputs are a set of strings, each representing a possible test input. The output of the generator program should conform to the input format and constraints specified in the problem description.

[0045] In one embodiment, a master-slave distributed architecture can be adopted for large-scale test case generation requirements. The master node is responsible for task sharding, breaking down the requirement into N sub-tasks (e.g., each sub-task generates 1000 test cases), and dynamically allocating tasks based on the real-time load (CPU / memory) of each computing node. Multiple slave nodes independently execute generator program sub-instances, and the generated candidate inputs are globally deduplicated using a deduplication hash ring (based on consistent hashing) to avoid duplicate generation. Stream aggregation is employed, with each node sending 100 candidate inputs in batches to the verification module, reducing memory usage.

[0046] In one embodiment, during test case generation, two generator instances, such as a main generator and an adversarial generator, can run in parallel. The main generator generates regular test cases, while the adversarial generator, based on the gradient attack concept, continuously generates adversarial inputs that can cause the standard answer code to time out, exceed memory limits, or produce abnormal outputs. The reward signal of the adversarial generator is negatively correlated with the pass rate of the main generator, forming a zero-sum game. In each iteration, the main generator and the adversarial generator exchange generation strategy weights. The main generator learns the boundary features of adversarial examples to avoid vulnerable areas, while the adversarial generator explores new attack paths. The final output set of candidate inputs is the union of the outputs of the main generator and the adversarial generator, significantly improving the robustness of the test cases.

[0047] When executing a generator program, it's necessary to monitor its runtime status to ensure it executes correctly and generates valid test input. If the generator program encounters compilation errors, runtime errors, or generates test input that doesn't meet the problem constraints during execution, it needs to proceed to the subsequent optimization process.

[0048] For example, a format parser injected at compile time can be used to perform compile-time type checks on each line of output to ensure that the output string strictly conforms to the format required by the problem; output with incorrect format is discarded during the generation stage.

[0049] A lightweight interpreter can be used to parse the generated input data and verify whether it meets the problem constraints, such as numerical range and array length. For example, if the generator outputs "Loan amount: -50000", the semantic filtering layer will immediately identify the negative number as invalid and trigger the generator to roll back to the previous valid state.

[0050] It can also maintain a sliding window hash set to calculate the local information entropy of the generated output in real time. If the entropy value is lower than the threshold, it indicates that the generator is trapped in pattern repetition. At this time, an adversarial disturbance signal can be injected to force the test case generator to introduce random mutations (such as changing the numerical generation from linear increase to exponential jump) and break the homogeneity cycle.

[0051] S104. In a preset sandbox environment, the candidate test input is validated for consistency using at least two different standard answer codes to obtain the consistency validation result of the candidate test input.

[0052] Generally, a sandbox environment provides a secure, isolated, and resource-controlled execution environment to ensure the stability and security of standard answer code during the verification process.

[0053] In one embodiment, a sandbox environment with multi-layered security and resource restriction mechanisms (such as system call whitelists, CPU / memory limits, and permission isolation) can be designed to securely and efficiently execute the generated standard answer code and candidate inputs, preventing malicious code from harming the system.

[0054] The pre-defined sandbox environment features multi-layered security and resource restriction mechanisms, including but not limited to system call whitelist filtering, CPU time and memory usage limits, process permission isolation, network access isolation, and file system access isolation. These mechanisms ensure the security, stability, and resource controllability of code execution. For example, resource restrictions are used to strictly enforce time limits (e.g., 1 second) and memory limits (e.g., 256MB) specified in the problem description. Security isolation is used to prevent the executed code from causing any potential harm to the system through system call filtering (e.g., using ptrace to intercept and only allow system calls from the whitelist), permission downgrading (downgrading from root to a non-privileged user), and network and file system isolation.

[0055] Specifically, CPU time limits are implemented by setting strict CPU time limits (e.g., 1 second) for the execution of each standard answer code to prevent malicious code or inefficient algorithms from exhausting system resources. Memory usage limits restrict the memory usage of the standard answer code (e.g., 256MB) to prevent memory leaks or malicious code consuming excessive memory. A system call whitelist filtering mechanism (e.g., allowing only basic I / O operations and computational calls) filters out potentially dangerous calls (such as file system access and network requests). Process permission isolation restricts the execution of the standard answer code to low-privilege users, preventing malicious operations on the system. File system isolation provides each standard answer code with an independent temporary file system, preventing the code from accessing or modifying files of other code. Network access isolation prohibits the standard answer code from accessing external networks, ensuring the independence and security of the verification process.

[0056] In one embodiment, each candidate test input is sequentially fed into a customized, highly secure, high-performance sandbox environment, and all standard answer codes (e.g., two standard answer codes) corresponding to the programming problem are run using the candidate test input.

[0057] Furthermore, in a preset sandbox environment, the same candidate test input is provided to at least two standard answer codes for execution, and the execution result corresponding to each standard answer code is obtained; when each standard answer code is successfully executed and generates an execution output, the consistency verification of the execution output corresponding to each standard answer code is performed to obtain the consistency verification result of the candidate test input.

[0058] In practical applications, a pre-defined sandbox environment refers to an isolated execution environment, which can be implemented using virtual machines, container technology, or a dedicated sandbox framework. Its purpose is to ensure the security and independence of code execution and avoid external interference or system risks.

[0059] Providing the same candidate test input to at least two standard answer codes can be understood as distributing input to multiple code instances in parallel or sequentially, with the aim of efficiently capturing behavioral differences under different implementation paths. Specifically, standardized input interfaces (such as STDIN or file input) can be used to pass each candidate test input to at least two different standard answer codes, ensuring that each standard answer code executes independently under the same input conditions.

[0060] Successful execution of each standard answer code and the generation of execution output means that the code terminates without exception and generates valid output data. This can be determined by checking return codes, output stream status, or runtime logs, with the aim of filtering out reliable execution results for verification. Furthermore, consistency verification is performed using exact string matching, semantic equivalence analysis, or predefined rule sets. Multiple execution outputs are compared to determine their consistency, thereby judging whether the output meets expectations.

[0061] Specifically, this embodiment distributes candidate test inputs to multiple standard answer codes in a sandbox environment for independent execution, forming a multi-source execution data foundation. Then, successful execution and output generation serve as verification trigger conditions to dynamically filter valid data. The output consistency verification process is only initiated when all standard answer codes meet the execution state conditions. This tightly couples the execution state with the verification logic, avoiding meaningless comparisons under abnormal states such as code crashes, timeouts, or no output, thus ensuring that the verification process is based solely on reliable output.

[0062] In one specific embodiment, a Docker container can be used as an isolated execution unit in a preset sandbox environment to simultaneously provide the same candidate test input to two Python implementations of standard answer code for execution. When both codes exit normally and produce standard output, a string comparison algorithm is used to verify whether the outputs are consistent. If they are consistent, the verification is marked as successful; if they are inconsistent, the verification is marked as unsuccessful.

[0063] Understandably, in the process of verifying the consistency of the execution output corresponding to each standard answer code, the lack of clear judgment logic will lead to inaccurate verification results. For example, when the output has different formats or the same semantics but different representations, it will be misjudged as inconsistent, thus incorrectly rejecting valid test input or accepting invalid input, affecting the reliability of test case generation.

[0064] To this end, this application further proposes: determining whether the execution results of the at least two standard answer codes are consistent for the same candidate test input; if the execution results are consistent, then marking the consistency verification result of the candidate test input as verified as passed; if the execution results are inconsistent, then marking the consistency verification result of the candidate test input as verified as failed.

[0065] Among them, judging whether the execution results are consistent refers to comparing whether the outputs of multiple standard answer codes are semantically equivalent. This can be achieved by direct string comparison or semantic analysis based on predefined rules, ensuring that the verification process is not affected by differences in output format.

[0066] If a candidate test input meets the problem constraints—that is, multiple standard answer codes produce the same or logically equivalent execution results for that candidate test input—then the validation is considered successful, and the candidate test input can be included in the valid set. If the execution results of the standard answer codes differ for that candidate test input, it means that the validation of the candidate test input fails, and the candidate test input is marked as invalid. This avoids including ambiguous inputs in subsequent processes, thereby reducing the generation of invalid test cases.

[0067] By leveraging the principle of multi-source verification, the output behavior of multiple independent implementations is compared, avoiding the bias of relying on a single piece of code. This allows invalid inputs to be filtered out during the verification phase, ensuring the accuracy of test input screening.

[0068] Understandably, in determining whether the execution results of at least two standard answer codes are logically equivalent to the same candidate test input, directly comparing the execution result strings cannot adapt to differences in output format and situations where they are logically equivalent but represent different things. For example, different standard answer codes may have slight differences due to floating-point calculation precision, output order, or format details, but the actual logic is correct, resulting in a high false positive rate of verification failure. This reduces the acquisition of effective test input and affects the efficiency and reliability of test case generation.

[0069] Therefore, if all standard answer codes produce the exact same output, the candidate test input is directly marked as valid; for example, for a simple mathematical calculation problem, if both standard answer codes produce the output 5, they are directly marked as valid.

[0070] For programming problems that allow multiple correct output formats, a custom checker program (Special Judge, SPJ) can be generated or invoked to determine whether the outputs of each execution are logically equivalent. The custom checker program is either automatically generated by the large language model based on the problem description or called from a pre-defined checker program library.

[0071] Furthermore, based on the problem description text of the programming problem, a checker program is generated using the Big Prophet model; the execution results of the at least two standard answer codes for the same candidate test input are input into the checker program, and according to preset logical rules, it is determined whether the execution results corresponding to each standard answer code meet the output requirements; when the execution results corresponding to each standard answer code meet the output requirements, it is determined that the execution results corresponding to each standard answer code are consistent; when the execution result corresponding to any standard answer code does not meet the output requirements, it is determined that the execution results corresponding to each standard answer code are inconsistent.

[0072] In one embodiment, the checker program refers to a verification tool customized based on the programming problem description. It can be generated from the problem description text of the coding problem using a large language model, or invoked from a pre-defined checker program database. The checker program is used to understand the constraints and output specifications specific to the programming problem, avoiding misjudgments caused by general rules.

[0073] Specifically, such as Figure 3 As shown, the large language model automatically generates checker programs based on the problem description, or calls checker programs from a pre-defined checker program library. For example, the problem description text should contain detailed input / output formats, constraints, and logical requirements. When the problem description text contains non-textual information (such as input sample images or flowcharts), the system activates a multimodal encoder (such as a CLIP model) to convert the image into a vector representation, which, along with the text description, serves as input to the LLM. Natural Language Processing (NLP) techniques are used to parse the problem description text and extract key information. Based on the extracted key information, an appropriate checker program template is selected, such as numerical comparison, structured data validation, or text similarity judgment; the LLM is then used to generate the specific checker program code.

[0074] This checker program can parse the semantics of the problem and define output validation rules to handle complex logical equivalence judgments. For example, for numerical output, the checker program can determine whether the output value is within the allowable error range; for structured output (such as lists and dictionaries), the checker program can verify whether the structure and key fields of the output are correct; for text output, the checker program can use regular expressions or text similarity algorithms for validation.

[0075] During the consistency verification process, the checker program will receive the execution results of multiple standard answer codes and perform verification according to preset logical rules.

[0076] Specifically, the execution results of at least two standard answer codes for the same candidate test input are input to the checker program. The input data should conform to the checker program's input format requirements, and the checker program receives the execution results through a standardized interface (such as STDIN or file input). Based on the problem description text, preset logical rules are used to verify whether the execution results meet the output requirements. For example, for numerical output, the checker program calculates the difference between the output value of each standard answer code and the expected value, determining whether it is within the allowable error range; for structured output, the checker program verifies whether the structure and key fields of the output conform to preset rules, for example, verifying whether the length and element values ​​of the output list are correct; for text output, the checker program uses regular expressions or text similarity algorithms to verify whether the output text conforms to preset format and content requirements.

[0077] The logical rules can include numerical ranges, the format and content of structured data, and text similarity. Generally, the strictness of the logical rules can be dynamically adjusted according to the complexity of the problem description text. For example, a stricter error range can be set for high-precision numerical output; a more relaxed similarity threshold can be set for fuzzy text output.

[0078] If the execution results of all standard answer codes meet the output requirements, then these execution results are considered consistent, the candidate test input is marked as valid, and its consistent execution result is recorded. If the execution result of any standard answer code does not meet the output requirements, then these execution results are considered inconsistent, the candidate test input is marked as invalid, and the reason for the exception is recorded.

[0079] This embodiment uses a detector program to verify the consistency of the execution results of multiple standard answer codes, effectively solving the problem of misjudgment caused by differences in output representation during the verification process, ensuring the accuracy of test input verification, thereby improving the reliability and quality of test case generation and avoiding the generation of invalid test cases.

[0080] To improve verification efficiency, the sandbox environment can support concurrent execution of multiple threads or processes. Thread pools or process pools are used to manage concurrent execution, dynamically adjusting the number of concurrent processes to fully utilize system resources. The execution of each standard answer code can take place in an independent thread or process, thus significantly reducing verification time.

[0081] Specifically, based on the actual execution performance of the standard answer code, an adaptive algorithm is used to optimize resource allocation strategies using historical execution data, dynamically adjusting CPU time and memory limits. For example, if a piece of code completes quickly with most inputs, its resource limits can be appropriately relaxed to handle more complex inputs.

[0082] If a standard answer code encounters an exception during execution (such as timeout or memory overrun), the exception is captured and detailed information is logged, and the execution of the code is terminated. For invalid input caused by exceptions, subsequent validation steps are automatically skipped to avoid wasting resources. If multiple standard answer codes encounter exceptions under the same input, the candidate test input is marked as "high-risk" input, which can be manually reviewed or further analyzed later.

[0083] The system meticulously records the validation results for each candidate test input, including execution time, memory usage, output content, and exception information. Statistical analysis is then performed on the validation results, such as calculating the proportion of valid inputs, average execution time, and memory usage distribution, to help optimize the generator and checker programs.

[0084] In one embodiment, when the same candidate test input is provided to at least two standard answer codes for execution, the running parameters during the execution of each standard answer code are collected, wherein the running parameters include execution time, memory usage, and running status; if the running parameters during the execution of any standard answer code are abnormal, the candidate test input is determined to be an invalid test input.

[0085] In one embodiment, each standard answer code is executed sequentially in a sandbox environment, and runtime parameters during the execution process are collected, including execution time, memory usage, and runtime status.

[0086] Among these, execution time refers to the total time from the start to the end of the execution of the standard answer code, used to detect whether the code execution times out. Memory usage refers to the amount of memory used during the execution of the standard answer code, used to detect whether the code execution exceeds the memory limit. Runtime status refers to the final state of the standard answer code execution, including success, timeout, memory overflow, runtime error, etc.

[0087] Specifically, the sandbox environment can monitor the execution process of the standard answer code in real time through system calls and resource management tools. After the execution is completed, the collected running parameters are recorded in a log file. During the execution process, the sandbox environment will detect whether the running parameters exceed the preset thresholds (such as execution time exceeding 1 second or memory usage exceeding 256MB). Once an anomaly is detected, the execution will be terminated immediately and the anomaly type will be recorded.

[0088] For example, a reasonable execution time threshold (e.g., 1 second) can be set based on the complexity of the problem and the expected performance of the standard answer code. If the execution time of the standard answer code exceeds the threshold, it is considered a timeout exception, and execution is terminated. A reasonable memory usage threshold (e.g., 256MB) can be set based on the memory requirements of the standard answer code. If the memory usage of the standard answer code exceeds the threshold, it is considered a memory overflow exception, and execution is terminated. Running statuses include success, timeout, memory overflow, and runtime error. If the running status of the standard answer code is timeout, memory overflow, or runtime error, it is considered an abnormal running status, and execution is terminated.

[0089] If all the standard answer codes produce the same result, the candidate test input is marked as valid. If any standard answer code times out, exceeds memory limits, or encounters a runtime error during execution, the execution of that code is terminated immediately, and the candidate test input is marked as invalid.

[0090] In practical applications, the execution time and memory usage thresholds can be dynamically adjusted based on the actual execution performance of the standard answer code. For example, if a piece of code completes quickly with most inputs, its resource limits can be appropriately relaxed to handle more complex inputs. During execution, the sandbox environment can also perform multi-level anomaly detection, including preliminary detection (e.g., execution time exceeding 500ms) and final judgment (e.g., execution time exceeding 1 second). Preliminary detection is used for early warning, which can be achieved by adjusting resource allocation or optimizing execution strategies; the final judgment is used to decide whether to terminate execution.

[0091] In one embodiment, anomalies can also be categorized and analyzed to distinguish whether they are due to problems with the candidate test input itself (such as excessively large input size) or defects in the standard answer code (such as inefficient algorithm). Simultaneously, anomaly information is fed back to the test case generator program, which adjusts its generation strategy based on the feedback to reduce the generation of invalid inputs. Through anomaly categorization analysis and feedback-driven optimization mechanisms, the generator program can be specifically optimized or the standard answer code can be fixed, gradually improving the quality and efficiency of the generator program.

[0092] This embodiment effectively improves the reliability of test case generation, ensuring that abnormal resource inputs during execution are identified and eliminated in a timely manner, thereby improving the accuracy of filtering effective test inputs and the quality of test cases.

[0093] S105. When the consistency verification result of the candidate test input is passed, the candidate test input is marked as a valid test input, and the consistency execution result corresponding to the valid test input is obtained.

[0094] In one embodiment, the condition for passing the consistency verification is that, under the premise that the running parameters (such as execution time, memory usage, and running status) of all standard answer codes are normal and there are no abnormalities (such as timeout, memory overflow, or runtime error), the execution results of all standard answer codes must be completely consistent (for simple problems) or logically equivalent (for complex problems).

[0095] Continue as Figure 3 As shown, if the outputs of all standard answer codes are exactly the same, the candidate test input is considered to have passed the consistency verification and is marked as a "valid test input", and its corresponding consistent output is recorded as the "correct output".

[0096] In one embodiment, for each valid test input, a unique identifier can be generated, and relevant data corresponding to each valid test input can be recorded, such as test input, execution result, verification information, and additional information.

[0097] In one embodiment, each valid test input can be categorized and labeled with its type (such as regular test case, boundary test case, or special test case) and coverage (such as which input conditions are covered).

[0098] Valid test inputs and their corresponding execution results are stored in a database or file to form structured test case data.

[0099] S106. Based on the valid test input and the consistent execution result corresponding to the valid test input, construct at least one test case.

[0100] In one embodiment, after the consistency verification passes, test cases are constructed based on valid test inputs and their corresponding execution results. Each "valid test input" is paired with its corresponding "correct output" to form a complete test case (Input-OutputPair). These high-quality test cases are collected to form a large test case dataset.

[0101] Specifically, valid test inputs and their corresponding execution results are extracted from the verified records. The extracted content includes test inputs, execution results, verification information, and additional information. Specifically, test inputs refer to the detailed content of candidate test inputs; execution results refer to the execution output of all standard answer codes, including numerical values, structured data, or text; verification information includes verification success flags and verification timestamps; and additional information may include runtime parameters such as execution time and memory usage.

[0102] The extracted test inputs and execution results are formatted into a unified test case data structure, such as JSON, XML, or CSV. The formatted test case data is then assembled into a complete test case.

[0103] Each test case can include a test case ID, input data, expected output, and metadata. Specifically, the test case ID is a unique identifier; the input data refers to the detailed content of the test input; the expected output refers to the consistent execution result, i.e., the execution output of the standard answer code; and the metadata refers to additional information such as execution time, memory usage, and verification timestamps.

[0104] The constructed test cases are stored in a test case database or file for use in subsequent testing tasks. Optionally, test cases can be stored in a relational database (such as MySQL or PostgreSQL) or a non-relational database (such as MongoDB); test cases can also be stored in files, with common file formats including JSON, XML, and CSV.

[0105] Classifying and labeling the constructed test cases facilitates the selection of appropriate test cases for subsequent testing tasks. Dimensions for classification and labeling can include: test case type, such as regular test cases, boundary test cases, and special test cases; coverage scope, i.e., the input conditions and scenarios covered; difficulty level, which can be graded according to the complexity of the test cases; and domain tags, such as finance, healthcare, etc., to facilitate domain-specific testing tasks.

[0106] This embodiment requires at least two distinct, validated standard answer codes for each programming problem. The validity of an input and its correct output are determined by comparing the execution results of these independently implemented codes on the same candidate input to see if they are consistent or logically equivalent, thus eliminating the need for prior knowledge of the "oracle." Through consistent cross-validation of multiple standard answers, the correctness and reliability of the generated test cases (input-output pairs) are fundamentally guaranteed, accurately solving the "oracle problem." Furthermore, the entire process, from generation and validation to optimization, requires almost no manual intervention, achieving full automation and continuously generating massive amounts of high-quality training data for large-scale code reinforcement learning tasks. The generated high-quality test cases provide accurate and highly discriminative reward signals for the code reinforcement learning model, significantly improving the model's training stability and the quality of the final generated code, especially when solving medium- to high-difficulty problems.

[0107] Using the methods described above, this application can automatically generate a dataset containing tens of thousands or even millions of high-quality test cases for a large number of programming problems. These test cases can provide accurate, reliable, and highly discriminative reward signals when subsequently used for code reinforcement learning, thereby effectively guiding LLM to learn and generate more correct code.

[0108] In one embodiment, during the test case generation process, when the test case generator program fails to execute or the proportion of generated candidate inputs that pass validation is too low (i.e., the number of test cases is too small), error feedback information is automatically generated. This error feedback information is then used to guide the LLM to iteratively optimize and refine the generator program, forming a... Figure 4 The system shown is a self-improving, closed-loop test case generation system.

[0109] like Figure 4 As shown, the internal structure of this test case generation system can be divided into several functional modules. Specifically, these include an acquisition module, a generation module, an execution module, a verification module, a construction module, and a correction module.

[0110] Specifically, the acquisition module is responsible for interacting with external data sources to obtain the programming problem description and at least two different standard answer codes.

[0111] The generation module has a built-in or connected first preset model (large language model). It receives a problem description from the acquisition module, and through its internal prompting engineering logic, calls the model to generate a test case generator program. This generation module can also receive error feedback from the correction module and, based on the feedback, call the model to correct the generator program.

[0112] The execution module is responsible for compiling and executing the test case generator program produced by the generation module, capturing its standard output, and forming a list of candidate test inputs. If execution fails, it generates error messages to be fed back to the correction module.

[0113] The verification module is the core module of this device, managing a pre-defined sandbox environment. This module receives candidate test inputs and standard answer codes, scheduling their execution within the sandbox. Internally, the module contains consistency comparison logic to determine whether the outputs of different standard answer codes are consistent, or whether they are logically equivalent through a custom checker program (SPJ). For inputs that pass verification, it outputs valid test inputs and corresponding results; for inputs that fail, it generates a failure reason (timeout, memory exhaustion, inconsistency, etc.) and feeds it back to the correction module.

[0114] The building module receives valid test inputs and correct outputs from the verification module, assembles them into a standard test case format (such as JSON), and stores them in the test case database for use in subsequent reinforcement learning training tasks.

[0115] The correction module receives failure information from the execution module and the verification module, integrates it to generate error feedback information, and passes it to the generation module to start the iterative correction process.

[0116] Further, a first number of valid test inputs and a second number of candidate test inputs generated by the test case generator are obtained; when the ratio of the first number to the second number is less than a preset ratio threshold, abnormal running data of each candidate test input whose consistency verification result is unsuccessful are collected, and error feedback information is generated; the error feedback information is input into a large language model, and the test case generator is iteratively optimized through the large language model so that the test case generator generates candidate test inputs that meet the requirements.

[0117] The first quantity refers to the statistical count of valid test inputs, which can be obtained by storing data in memory variables or recording it in a database. The second quantity refers to the total number of candidate test inputs generated by the test case generator, comprehensively reflecting the overall scale of the generation process; the second quantity can be obtained by accumulating a counter or summarizing data from a log file. The preset ratio threshold refers to the ratio of the number of valid test inputs to the total number of candidate test inputs, which can be set to a fixed value or dynamically adjusted based on historical data.

[0118] Specifically, the generator's performance is dynamically evaluated by calculating the ratio between the first number of valid test inputs and the second number of candidate test inputs, which are obtained in real time. When the ratio falls below a preset threshold, an in-depth analysis of failed validation cases is automatically triggered, abnormal operation data is collected, and structured into error feedback information.

[0119] Here, abnormal runtime data refers to runtime information when consistency verification fails, which may include execution error logs, abnormal resource usage indicators, etc., used to capture the specific reasons for generation failure. Error feedback information refers to structured diagnostic data, which can be encapsulated in JSON format to represent abnormal runtime data. Error feedback information includes at least one of the following: compilation error information, runtime error information, execution timeout information, memory limit information, or output inconsistency information.

[0120] When the proportion of valid test inputs is detected to be lower than a preset threshold, the system automatically collects runtime logs of candidate test inputs that failed verification, including standard error output and abnormal memory usage information. This runtime log data can be parsed into structured data containing input content, error types, and resource metrics—i.e., error feedback information—and provided as input to the large language model. The large language model uses its semantic understanding capabilities to analyze key deviations in the error feedback information and, combined with historical optimization experience, generates optimization instructions for the test case generator. The test case generator adjusts its generation strategy according to these optimization instructions, thereby improving the compliance of candidate test inputs in subsequent iterations; for example, it automatically avoids out-of-bounds values ​​when generating numerical inputs.

[0121] In one embodiment, iterative optimization of the test case generator may include program optimization of the test case generator and / or logic optimization of the test case generator.

[0122] For example, optimizing a test case generator program means that if the test case generator program fails to compile or run during the generation of candidate test inputs, it captures the error log and sends it, along with the original problem description text, back to the LLM, requesting it to "fix this bug." The LLM then generates an optimized generator program, and the process restarts.

[0123] Optimizing the test case generator logic refers to the process where, after candidate test inputs are generated, the standard answer code runs through these candidate inputs. If a large number of candidate test inputs cause the standard answer code to time out, exceed memory limits, or produce inconsistent outputs, it indicates that the distribution of input data generated by the test case generator program is unreasonable. For example, the data size may be too large, or it may be triggering a performance bottleneck in the standard solution. In this case, these failure messages can be used as feedback to allow the LLM to adjust the generator program's logic to produce more suitable inputs.

[0124] Generally, the iterative optimization process can be carried out in multiple rounds (e.g., 1 to 5 rounds) until a predetermined number of valid test cases are generated or the maximum number of iterations is reached.

[0125] This embodiment uses a closed-loop mechanism of proportional monitoring, problem diagnosis, and strategy optimization to enable the test case generation system to automatically identify generation defects and implement targeted improvements, avoiding the simple discarding of invalid inputs.

[0126] This embodiment provides a reinforcement learning-based test case generation method. This method acquires the problem description text and standard answer code, and uses a large language model to generate an executable test case generator, thus automating test case generation and reducing the tedious work of manually writing test cases. The generator generates candidate test inputs by driving the generation through preset test case requirements, and performs consistency verification using multiple standard answer codes in a sandbox environment, ensuring the high quality and reliability of the generated test cases. By marking valid test inputs and constructing test cases, the efficiency and quality of test case generation are further improved. This application effectively solves the problems of poor automation and scalability in the test case generation process of existing technologies by constructing a complete automated test case generation and verification framework. It not only improves the automation level of test case generation but also significantly improves the quality and coverage of test cases through consistency verification and dynamic optimization mechanisms, thereby greatly improving the efficiency of test case generation while ensuring high-quality output.

[0127] Please see Figure 5 , Figure 5 This is a schematic diagram of the current embodiment of a reinforcement learning-based test case generation device provided in this application. The reinforcement learning-based test case generation device is used to execute the aforementioned reinforcement learning-based test case generation method.

[0128] like Figure 5 As shown, the reinforcement learning-based test case generation device 200 includes: a programming problem acquisition module 201, a generator generation module 202, a consistency verification module 204, a valid test input determination module 205, and a test case generation module 206.

[0129] The programming problem acquisition module 201 is used to acquire the problem description text of the programming problem to be tested, and at least two different standard answer codes corresponding to the problem description text; The generator generation module 202 is used to generate an executable test case generator based on the problem description text using a large language model. The candidate test input generation module 203 is used to generate at least one candidate test input according to the preset test case requirements through the test case generator; The consistency verification module 204 is used to perform consistency verification on the candidate test input in a preset sandbox environment using at least two different standard answer codes, and obtain the consistency verification result of the candidate test input. The valid test input determination module 205 is used to mark the candidate test input as a valid test input when the consistency verification result of the candidate test input is that the verification is passed, and to obtain the consistency execution result corresponding to the valid test input; The test case generation module 206 is used to construct at least one test case based on the valid test input and the consistent execution result corresponding to the valid test input.

[0130] It should be noted that those skilled in the art will understand that, for the sake of convenience and brevity, the specific working processes of the device and each module described above can be referred to the corresponding processes in the aforementioned embodiments of the reinforcement learning-based test case generation method, and will not be repeated here.

[0131] The apparatus provided in the above embodiments can be implemented as a computer program, which can be used in, for example... Figure 6 It runs on the computer device shown.

[0132] Please see Figure 6 , Figure 6 This is a schematic block diagram illustrating the structure of a computer device according to an embodiment of this application. The computer device may be a server.

[0133] See Figure 6 The computer device includes a processor, memory, and network interface connected via a system bus, wherein the memory may include non-volatile storage media and internal memory.

[0134] Non-volatile storage media can store operating systems and computer programs. These computer programs include program instructions that, when executed, cause the processor to perform any reinforcement learning-based test case generation method.

[0135] The processor provides computing and control capabilities, supporting the operation of the entire computer device.

[0136] Internal memory provides an environment for the execution of computer programs in non-volatile storage media. When the computer program is executed by the processor, it enables the processor to execute any reinforcement learning-based test case generation method.

[0137] This network interface is used for network communication, such as sending assigned tasks. Those skilled in the art will understand that... Figure 6 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.

[0138] It should be understood that the processor can be a Central Processing Unit (CPU), but it can also be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. Among these, a general-purpose processor can be a microprocessor or any conventional processor.

[0139] In one embodiment, the processor is configured to run a computer program stored in memory to perform the following steps: Obtain the problem description text of the programming problem to be tested, and at least two different standard answer codes corresponding to the problem description text; Based on the problem description text, an executable test case generator is generated using a large language model; Based on the preset test case requirements, at least one candidate test input is generated through the test case generator; In a pre-defined sandbox environment, the candidate test input is validated for consistency using at least two different standard answer codes to obtain the consistency validation result of the candidate test input. When the consistency verification result of the candidate test input is successful, the candidate test input is marked as a valid test input, and the consistency execution result corresponding to the valid test input is obtained; Based on the valid test input and the consistent execution results corresponding to the valid test input, at least one test case is constructed.

[0140] The embodiments of this application also provide a computer-readable storage medium storing a computer program, the computer program including program instructions, and the processor executing the program instructions to implement any of the reinforcement learning-based test case generation methods provided in the embodiments of this application.

[0141] The computer-readable storage medium may be an internal storage unit of the computer device described in the foregoing embodiments, such as the hard disk or memory of the computer device. The computer-readable storage medium may also be an external storage device of the computer device, such as a plug-in hard disk, SmartMediaCard (SMC), SecureDigital (SD) card, or FlashCard equipped on the computer device.

[0142] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in this application, and these modifications or substitutions should all be covered within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. A test case generation method based on reinforcement learning, characterized in that, The method includes: Obtain the problem description text of the programming problem to be tested, and at least two different standard answer codes corresponding to the problem description text; Based on the problem description text, an executable test case generator is generated using a large language model; Based on the preset test case requirements, at least one candidate test input is generated through the test case generator; In a pre-defined sandbox environment, the candidate test input is validated for consistency using at least two different standard answer codes to obtain the consistency validation result of the candidate test input. When the consistency verification result of the candidate test input is successful, the candidate test input is marked as a valid test input, and the consistency execution result corresponding to the valid test input is obtained; Based on the valid test input and the consistent execution results corresponding to the valid test input, at least one test case is constructed.

2. The test case generation method based on reinforcement learning according to claim 1, characterized in that, The step of performing consistency verification on the candidate test input in a preset sandbox environment using at least two different standard answer codes to obtain the consistency verification result of the candidate test input includes: In a pre-defined sandbox environment, the same candidate test input is provided to at least two standard answer codes for execution, and the execution result corresponding to each standard answer code is obtained. When each of the standard answer codes is executed successfully and generates execution output, the consistency verification of the execution output corresponding to each standard answer code is performed to obtain the consistency verification result of the candidate test input.

3. The test case generation method based on reinforcement learning according to claim 2, characterized in that, The process of performing consistency verification on the execution output corresponding to each of the standard answer codes to obtain the consistency verification result of the candidate test input includes: Determine whether the execution results of the at least two standard answer codes are consistent for the same candidate test input; If the execution results are consistent, then the consistency verification result of the candidate test input is marked as verified as passed; If the execution results are inconsistent, the consistency verification result of the candidate test input is marked as verification failure.

4. The test case generation method based on reinforcement learning according to claim 3, characterized in that, The determination of whether the execution results of the at least two standard answer codes are consistent for the same candidate test input includes: Based on the problem description text of the programming problem, a checker program is generated using the Big Prophet model. The execution results of the at least two standard answer codes for the same candidate test input are input into the checker program, and the execution results corresponding to each standard answer code are judged according to the preset logic rules to determine whether they meet the output requirements. If the execution results corresponding to each of the aforementioned standard answer codes meet the output requirements, it is determined that the execution results corresponding to each of the aforementioned standard answer codes are consistent. If the execution result corresponding to any of the standard answer codes does not meet the output requirements, it is determined that the execution results corresponding to each of the standard answer codes are inconsistent.

5. The test case generation method based on reinforcement learning according to claim 2, characterized in that, After providing the same candidate test input to at least two standard answer codes for execution in a preset sandbox environment and obtaining the execution results corresponding to each standard answer code, the method further includes: When the same candidate test input is provided to at least two standard answer codes for execution, the running parameters during the execution of each standard answer code are collected, wherein the running parameters include execution time, memory usage and running status; If any of the running parameters are abnormal during the execution of the standard answer code, the candidate test input is determined to be invalid test input.

6. The test case generation method based on reinforcement learning according to claim 1, characterized in that, After marking the candidate test input as a valid test input and obtaining the consistency execution result corresponding to the valid test input when the consistency verification result of the candidate test input is successful, the method further includes: Obtain a first number of valid test inputs and a second number of candidate test inputs generated by the test case generator; When the ratio of the first quantity to the second quantity is less than a preset ratio threshold, abnormal running data of each candidate test input that failed the consistency verification result are collected, and error feedback information is generated. The error feedback information is input into a large language model, and the test case generator is iteratively optimized through the large language model so that the test case generator can generate candidate test inputs that meet the requirements.

7. The test case generation method based on reinforcement learning according to claim 1, characterized in that, The test case generator includes a first generator and a second generator; The step of generating an executable test case generator based on the problem description text using a large language model includes: Get the first hints for generating regular test cases and the second hints for generating boundary test cases; The first prompt and the second prompt are respectively input into the large language model, so as to use the large language model to generate the first generator based on the first prompt and the second generator based on the second prompt.

8. A test case generation device based on reinforcement learning, characterized in that, The reinforcement learning-based test case generation device includes: The programming problem acquisition module is used to acquire the problem description text of the programming problem to be tested, and at least two different standard answer codes corresponding to the problem description text; The generator generation module is used to generate an executable test case generator based on the problem description text and using a large language model. The candidate test input generation module is used to generate at least one candidate test input based on preset test case requirements through the test case generator. The consistency verification module is used to perform consistency verification on the candidate test input in a preset sandbox environment using at least two different standard answer codes, and obtain the consistency verification result of the candidate test input. The valid test input determination module is used to mark the candidate test input as a valid test input when the consistency verification result of the candidate test input is that the verification is passed, and to obtain the consistency execution result corresponding to the valid test input; The test case generation module is used to construct at least one test case based on the valid test input and the consistent execution result corresponding to the valid test input.

9. A computer device, characterized in that, The computer device includes a processor, a memory, and a computer program stored in the memory and executable by the processor, wherein when the computer program is executed by the processor, it implements the steps of the reinforcement learning-based test case generation method as described in 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, wherein when the computer program is executed by a processor, it implements the steps of the reinforcement learning-based test case generation method as described in any one of claims 1 to 7.