Test case based code repair method, device and equipment and storage medium

By using an automated repair mechanism based on test cases, the problems of low code repair efficiency and insufficient security in existing technologies are solved. This enables efficient and accurate code repair in complex systems and high-concurrency environments, thereby improving the overall efficiency and stability of software development.

CN121349839BActive Publication Date: 2026-06-23广州三七极耀网络科技有限公司

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
广州三七极耀网络科技有限公司
Filing Date
2025-08-26
Publication Date
2026-06-23

AI Technical Summary

Technical Problem

Existing software testing and repair processes are inadequate in terms of efficiency, effectiveness, and security, making it difficult to meet the needs of rapid iteration and high-quality delivery. In particular, in complex systems or large-scale codebases, manual repair methods are time-consuming, inefficient, and prone to introducing new errors and security risks.

Method used

By using a test case-based automated repair mechanism, preset test cases are executed to obtain the execution results of the target code, identify failed test cases, locate the error code and its type, and generate targeted correction code to complete the repair, reducing manual intervention and improving the accuracy and efficiency of code repair.

Benefits of technology

It enables efficient and accurate code repair in complex systems and high-concurrency environments, and is suitable for continuous integration systems and multi-module software maintenance, improving the overall efficiency and stability of software development and reducing the impact of human factors and security risks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121349839B_ABST
    Figure CN121349839B_ABST
Patent Text Reader

Abstract

The application discloses a code repair method and device based on test cases, equipment and a storage medium. The method comprises the following steps: executing a preset test case on target code to obtain an execution result of the target code, determining a failed test case in the test case based on the execution result; locating an error code in the target code according to the failed test case, and identifying an error type corresponding to the error code; generating a correction code based on the error code and the error type corresponding to the error code, and applying the correction code to the target code to complete the repair of the target code. Through the analysis of the execution result of the test case, the accurate positioning of the error in the target code is realized, and the correction code is generated in combination with the error type, so that the automatic code repair is realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular to a code repair method, apparatus, device, and storage medium based on test cases. Background Technology

[0002] As software development scales up, test case execution has become a crucial step in ensuring software quality and stability. During development, developers typically need to analyze and fix errors in the code, including parameter anomalies, assertion errors, logical errors, and database operation anomalies.

[0003] However, existing software testing and remediation processes still have significant shortcomings in terms of efficiency, effectiveness, and security, making it difficult to meet the demands of rapid iteration and high-quality delivery. For example, traditional manual analysis and remediation methods require developers to manually check the execution results of test cases, locate errors, and fix the code. In complex systems or large-scale codebases, this approach is not only time-consuming and inefficient, but also susceptible to human error, leading to incomplete remediation and impacting software stability and reliability. Furthermore, the significant time developers invest in remediation reduces the time available for developing new features, affecting the end-user experience. In addition, vulnerabilities or errors that may arise during manual remediation pose potential security risks. The lack of efficient testing and remediation mechanisms suitable for complex systems and high-concurrency development environments severely restricts the improvement of software development efficiency and quality. Summary of the Invention

[0004] This application provides a code repair method, apparatus, device, and storage medium based on test cases, solving the technical problems of low efficiency and incomplete error repair in existing software development processes. During code repair, the execution status of the target code is obtained by executing test cases, enabling error location and repair code generation, thereby efficiently completing the repair of the target code. This method improves the accuracy and reliability of code repair and is suitable for scenarios such as complex system development and high-concurrency software maintenance.

[0005] Firstly, this application provides a code repair method based on test cases, including:

[0006] Pre-defined test cases are executed on the target code to obtain the execution results of the target code, and failed test cases are determined based on the execution results;

[0007] Based on the failed test cases, locate the error code in the target code and identify the error type corresponding to the error code;

[0008] Based on the error code and its corresponding error type, a correction code is generated, and the correction code is applied to the target code to complete the repair of the target code.

[0009] Secondly, this application provides a code repair device based on test cases, comprising:

[0010] The code testing module is used to execute preset test cases on the target code to obtain the execution result of the target code, and to determine the failed test cases based on the execution result;

[0011] The error location module is used to locate the error code in the target code based on the failed test cases;

[0012] The type identification module is used to identify the error type corresponding to the error code;

[0013] The code repair module is used to generate correction code based on the error code and its corresponding error type, and apply the correction code to the target code to complete the repair of the target code.

[0014] Thirdly, this application provides a code repair device based on test cases, comprising:

[0015] One or more processors;

[0016] A memory that stores one or more programs that, when executed by one or more processors, cause the one or more processors to implement the test case-based code repair method as described in the first aspect.

[0017] Fourthly, this application provides a storage medium containing computer-executable instructions, which, when executed by a computer processor, are used to perform the test case-based code repair method as described in the first aspect.

[0018] This application constructs a test-case-driven automated repair mechanism, achieving precise location and efficient repair of target code. In the code repair process, the target code to be repaired is used as input. First, pre-defined test cases are executed to obtain the execution results of the target code. Based on the execution results, failed test cases are identified, thus clarifying the problematic areas in the code. After the failed test cases are identified, the erroneous code in the target code is located based on these test cases, and the corresponding error type is identified, providing precise information for subsequent repair. Targeted corrective code is generated based on the erroneous code and its error type, and this corrective code is applied to the target code to complete the repair, achieving error elimination and code functionality restoration. This solution, through the collaborative design of test-case-driven error location and corrective code generation, significantly improves the accuracy and efficiency of automated code repair, and is suitable for high-concurrency development environments, continuous integration systems, and multi-module software maintenance scenarios. Attached Figure Description

[0019] Figure 1 This is a flowchart of a code repair method based on test cases provided in an embodiment of this application;

[0020] Figure 2 This is a flowchart of an error code location method provided in an embodiment of this application;

[0021] Figure 3 This is a flowchart of an error type determination method provided in an embodiment of this application;

[0022] Figure 4 This is a flowchart of a modified code generation method provided in an embodiment of this application;

[0023] Figure 5 This is a flowchart of a target correction model matching method provided in an embodiment of this application;

[0024] Figure 6 This is a flowchart of a target code repair method provided in an embodiment of this application;

[0025] Figure 7 This is a flowchart of a secondary testing method for target code provided in an embodiment of this application;

[0026] Figure 8 This is a flowchart illustrating the steps of a code repair method based on test cases provided in an embodiment of this application;

[0027] Figure 9 This is a structural block diagram of a code repair device based on test cases provided in an embodiment of this application;

[0028] Figure 10 This is a schematic diagram of the structure of a code repair device based on test cases provided in an embodiment of this application. Detailed Implementation

[0029] To make the objectives, technical solutions, and advantages of this application clearer, specific embodiments of this application will be described in further detail below with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are merely for explaining this application and not for limiting it. It should also be noted that, for ease of description, only the parts relevant to this application are shown in the drawings, not all of them. Before discussing exemplary embodiments in more detail, it should be mentioned that some exemplary embodiments are described as processes or methods depicted as flowcharts. Although the flowcharts describe operations (or steps) as being processed sequentially, many of these operations can be performed in parallel, concurrently, or simultaneously. Furthermore, the order of the operations can be rearranged. A process can be terminated when its operation is completed, but it may also have additional steps not included in the drawings. A process can correspond to a method, function, procedure, subroutine, subroutine, etc.

[0030] The terms "first," "second," etc., used in the specification and claims of this application are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such use of data can be interchanged where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein, and the objects distinguished by "first," "second," etc., are generally of the same class and the number of objects is not limited; for example, a first object can be one or more. Furthermore, in the specification and claims, "and / or" indicates at least one of the connected objects, and the character " / " generally indicates that the preceding and following objects are in an "or" relationship.

[0031] Currently, test case execution has become a key technical aspect of ensuring software quality during software development. In complex system development environments, test cases involve various tasks such as parameter anomaly checking, assertion verification, code logic testing, and SQL statement validation. Traditional test case execution and problem fixing methods generally rely on manual analysis and manual repair. When developers discover anomalies or errors, they need to locate and modify the problems one by one. This manual approach is not only inefficient, especially when dealing with large and complex systems, resulting in long repair cycles that directly affect development progress and project launch schedules, but it is also susceptible to human error, leading to missed problems, incomplete repairs, or the introduction of new errors during the repair process.

[0032] In existing technologies, manual analysis and fixing of code issues requires significant time, especially in complex systems or multi-module projects, where the fix cycle is significantly extended, impacting the overall development schedule. Because it relies on manual judgment, issues may be missed or incompletely fixed, reducing software stability and reliability. Developers must invest considerable time in bug fixing, reducing resources available for new feature development and thus affecting the end-user experience. Manual fixing may introduce new vulnerabilities or errors, increasing system security risks. These problems are particularly pronounced in modern software development environments characterized by multi-module collaborative development, continuous integration, and rapid iteration, urgently requiring an efficient, automated, and traceable code issue detection and fixing mechanism to improve the overall efficiency, stability, and security of software development.

[0033] To address the problems of low efficiency, incomplete repair, and difficulty in problem tracking associated with traditional manual code repair methods in complex system development, this embodiment provides a test case-based code repair method. By introducing a test case-driven task identification management mechanism and automated repair strategies, a code maintenance system with high throughput and traceable repair capabilities is constructed, enabling efficient repair of target code and real-time feedback on the repair process. This method takes the target code to be repaired and its corresponding set of test cases as input. First, preset test cases are executed to obtain the execution results of the target code, and failed test cases are identified based on the execution results to pinpoint the problematic areas in the code. After the failed test cases are identified, the erroneous code in the target code is located based on the failed test cases, and the corresponding error type is identified, providing accurate information for subsequent repair. After the erroneous code and its error type are determined, targeted correction code is generated and applied to the target code to complete the repair, achieving error elimination and functional restoration. This solution effectively reduces the reliance on manual intervention and significantly improves the efficiency and accuracy of code repair through a collaborative mechanism of test case-driven error localization, task identification management, and automated correction code generation. Meanwhile, this method has good scalability and can be seamlessly integrated with continuous integration platforms, automated testing systems, and multi-module software engineering environments, providing key technical support for achieving efficient, traceable, and low-risk code repair.

[0034] The test case-based code repair method provided in this embodiment can be executed by a test case-based code repair device. This device can be implemented through software and / or hardware, and can consist of two or more physical entities, or a single physical entity. For example, the test case-based code repair device can be a code server used for automatic code repair.

[0035] The test-case-based code repair device has at least one type of operating system installed, including but not limited to Android, Linux, and Windows. The test-case-based code repair device can install at least one application on the operating system; this application can be a built-in application of the operating system or an application downloaded from a third-party device or server. In this embodiment, the test-case-based code repair device has at least one application capable of executing test-case-based code repair methods.

[0036] For ease of understanding, this embodiment uses the operation and maintenance server as the main body for executing the code repair method based on test cases as an example.

[0037] Figure 1 A flowchart of a code repair method based on test cases, provided in an embodiment of this application, is given. (Reference) Figure 1 The test case-based code fix method specifically includes:

[0038] S110. Execute preset test cases on the target code to obtain the execution result of the target code, and determine the failed test cases in the test cases based on the execution result.

[0039] In some embodiments, in one instance, preset test cases are first executed on the target code. The target code refers to a program module used to implement a specific function or logic, and the test cases refer to input sequences and operation steps used to verify the correctness and stability of the target code's functionality. After executing the test cases, the execution results of the target code are obtained. The execution results refer to the output data, status information, or running logs of the target code under each test case. Subsequently, based on the execution results, failed test cases are determined. Failed test cases refer to test cases whose execution results are inconsistent with the expected output.

[0040] In one embodiment, the execution result can be obtained by collecting the output data, log records, and status identification information corresponding to each test case during the execution of the target code.

[0041] In one embodiment, failing test cases can be identified by comparing the actual output of each test case with the expected output and marking the mismatched test cases as failing test cases.

[0042] In one embodiment, the method for recording and managing failed use cases can be: storing failed use case information in a structured data table or log system, and supporting subsequent querying, analysis and report generation.

[0043] S120. Locate the error code in the target code based on the failed test case, and identify the error type corresponding to the error code.

[0044] In some embodiments, firstly, the error code in the target code is located based on the failed test cases, where the failed test cases are test cases whose execution results are inconsistent with the expected output, and the error code is the program code fragment that causes the test case to fail. Subsequently, the error type corresponding to the error code is identified, where the error type is category information that characterizes the nature of the error code problem, such as logical error, syntax error, or runtime exception.

[0045] In one embodiment, locating the error code can be done by analyzing the execution logs, stack information, and output differences of the failed test case to determine the code segment that caused the failure.

[0046] In one embodiment, the error type can be identified by classifying it into logical errors, syntax errors, runtime exceptions, or other types based on the characteristics of the error code, exception information, and runtime environment.

[0047] In one embodiment, error information management can be achieved by recording the located error code and its type in a structured log or database to support subsequent analysis, repair, and backtracking.

[0048] Optionally, Figure 2 A flowchart of an error code localization method provided in an embodiment of this application is given. (Reference) Figure 2 The specific methods for locating this error code include:

[0049] S1201. Obtain the code coverage area corresponding to each of the test cases in the target code.

[0050] For example, firstly, the code coverage area corresponding to each test case in the target code is obtained. Here, the test case is the input sequence and operation steps used to verify the correctness of the target code's function, and the code coverage area is the set of code segments that are actually triggered or accessed by the test case during the execution of the target code.

[0051] In one embodiment, the code coverage area can be obtained by instrumenting target code, running test cases and recording execution paths, or by using code coverage analysis tools to collect information on statements, branches, or function calls triggered by each test case.

[0052] In one embodiment, code coverage information management can be achieved by storing the code coverage areas corresponding to each test case in a structured data format, supporting subsequent error localization, test optimization, and coverage analysis.

[0053] S1202. Calculate the correlation between each code segment of the target code and the failed test case based on the code coverage area.

[0054] For example, the correlation between each code segment of the target code and the failed test cases is first calculated based on the code coverage area. The code coverage area is the set of code segments that are actually triggered in the target code for each test case. The failed test cases are test cases whose execution results are inconsistent with the expected output. The correlation is a numerical value that characterizes the possible causal relationship or degree of influence between the code segments and the failed test cases.

[0055] In one embodiment, the correlation can be calculated by: counting the frequency of code segments covered by failed test cases, the length of execution paths, or triggering dependencies, and calculating the contribution of each code segment to the failed test cases based on a weight model.

[0056] In one embodiment, the correlation can be calculated by constructing a matrix relationship between code snippets and test cases based on the coverage area, and determining the correlation between code snippets and failed test cases through correlation analysis or similarity calculation.

[0057] In one embodiment, the correlation management method can be to store the correlation information between each code snippet and the failed use case in a structured data table for subsequent error location and repair decisions.

[0058] S1203. The code segment whose correlation exceeds the preset correlation threshold is identified as an error code.

[0059] For example, code snippets with a correlation exceeding a preset threshold are first identified as error codes. Here, correlation is the numerical value of the degree of influence between the code snippet and the failed test case, the preset threshold is a reference value used to determine whether the code snippet may cause the failed test case, and the error code is the program code snippet that causes the test case to fail.

[0060] In one embodiment, error codes can be determined by directly comparing the correlation between each code segment and the failed use case with a threshold, and marking segments that exceed the threshold as error codes.

[0061] In one embodiment, the error code can be determined by further analyzing code fragments with a relevance close to a threshold, combined with the code context, execution path, and historical defect records, to help determine whether it is an error code.

[0062] In one embodiment, error code management can be achieved by recording identified error codes in a structured data table or log system, and supporting subsequent error type identification and repair processing.

[0063] Optionally, Figure 3 A flowchart of an error type determination method provided in an embodiment of this application is given. (Reference) Figure 3 The method for determining this error type specifically includes:

[0064] S1204. Obtain associated failed use cases from the failed use cases whose correlation with the error code exceeds a preset correlation threshold.

[0065] For example, firstly, associated failed test cases with a correlation degree exceeding a preset threshold are obtained from the failed test cases. Here, a failed test case is a test case whose execution result is inconsistent with the expected output, an error code is a program code segment that causes the test case to fail, an associated failed test case is a failed test case with a high correlation degree with the error code, and the preset threshold is a reference value used to determine whether the correlation degree is significant.

[0066] In one embodiment, the method for obtaining associated failed use cases may be: by comparing the correlation between each failed use case and the error code with a preset threshold, the failed use cases that exceed the threshold are marked as associated failed use cases.

[0067] In one embodiment, the management of associated failure test cases can be achieved by recording the identified associated failure test cases into a structured data table or log system for subsequent error analysis and remediation strategy generation.

[0068] S1205. Obtain the test log of the associated failed test case, match the exception information in the test log with the preset error feature library, and determine the error type of the error code based on the matching result.

[0069] For example, firstly, test logs of associated failed test cases are obtained. Associated failed test cases are those highly correlated with the error code, and test logs are files or data sets recording the output, status, and exception information during the execution of the failed test cases. Then, the exception information in the test logs is matched against a pre-defined error signature library, and the error type of the error code is determined based on the matching results. The error signature library is a predefined set of common error types and their corresponding feature information, and the error type is category information characterizing the nature of the error code problem, such as logical error, syntax error, or runtime exception.

[0070] In one embodiment, the method for matching abnormal information can be: analyzing the correspondence between the abnormal information in the test log and the feature items in the error feature library through text comparison, pattern matching, or regular expressions.

[0071] In one embodiment, the error type can be determined by classifying the error code into the corresponding error type based on the matched feature information and recording it in a structured data table or log system for subsequent repair and analysis.

[0072] S130. Generate correction code based on the error code and its corresponding error type, and apply the correction code to the target code to complete the repair of the target code.

[0073] In some embodiments, corrective code is first generated based on the error code and its corresponding error type. The error code is a code snippet that causes a test case to fail, the error type is category information characterizing the nature of the error code's problem, and the corrective code is code used to replace or modify the error code to correct its behavior. Subsequently, the corrective code is applied to the target code, which is the program module to be verified and repaired, to complete the repair of the target code.

[0074] In one embodiment, the correction code can be generated by automatically generating or suggesting alternative program snippets to eliminate the error, based on the error type and the logical structure of the error code.

[0075] In one embodiment, applying the correction code can be done by inserting, replacing, or modifying the error code location in the original target code, while ensuring that the code structure and dependencies are correct.

[0076] In one embodiment, the method for fixing and verifying the error can be: re-execute the relevant test cases to confirm that the corrected code has eliminated the error and has not introduced any new errors.

[0077] Optionally, Figure 4 A flowchart of a modified code generation method provided in an embodiment of this application is given. (Reference) Figure 4 The specific methods for generating the corrected code include:

[0078] S1301. Based on preset matching rules, determine the target correction model that matches the error type from the model library.

[0079] For example, firstly, a target correction model matching the error type is determined from the model library based on a preset matching rule. Here, the error type is category information that characterizes the nature of the error code problem, the target correction model is a model used to generate correction code to correct the behavior of the error code, the model library is a collection that stores various correction models and their applicable error types, and the matching rule is a reference rule used to determine the suitability of the model with the error type.

[0080] In one embodiment, the target correction model can be determined by selecting a correction model that is a perfect match or the best match based on the matching relationship between the error type and the applicable types of each model in the model library.

[0081] In one embodiment, the target correction model management method can be: recording the matched target correction model and its corresponding error type into a structured data table or model management system so as to generate correction code later.

[0082] Optionally, Figure 5 A flowchart of a target correction model matching method provided in an embodiment of this application is given. (Reference) Figure 5 The target correction model matching method specifically includes:

[0083] S13011. Based on preset matching rules, select several candidate correction models from the model library that match the error type.

[0084] For example, firstly, based on preset matching rules, several candidate correction models that match the error type are selected from the model library. Here, the error type is category information that characterizes the nature of the error code problem, the candidate correction model is a set of models that may be used to generate correction codes to correct the behavior of the error code, the model library is a set that stores various correction models and their applicable error types, and the matching rules are reference rules used to determine the suitability of the model with the error type.

[0085] In one embodiment, the method for screening candidate correction models can be: selecting several models that are fully matched or optimally matched based on the matching relationship between the error type and the applicable type of each model in the model library.

[0086] In one embodiment, the method for screening candidate correction models can be: combining the severity or priority of the error type to perform weighted screening of a portion of the models in the model library to obtain the most likely effective set of candidate correction models.

[0087] S13012. Obtain the historical correction success rate of each candidate correction model on the failed use cases associated with the error code.

[0088] For example, firstly, the historical correction success rate of each candidate correction model on the failed test cases associated with the error code is obtained. Here, the candidate correction model is a set of models selected from the model library that may be used to generate correction code, the failed test cases are test cases that have a high degree of correlation with the error code, and the historical correction success rate is the proportion of candidate correction models that generate correction code and successfully pass the verification under similar error types and failed test cases.

[0089] In one embodiment, the historical correction success rate can be obtained by querying the correction history of each candidate model corresponding to the error type and failed test cases in the model library or the repair record database, and calculating the ratio of the number of successful corrections to the total number of attempts.

[0090] In one embodiment, the historical repair success rate can be obtained by weighting historical data based on the type of failed test cases, context information, and execution environment to obtain a more accurate repair success rate metric.

[0091] S13013. Determine the target correction model from the candidate correction models based on the historical correction success rate.

[0092] For example, the target correction model is first determined from the candidate correction models based on the historical correction success rate. The candidate correction models are a set of models that may be used to generate correction code, the historical correction success rate is the proportion of each candidate model that generates correction code and successfully passes verification under similar error types and failed use cases, and the target correction model is the model that is finally selected to generate correction code.

[0093] In one embodiment, the target correction model can be determined by selecting the candidate model with the highest historical correction success rate as the target correction model.

[0094] In one embodiment, the target correction model can be determined by combining the error type, contextual information of failed use cases, and historical success rate to give a weighted score to the candidate models, and selecting the model with the highest score as the target correction model.

[0095] S1302. Obtain the context information corresponding to the error code. The context information includes the function where the error code is located, the adjacent code segments of the error code, and the test log corresponding to the error code.

[0096] For example, firstly, obtain the context information corresponding to the error code. The error code is the program code segment that causes the test case to fail. The context information includes the function where the error code is located, the adjacent code segments of the error code, and the test log corresponding to the error code. The test log records the output and exception information of the execution of the error code.

[0097] In one embodiment, the context information can be obtained by extracting the function containing the error code and its adjacent code segments through static code analysis.

[0098] In one embodiment, the context information can be obtained by combining dynamic analysis methods to collect the execution context and call path of the error code while running the target code.

[0099] In one embodiment, the context information can be obtained by associating the test log corresponding to the error code with the code snippet, and recording the code line and execution result corresponding to each log entry.

[0100] In one embodiment, context information management can be achieved by storing the extracted context information in a structured manner in a database or log system to support subsequent code generation and error analysis.

[0101] In one embodiment, contextual information enhancement can be achieved by combining version control records or historical defect data with additional information on code change history and past error types to provide a reference for the correction model.

[0102] S1303. Input the error code and its corresponding context information into the target correction model to generate a correction code.

[0103] For example, the error code and its corresponding context information are first input into the target correction model to generate correction code. The error code is the program code segment that causes the test case to fail. The context information includes the function where the error code is located, the adjacent code segments of the error code, and the test log corresponding to the error code. The target correction model is the model used to generate correction code, and the correction code is the program segment used to replace or modify the error code.

[0104] In one embodiment, the correction code can be generated by taking the error code and its context information as model input and calculating the corresponding correction code through the target correction model.

[0105] In one embodiment, the correction code can be generated by optimizing the model output by combining the error type and context information to improve the accuracy of the correction code.

[0106] Optionally, Figure 6 A flowchart of a target code repair method provided in an embodiment of this application is given. (Reference) Figure 6 The specific methods for fixing this target code include:

[0107] S1304. Replace the corresponding error code in the target code with the corrected code to obtain the updated code.

[0108] For example, the corresponding error code in the target code is first replaced with the corrected code to obtain the updated code. The corrected code is a program snippet generated by the target correction model, the error code is a program code snippet that causes the test case to fail, the target code is the program module to be repaired, and the updated code is the repaired version after replacing the error code.

[0109] In one embodiment, the way to replace the error code is to directly overwrite the location of the error code in the target code with the correction code, thus maintaining the consistency of the code logic and structure.

[0110] In one embodiment, replacing erroneous code can be done by checking function interfaces, dependencies, and code style during the replacement process to ensure that the updated code can be compiled and run correctly.

[0111] S1305. Based on the compilation result of the updated code, adjust the code arrangement order of the updated code, and determine the adjusted updated code as the repair code.

[0112] For example, firstly, the compilation result based on the updated code is obtained. Here, the updated code refers to the target program code obtained after the erroneous code has been replaced. The compilation result refers to the information obtained after the compiler performs syntax analysis, semantic checking, and instruction generation on the updated code. This information may include compilation logs, warning messages, execution performance metrics, or instruction sequence structures. After obtaining the compilation result, the code arrangement order of the updated code is adjusted accordingly to optimize the code logic structure or improve execution efficiency. The adjusted updated code is then identified as the repair code. Here, the code arrangement order refers to the organizational order of code segments, functions, or instructions, and the repair code refers to the final code version that meets both compilation correctness and target runtime requirements after the adjustment.

[0113] In one embodiment, adjusting the code order of updated code based on compilation results can be achieved by rearranging hot code segments according to the performance metrics output by the compiler to reduce execution time or memory usage.

[0114] In one embodiment, adjusting the code order of updated code based on compilation results can also be achieved by reorganizing the function or module call order according to the dependency information contained in the compilation log, in order to ensure the consistency and maintainability of the code logic.

[0115] In one embodiment, adjusting the code order of the updated code based on the compilation results can also be achieved by combining static optimization strategies to adjust loop unrolling, instruction scheduling, or register allocation, in order to further improve the overall performance of the repair code.

[0116] Optionally, Figure 7 A flowchart of a secondary testing method for target code provided in an embodiment of this application is given. (Reference) Figure 7 The secondary testing method for this target code specifically includes:

[0117] S131. Calculate the correlation between each test case and the failed test case, and obtain the periodic failure ratio of each test case within a preset period.

[0118] For example, in one embodiment, the relevance of each test case to each failed test case is first calculated. A test case refers to a set of input conditions, execution steps, and expected results used to verify the correctness of the target code's functionality. A failed test case refers to a test case that generates runtime errors, produces unexpected results, or leads to an abnormal state during test execution. Relevance measures the similarity between test cases and failed test cases in terms of input characteristics, execution paths, or error behaviors. After calculating the relevance, the periodic failure ratio of each test case within a preset period is further obtained. The preset period refers to a fixed time window or execution round used for statistics, and the periodic failure ratio is the ratio of the number of failures of a test case within that period to the total number of executions.

[0119] In one embodiment, the relevance can be calculated by performing similarity matching based on input data features to measure the similarity of input patterns between different test cases.

[0120] In one embodiment, the relevance can also be calculated by comparing execution paths and measuring the overlap of test cases in code coverage or call chains to reflect the logical proximity between test cases.

[0121] In one embodiment, the relevance can also be calculated by combining error information analysis with the log information and exception stack information generated by failed test cases and the results of other test cases to identify potential error propagation relationships.

[0122] In one embodiment, the failure rate of a test case can be obtained by statistically analyzing the execution records of the test cases within a preset period and calculating the proportion of failures to the total number of failures.

[0123] In one embodiment, the failure rate of a cycle can also be obtained by combining the task scheduling logs of the distributed execution environment to aggregate and statistically analyze the failures across nodes, in order to obtain a more accurate failure rate result.

[0124] S132. Test cases whose relevance exceeds the relevance threshold are identified as highly relevant test cases, and test cases whose periodic failure ratio exceeds the preset ratio threshold are identified as high-risk test cases.

[0125] For example, test cases with a relevance exceeding a relevance threshold are identified as highly relevant test cases. The relevance threshold is a preset critical value used to distinguish the strength of the association between test cases and failed test cases. Highly relevant test cases are those that have a high similarity or dependency with failed test cases in terms of input characteristics, execution paths, or error behavior. Simultaneously, test cases with a failure rate exceeding a preset percentage threshold are identified as high-risk test cases. The preset percentage threshold is a benchmark value used to measure the stability and reliability of test cases. High-risk test cases are those with a high probability of failure within a preset period, which may lead to abnormal code operation or instability.

[0126] In one embodiment, a way to determine highly relevant test cases is to mark the corresponding test cases as highly relevant test cases when the relevance value is greater than the relevance threshold, based on the relevance calculation results.

[0127] In one embodiment, another way to determine highly relevant use cases is to combine a machine learning model to perform cluster analysis on the relevance distribution, and mark the test cases that are close to the cluster of failed use cases in the cluster results as highly relevant use cases.

[0128] In one embodiment, high-risk test cases can be identified by: based on the statistical results of the periodic failure rate, when the rate exceeds a preset threshold, the test case is marked as a high-risk test case.

[0129] In one embodiment, high-risk use cases can also be identified by combining a trend prediction model with a curve of the change in the failure rate of a cycle. When the predicted value exceeds a preset threshold, the test case is identified as a high-risk use case in advance.

[0130] S133. The highly relevant use cases and the high-risk use cases are identified as screening test cases. The screening test cases are executed on the repaired target code to obtain test results. Repair information is output based on the execution results and the test results.

[0131] For example, highly relevant test cases and high-risk test cases are identified as screening test cases. Highly relevant test cases are those that are highly similar to failed test cases in terms of input characteristics, execution paths, or error behaviors. High-risk test cases are those that have a high probability of failure within a preset period and may cause system malfunctions. Screening test cases are a subset of test cases selected from the entire test case set for focused verification of the repair effect. Subsequently, the screened test cases are executed on the repaired target code to obtain test results. The repaired target code refers to the executable program version after the erroneous code has been replaced and compiled and adjusted. Test results refer to the runtime feedback information obtained after executing the screened test cases, including execution status, output results, error logs, or performance metrics. Based on the execution results and test results, repair information is output. The repair information refers to a description of the results characterizing the repair effect, which may include whether the repair was successful, potential residual defects, performance change trends, or subsequent optimization suggestions.

[0132] In one embodiment, the method for determining the selection of test cases can be to directly merge highly relevant test cases with high-risk test cases to form a verification set, thereby ensuring that the test covers critical failure paths and potential risk points.

[0133] In one embodiment, the way to perform screening test cases on the repaired target code can be: to run screening test cases in batches through an automated testing framework and collect log files, assertion results and resource consumption information in order to generate complete test results.

[0134] In one embodiment, the method for outputting repair information based on execution results and test results may be as follows: when the execution results meet the preset correctness conditions and the failure rate of the filtered test cases is reduced to below the threshold, a prompt message indicating successful repair is generated; when some filtered test cases still exhibit abnormalities, a repair feedback message containing a list of unrepaired issues is generated.

[0135] In one embodiment, the method of outputting repair information based on execution results and test results can also be: combining statistical analysis and model prediction to quantitatively evaluate the degree of improvement in stability and performance of the repaired target code, and generating a repair report that can be used as a reference for subsequent optimization.

[0136] Optionally, Figure 8 A step-by-step diagram of a code repair method based on test cases provided in an embodiment of this application is given. (Reference) Figure 8 The test case-based code fix method specifically includes:

[0137] S201, Test case execution.

[0138] For example, a pre-configured set of test cases is executed to verify the functionality and logic of the target code, fully capturing standard output, error messages, and system logs during execution. A test case refers to a set of input conditions, execution steps, and expected output results used to verify the correctness and stability of the target code's functionality. Test case execution refers to running the target code in a preset test environment according to the input conditions and comparing the results with the expected results to determine whether the target code's behavior meets expectations.

[0139] In one embodiment, test cases can be executed by calling independent functions or modules in a unit testing environment and comparing the output with the preset expected value to verify the correctness of the local function.

[0140] In one embodiment, test cases can also be executed by running the interaction logic of multiple modules simultaneously in an integration testing environment to check whether cross-module calls are normal and to ensure the overall system functionality is coordinated.

[0141] In one embodiment, test cases can also be executed by simulating real business scenarios in a test environment and evaluating the stability of the target code under complex operating conditions by executing test cases that cover different boundary conditions and abnormal inputs.

[0142] In one embodiment, test cases can also be executed by using an automated testing framework to run test cases in batches and collect runtime logs, exception information, and performance metrics for subsequent test result analysis and evaluation of repair effectiveness.

[0143] S202. Results Collection and Analysis.

[0144] For example, the test execution results are summarized, distinguishing between pass and fail test cases, and the reasons for failure are analyzed by combining log and stack trace information. Result collection refers to the process of collecting runtime status, output data, log information, and performance metrics during test case execution, while result analysis refers to the processing steps of verifying correctness, detecting anomalies, and evaluating performance based on the collected data.

[0145] In one embodiment, results can be collected by automatically recording execution logs, assertion results, and error stack information through the built-in monitoring module of the testing framework for subsequent analysis.

[0146] In one embodiment, the results can also be collected by introducing performance monitoring probes into the runtime environment to sample metrics such as CPU utilization, memory consumption, and response time in real time, so as to comprehensively reflect the runtime performance of the target code.

[0147] In one embodiment, the result analysis can be performed by comparing the running results with the expected output of the test cases to determine whether the test passed and marking failed test cases.

[0148] In one embodiment, the result analysis can also be conducted by: based on log parsing and anomaly feature extraction, locating the function call location or triggering condition where the error occurred, thereby providing a basis for code repair.

[0149] In one embodiment, the results analysis can also be performed by combining statistical methods and visualization tools to aggregate and trend analyze performance indicators, in order to evaluate the differences and optimization effects of the target code before and after the fix.

[0150] S203, AI model detection code issue.

[0151] For example, failed use cases and their context information are input into a pre-trained AI model, which then identifies potential code problem types, such as parameter anomalies, boundary condition defects, assertion errors, and missing dependencies. Utilizing AI models to detect code problems involves comparing the input code data with the model's learned feature patterns based on static characteristics or dynamic execution behavior to identify potential error points and risk areas.

[0152] In one embodiment, the AI ​​model can detect code problems by: extracting features from the syntax structure, data flow relationships, and control flow graph of the source code based on a static analysis model, and identifying potential issues such as null pointer references, array out-of-bounds access, or the use of uninitialized variables.

[0153] In one embodiment, the AI ​​model can also detect code problems by: monitoring the execution trajectory, memory allocation, and abnormal call chains generated by the code during execution based on a dynamic analysis model, and identifying potential deadlocks, memory leaks, or performance degradation issues.

[0154] In one embodiment, the AI ​​model can detect code problems by combining a pre-trained language model trained on a large-scale code corpus to perform semantic understanding and contextual reasoning on the target code fragment, and to determine whether the logical implementation deviates from common patterns or has potential defects.

[0155] In one embodiment, the AI ​​model can detect code problems by: identifying abnormal data points in compilation logs, execution results, and performance metrics based on anomaly detection algorithms, comparing them with historical normal samples, and marking potentially problematic code segments.

[0156] S204, AI model-generated repair solution.

[0157] For example, the AI ​​model automatically generates candidate remediation solutions based on the detection results, outputting code snippets, modification suggestions, and potential alternative implementations. The AI ​​model, trained using machine learning or deep learning methods, learns code repair patterns based on large-scale code data and problem samples. The remediation solution refers to the modification suggestions or replacement code snippets generated for the detected code problems, used to restore functional correctness, improve performance, or eliminate security vulnerabilities. AI model-generated remediation solutions mean that after a code problem is identified, the model automatically generates feasible remediation strategies or code modifications based on its knowledge and reasoning abilities.

[0158] In one embodiment, the AI ​​model can generate a repair solution by generating candidate code snippets based on a code completion model when missing statements or grammatical errors are detected, and inserting them into the target location to complete the repair.

[0159] In one embodiment, the AI ​​model can generate a repair solution by: using a code translation model to translate the erroneously implemented function logic into an equivalent implementation that conforms to common programming patterns, thereby repairing the logical error.

[0160] In one embodiment, the AI ​​model can generate a repair solution by combining a historical repair sample library, matching existing repair strategies for detected code problems in similar scenarios, and migrating the optimal repair steps to the current code.

[0161] In one embodiment, the AI ​​model can generate a repair solution by: using reinforcement learning methods, repeatedly simulating the execution of candidate repair solutions, and gradually optimizing the modified content so that the final solution can be verified by test cases and ensures operational performance.

[0162] S205, Automatic application of repair solutions.

[0163] For example, candidate fixes are automatically applied to the target codebase, generating a new corrected version, and changes are managed and rolled back through a version control system. Here, a fix refers to a modification suggestion or replacement code snippet generated for the detected code problem; automatic application means directly applying the fix to the target code, completing the modification without manual intervention, thus obtaining the fixed target code. The target code refers to the program version before the erroneous code was identified and replaced; the fixed target code refers to the executable program version that meets functional correctness, performance requirements, and security constraints after applying the fix.

[0164] In one embodiment, the automatic application of the repair solution can be achieved by using a code replacement module to insert candidate code snippets generated by the AI ​​model into the corresponding positions in the target code, while maintaining the consistency of the original code structure and calling relationships.

[0165] In one embodiment, the automatic application of the fix can also be achieved by combining a version control system to commit and record the code modifications for applying the fix, so as to facilitate backtracking and multi-version management.

[0166] In one embodiment, the automatic application of the repair scheme can also be achieved by performing syntax checks and static analysis during the application process to ensure that the modified code can be compiled without introducing new syntax or logic errors.

[0167] In one embodiment, the automatic application of the repair solution can also be achieved by automatically triggering test case execution after the repair, verifying the repaired target code, and ensuring that the application of the repair solution can effectively solve the original problem and maintain system stability.

[0168] S206. Re-execute the test cases.

[0169] For example, the same set of test cases is executed again on the repaired code to verify whether the repair solution eliminates the original problem and maintains the correctness of other functions. Here, "re-execution" refers to running the previously defined test cases again on the repaired target code to verify the repair effect and the functional correctness of the target code. Test cases refer to a set of input conditions, execution steps, and expected output results used to verify the functionality and performance of the target code. Repaired target code refers to the executable program version that meets functional correctness, performance requirements, and security constraints after the repair solution is applied.

[0170] In one embodiment, test cases can be re-executed by using an automated testing framework to run all or part of the test cases in batches and recording the execution status, output results, and exception information to evaluate the performance of the fixed code.

[0171] In one embodiment, test cases can also be re-executed by prioritizing the execution of highly relevant and high-risk test cases to quickly verify whether critical functional paths and potential risk points have been fixed.

[0172] In one embodiment, test cases can also be re-executed by combining a distributed testing environment, distributing test cases to multiple nodes for parallel execution, in order to improve verification efficiency and collect comprehensive runtime data.

[0173] In one embodiment, the test cases can also be re-executed by automatically generating a test report after execution, analyzing the pass rate, failed test cases, and performance metrics to provide a basis for subsequent fixes, optimizations, or version releases.

[0174] S207. Record and provide feedback on the repair results.

[0175] For example, the context of the remediation process, the AI-generated remediation plan, the execution results, and comparative analysis are all recorded and fed back to the developers or management platform for subsequent optimization and tracking. Here, the remediation results refer to the target code's running status, functional correctness, performance metrics, and potential residual defects obtained after applying the remediation plan and re-executing test cases. Recording refers to saving these remediation results to a database or log file for later querying and analysis. Feedback refers to providing the remediation results to developers, testing systems, or automated management platforms to guide further code optimization or version management.

[0176] In one embodiment, the repair results can be recorded by: storing the execution status, output results, failure reasons and related log information of each test case in a structured manner in a database or file system in order to track the repair effect.

[0177] In one embodiment, the method of recording the repair results can also be: combining a version control system to archive the status of the target code after repair, the application record of the repair solution, and the test report in association, so as to support multi-version management and backtracking operations.

[0178] In one embodiment, the feedback of the repair results can be provided by sending information such as whether the repair was successful, remaining issues, and performance changes to the developers or operations system in the form of charts or text through an automated report generation module.

[0179] In one embodiment, the feedback of the repair results can also be achieved by comparing and analyzing the repair results with historical repair data to generate optimization suggestions or risk assessment reports, providing a basis for decision-making in subsequent code iterations.

[0180] Based on the above embodiments, Figure 9This is a structural block diagram of a code repair device based on test cases, provided as an embodiment of this application. (Reference) Figure 9 The code repair device based on test cases provided in this embodiment specifically includes: a code testing module 21, an error location module 22, a type identification module 23, and a code repair module 24.

[0181] The code testing module 21 is configured to execute preset test cases on the target code to obtain the execution result of the target code, and determine the failed test cases in the test cases based on the execution result; the error location module 22 is configured to locate the error code in the target code according to the failed test cases; the type identification module 23 is configured to identify the error type corresponding to the error code; and the code repair module 24 is configured to generate correction code based on the error code and its corresponding error type, and apply the correction code to the target code to complete the repair of the target code.

[0182] Based on the above embodiments, the error localization module 22 includes: a code coverage unit configured to obtain the code coverage area corresponding to each of the test cases in the target code; a correlation unit configured to calculate the correlation between each code segment of the target code and the failed test case based on the code coverage area; and an error code unit configured to determine the code segment whose correlation exceeds a preset correlation threshold as an error code.

[0183] Based on the above embodiments, the type identification module 23 includes: an associated use case unit, configured to obtain associated failed use cases from the failed use cases whose correlation with the error code exceeds a preset correlation threshold; and a type matching unit, configured to obtain the test logs of the associated failed use cases, match the abnormal information in the test logs with a preset error feature library, and determine the error type of the error code based on the matching result.

[0184] Based on the above embodiments, the code repair module 24 includes: a correction model unit, configured to determine a target correction model matching the error type from a model library based on preset matching rules; a code context unit, configured to obtain context information corresponding to the error code, the context information including the function where the error code is located, adjacent code segments of the error code, and test logs corresponding to the error code; and a model input unit, configured to input the error code and its corresponding context information into the target correction model to generate correction code.

[0185] Based on the above embodiments, the correction model unit includes: a candidate model unit, configured to filter a number of candidate correction models that match the error type from the model library based on preset matching rules; a correction probability unit, configured to obtain the historical correction success rate of each candidate correction model on the failed test cases associated with the error code; and a model determination unit, configured to determine the target correction model from the candidate correction models based on the historical correction success rate.

[0186] Based on the above embodiments, the code repair module 24 further includes: an update code unit, configured to replace the corresponding error code in the target code with the correction code to obtain update code; and a code reordering unit, configured to adjust the code arrangement order of the update code based on the compilation result of the update code, and determine the adjusted update code as the repair code.

[0187] Based on the above embodiments, the test case-based code repair device further includes: a relevance module configured to calculate the relevance between each test case and the failed test case; a failure ratio module configured to obtain the periodic failure ratio of each test case within a preset period; a test case determination module configured to determine test cases with a relevance exceeding a relevance threshold as highly relevant test cases and test cases with a periodic failure ratio exceeding a preset ratio threshold as high-risk test cases; and a test case execution module configured to determine the highly relevant test cases and the high-risk test cases as screening test cases, execute the screening test cases on the repaired target code to obtain test results, and output repair information based on the execution results and the test results.

[0188] The code repair device based on test cases provided in this application embodiment achieves an end-to-end automated processing chain from test execution, error location, type identification to code repair by constructing a hierarchical task processing architecture consisting of a code testing module, an error location module, a type identification module, and a code repair module. This device can adapt to various types of target code input, dynamically analyze execution results, and generate targeted repair solutions, thereby significantly improving the repair efficiency and accuracy in highly complex codebases or multi-module dependency environments. Specifically, the code testing module 21 has test case execution and result acquisition capabilities, used to execute preset test cases on the target code and capture output and log information during execution to obtain complete execution results. Based on these results, the module can automatically identify failed test cases, providing basic data for subsequent error analysis. The error location module 22 is used to locate erroneous code in the target code based on failed test cases. By analyzing stack information, execution paths, and contextual dependencies, it achieves accurate error location identification, thereby providing a reliable basis for generating repair solutions. The type identification module 23, as the core unit of error feature analysis, is configured to identify the error type corresponding to the error code, including various categories such as parameter anomalies, logical defects, assertion errors, and dependency conflicts, providing classification guidance for the selection and generation of subsequent repair solutions. The code repair module 24 generates corrective code based on the error code and its corresponding error type, and automatically applies the corrective code to the target code, thereby completing the repair of the target code. This module ensures that the repaired code is consistent with the original target code in function and logic through template generation, context adaptation, and feasibility verification mechanisms, while eliminating detected problems. Through the collaborative processing of the above modules, this device constructs a complete closed loop from test execution, error location, type identification to code repair, breaking through the bottlenecks of efficiency, accuracy, and traceability in traditional manual repair modes, and is widely applicable to code library maintenance scenarios with high concurrency, multi-module dependencies, and complex logic.

[0189] The code repair device based on test cases provided in this application can be used to execute the code repair method based on test cases provided in the above embodiments, and has corresponding functions and beneficial effects.

[0190] Figure 10 This is a schematic diagram of the structure of a code repair device based on test cases provided in an embodiment of this application, with reference to... Figure 10The test case-based code repair device includes a processor 31, a memory 32, a communication device 33, an input device 34, and an output device 35. The number of processors 31 and the number of memories 32 in the test case-based code repair device can be one or more. The processor 31, memory 32, communication device 33, input device 34, and output device 35 of the test case-based code repair device can be connected via a bus or other means.

[0191] The memory 32, as a computer-readable storage medium, can be used to store software programs, computer-executable programs, and modules, such as program instructions / modules corresponding to the code repair method based on test cases in any embodiment of this application (e.g., code testing module 21, error location module 22, type identification module 23, and code repair module 24 in the code repair device based on test cases). The memory 32 may primarily include a program storage area and a data storage area. The program storage area may store the operating system and at least one application program required for a function; the data storage area may store data created based on the use of the device, etc. Furthermore, the memory 32 may include high-speed random access memory and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other non-volatile solid-state storage device. In some instances, the memory may further include memory remotely located relative to the processor, and these remote memories can be connected to the device via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.

[0192] The communication device 33 is used for data transmission.

[0193] The processor 31 executes various functional applications and data processing of the device by running software programs, instructions and modules stored in the memory 32, thereby implementing the above-mentioned code repair method based on test cases.

[0194] Input device 34 can be used to receive input digital or character information, and to generate key signal inputs related to user settings and function control of the device. Output device 35 may include display devices such as a display screen.

[0195] The test case-based code repair device provided above can be used to execute the test case-based code repair method provided in the above embodiments, and has corresponding functions and beneficial effects.

[0196] This application also provides a storage medium containing computer-executable instructions. When executed by a computer processor, the computer-executable instructions are used to perform a test case-based code repair method. The test case-based code repair method includes: executing preset test cases on target code to obtain the execution result of the target code; determining failed test cases in the test cases based on the execution result; locating erroneous code in the target code according to the failed test cases and identifying the error type corresponding to the erroneous code; generating correction code based on the erroneous code and its corresponding error type, and applying the correction code to the target code to complete the repair of the target code.

[0197] Storage medium—any type of memory device or storage device. The term "storage medium" is intended to include: mounting media, such as CD-ROM, floppy disk, or magnetic tape devices; computer system memory or random access memory, such as DRAM, DDR RAM, SRAM, EDO RAM, etc.; non-volatile memory, such as flash memory, magnetic media (e.g., hard disk or optical storage); registers or other similar types of memory elements, etc. Storage medium may also include other types of memory or combinations thereof. Furthermore, storage medium may reside in a first computer system in which a program is executed, or it may reside in a different second computer system connected to the first computer system via a network (such as the Internet). The second computer system can provide program instructions to the first computer for execution. The term "storage medium" may include two or more storage media residing in different locations (e.g., in different computer systems connected via a network). Storage medium may store program instructions (e.g., specifically implemented as a computer program) executable by one or more processors.

[0198] Of course, the computer-executable instructions provided in the embodiments of this application are not limited to the code repair method based on test cases as described above, but can also execute related operations in the code repair method based on test cases provided in any embodiment of this application.

[0199] The test case-based code repair device, storage medium, and test case-based code repair equipment provided in the above embodiments can execute the test case-based code repair method provided in any embodiment of this application. For technical details not described in detail in the above embodiments, please refer to the test case-based code repair method provided in any embodiment of this application.

[0200] The above description is merely a preferred embodiment and the technical principles employed in this application. This application is not limited to the specific embodiments described herein, and various obvious changes, readjustments, and substitutions that can be made by those skilled in the art will not depart from the scope of protection of this application. Therefore, although this application has been described in detail through the above embodiments, this application is not limited to the above embodiments, and may include many other equivalent embodiments without departing from the concept of this application. The scope of this application is determined by the scope of the claims.

Claims

1. A code repair method based on test cases, characterized in that, include: Pre-defined test cases are executed on the target code to obtain the execution results of the target code, and failed test cases are determined based on the execution results; Based on the failed test cases, locate the erroneous code in the target code, obtain the associated failed test cases from the failed test cases whose correlation with the erroneous code exceeds a preset correlation threshold, obtain the test logs of the associated failed test cases, match the abnormal information in the test logs with a preset error feature library, and determine the error type of the erroneous code based on the matching results; Based on preset matching rules, a target correction model matching the error type is determined from the model library. The context information corresponding to the error code is obtained. The context information includes the function where the error code is located, the adjacent code segments of the error code, and the test log corresponding to the error code. The error code and its corresponding context information are input into the target correction model to generate correction code. The correction code is then applied to the target code to complete the repair of the target code. Calculate the relevance of each test case to the failed test case, and obtain the periodic failure ratio of each test case within a preset period. Determine test cases with a relevance exceeding a relevance threshold as highly relevant test cases, and determine test cases with a periodic failure ratio exceeding a preset ratio threshold as high-risk test cases. Determine the highly relevant test cases and the high-risk test cases as screening test cases, execute the screening test cases on the repaired target code to obtain test results, and output repair information based on the execution results and the test results.

2. The code repair method based on test cases according to claim 1, characterized in that, The step of locating the error code in the target code based on the failed test case includes: Obtain the code coverage area corresponding to each of the test cases in the target code; The correlation between each code segment of the target code and the failed test case is calculated based on the code coverage area. Code segments whose relevance exceeds a preset relevance threshold are identified as error codes.

3. The code repair method based on test cases according to claim 1, characterized in that, The step of determining the target correction model that matches the error type from the model library based on preset matching rules includes: Based on preset matching rules, several candidate correction models that match the error type are selected from the model library; Obtain the historical correction success rate of each candidate correction model on the failed use cases associated with the error code; The target correction model is determined from the candidate correction models based on the historical correction success rate.

4. The code repair method based on test cases according to any one of claims 1-3, characterized in that, The step of applying the corrected code to the target code to complete the repair of the target code includes: The corrected code is used to replace the corresponding erroneous code in the target code to obtain the updated code; Based on the compilation results of the updated code, the code arrangement order of the updated code is adjusted, and the adjusted updated code is determined as the repair code.

5. A code repair device based on test cases, characterized in that, include: The code testing module is used to execute preset test cases on the target code to obtain the execution result of the target code, and to determine the failed test cases based on the execution result; The error location module is used to locate the error code in the target code based on the failed test cases; The type identification module is used to obtain associated failed test cases from the failed test cases whose correlation with the error code exceeds a preset correlation threshold, obtain the test logs of the associated failed test cases, match the abnormal information in the test logs with a preset error feature library, and determine the error type of the error code based on the matching results. The code repair module is used to determine the target correction model that matches the error type from the model library based on preset matching rules, obtain the context information corresponding to the error code, the context information includes the function where the error code is located, the adjacent code segments of the error code, and the test log corresponding to the error code, input the error code and its corresponding context information into the target correction model to generate correction code, and apply the correction code to the target code to complete the repair of the target code; The relevance module is configured to calculate the relevance between each of the test cases and the failed test cases. The failure ratio module is configured to obtain the period failure ratio of each test case within a preset period; The test case determination module is configured to determine test cases whose relevance exceeds a relevance threshold as highly relevant test cases, and test cases whose periodic failure rate exceeds a preset rate threshold as high-risk test cases; The test case execution module is configured to identify the highly relevant test cases and the high-risk test cases as screening test cases, execute the screening test cases on the repaired target code to obtain test results, and output repair information based on the execution results and the test results.

6. A code repair device based on test cases, characterized in that, include: One or more processors; A memory that stores one or more programs, which, when executed by one or more processors, cause the one or more processors to implement the test case-based code repair method as described in any one of claims 1-4.

7. A storage medium containing computer-executable instructions, characterized in that, The computer-executable instructions, when executed by a computer processor, are used to perform the test case-based code repair method as described in any one of claims 1-4.