[go: up one dir, main page]

WO2025246269A1 - Test code repairing method and related device - Google Patents

Test code repairing method and related device

Info

Publication number
WO2025246269A1
WO2025246269A1 PCT/CN2024/137807 CN2024137807W WO2025246269A1 WO 2025246269 A1 WO2025246269 A1 WO 2025246269A1 CN 2024137807 W CN2024137807 W CN 2024137807W WO 2025246269 A1 WO2025246269 A1 WO 2025246269A1
Authority
WO
WIPO (PCT)
Prior art keywords
code
repair
error
test
assertion
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
PCT/CN2024/137807
Other languages
French (fr)
Chinese (zh)
Inventor
胡昭宇
周建祎
顾思琦
陈振宇
房春荣
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Nanjing University
Huawei Cloud Computing Technologies Co Ltd
Original Assignee
Nanjing University
Huawei Cloud Computing Technologies Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Nanjing University, Huawei Cloud Computing Technologies Co Ltd filed Critical Nanjing University
Publication of WO2025246269A1 publication Critical patent/WO2025246269A1/en
Pending legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Definitions

  • This application relates to the field of artificial intelligence (AI) technology, and in particular to a test code repair method, a code development platform, a computing device cluster, a computer-readable storage medium, and a computer program product.
  • AI artificial intelligence
  • test code may contain errors, which could be caused by logical flaws, coding mistakes, or environment configuration issues. Incorrect test code not only fails to accurately detect problems in the software but may also lead developers to make incorrect code modifications, resulting in decreased software quality or even introducing new errors.
  • test code fixing techniques can help alleviate the burden on developers and improve the efficiency and accuracy of testing.
  • This application provides a test code repair method. This method locates errors by combining execution information, extracts context information based on the location of the error code, and generates more accurate and complex repair code using an advanced language model based on this context information. This adapts to various complex error scenarios, is not limited to specific error types, and thus improves repair efficiency and accuracy.
  • This application also provides a code development platform, computing device cluster, computer-readable storage medium, and computer program product corresponding to the above method.
  • this application provides a method for repairing test code.
  • This method can be executed by a code development platform.
  • Code development platforms are typically used to develop and maintain test code.
  • Code development platforms can be provided to users in different forms.
  • a code development platform can be a standalone software system, including but not limited to an integrated development environment (IDE) or a code editor.
  • IDE integrated development environment
  • the developer can provide the code development platform software package to the user, who can then deploy it themselves, for example, on a local computing device, to achieve comprehensive repair of the test code.
  • the code development platform can be integrated into other software or platforms, for example, as a plugin or component. This allows for a seamless repair experience for users through an embedded solution.
  • the code development platform can be deployed in a cloud environment and provided to users for subscription as a cloud service.
  • the cloud environment can be a cloud computing cluster formed by multiple computing devices, including but not limited to a central cloud (a cloud computing cluster formed by central computing devices) and an edge cloud (a cloud computing cluster formed by edge computing devices).
  • the cloud service subscription model allows users to access the corresponding cloud service via the Internet to execute the test code repair method of this application, without the need for local software package installation, offering high flexibility and scalability.
  • the code development platform can also be a hardware system with test code development capabilities, such as a cluster of computing devices with test code development capabilities. When the computing device cluster is running, it executes the test code repair method of this application.
  • the code development platform can obtain the test code corresponding to the source code. This test code is used to test the functionality and/or performance of the source code. The platform then executes the test code and obtains its execution information, including stack traces of any exceptions output during execution. The platform can then locate errors in the test code based on this information, obtaining the location of the erroneous code. Based on this location, it extracts contextual information, including at least one of the following: erroneous test cases, error descriptions, or error content. The platform can then use a language model built based on this contextual information to reason and obtain a first corrective code. This first corrective code is obtained by the language model correcting the erroneous code in the test code.
  • This method first locates errors by combining the execution information of the test code, then extracts contextual information based on the location of the error code. Based on this contextual information, it generates more accurate and complex repair code using an advanced language model to adapt to various complex error scenarios, not limited to specific error types. This reduces manual intervention, improves the automation level of test code repair, and thus improves repair efficiency and accuracy, accelerates the iteration speed of software development and testing, and enhances the overall quality of the software. Furthermore, this method can repair different error types, demonstrating strong versatility and adaptability.
  • the code development platform can also execute the first fix code or test code fixed using the first fix code. Specifically, if the first fix code is the full code, the code development platform can execute it. If the first fix code is incremental code, the code development platform can execute the test code fixed using the first fix code, such as inserting a code block containing the first fix code into the test code, or replacing an erroneous code block with the first fix code in the test code. If execution fails, the code development platform presents the first fix code to the user, receives user feedback on the first fix code, and obtains an updated first fix code.
  • this method In addition to automatically repairing test code, this method also introduces a manual repair channel, allowing users to provide feedback such as modifying the first repair code, thereby further improving the accuracy and efficiency of the repair.
  • the code development platform can also determine the error type of the error code, fix the error code according to the corresponding repair template, and obtain a second repair code. Correspondingly, if the second repair code fails to fix the error, the code development platform can extract context information based on the location information of the error code.
  • Template repair relies on pre-defined repair templates to quickly locate and fix common error types, while language model repair can generate more precise and complex repair solutions to handle complex error scenarios.
  • the error type of the error code includes assertion failure. Accordingly, the code development platform can first determine the assertion type of the erroneous assertion in the error code. When the assertion type is an equality type, the code development platform extracts the expected value of the erroneous assertion from the error code, extracts the actual value of the erroneous assertion from the test report, and then replaces the expected value in the assertion parameter of the erroneous assertion with the actual value according to the assertion repair template corresponding to the assertion type, thus obtaining the second repair code.
  • the code development platform can use the original assertion template as the assertion repair template to replace the assertion parameters of the erroneous assertion, such as replacing the expected value with the actual value, thereby achieving rapid repair of erroneous assertions of the equality type.
  • the code development platform can generate second repair code based on the assertion parameters in the error assertion and the second assertion repair template corresponding to the first assertion repair template used by the error assertion, wherein the Boolean logic of the second assertion repair template is opposite to that of the first assertion repair template.
  • the code development platform can quickly fix Boolean type error assertions by changing the template (for example, changing the assertion repair template used by the error assertion to an assertion repair template with the opposite Boolean logic) while keeping the assertion parameters unchanged.
  • the error type of the error code includes an exception
  • the second fix code may include the exception handling code block corresponding to the exception.
  • the code development platform can determine the exception type from the exception's stack trace information, and then fill the exception type into the exception fix template to obtain the exception handling code block.
  • the second fix code is incremental code, it may include the aforementioned exception handling code block.
  • the second fix code is full code, it may include test code and the exception handling code block; for example, the code development platform inserts an exception handling code block after the error code in the test code to obtain the second fix code.
  • This method addresses error codes related to exception types. By filling the exception type into an exception repair template, exception handling is achieved, thus enabling rapid repair of error codes of exception types. It should be noted that the exception repair template of this method supports rapid repair of various exception types, and is not limited to specific exception types such as null pointer exceptions, thus possessing high usability.
  • the code development platform can also compile test code to obtain compilation information.
  • This compilation information includes error logs output by the compiler, which record the error type of the erroneous code.
  • the second fix can include import statements.
  • the code development platform can determine the missing class name and construct a symbol index based on project dependencies, development tool libraries, or third-party libraries. This symbol index includes the fully qualified names of accessible classes. The platform then matches the missing class name with the symbol index to obtain the fully qualified name corresponding to the missing class name.
  • the code development platform can insert this fully qualified name into the import fix template to obtain the import statement.
  • the second fix can be incremental code, in which case it can include the aforementioned import statements.
  • the second fix can be full code, in which case it can include both test code and import statements. For example, the code development platform can insert import statements into the test code to obtain the second fix.
  • This method also supports generating import statements using import repair templates for compilation error codes such as missing class references, thereby enabling rapid repair of error codes with missing class references.
  • the code development platform can re-execute the code fix for the test code until the test code is successfully fixed or the number of retries reaches the target value.
  • This method supports setting a maximum number of retries, and the code development platform can perform multiple repairs on the test code based on the language model, thereby improving the repair success rate and the degree of automation.
  • the code development platform includes:
  • the test code selection module is used to obtain the test code corresponding to the source code, and the test code is used to test the functionality and/or performance of the source code;
  • the execution module is used to execute the test code and obtain the execution information of the test code, including the stack trace information of the exceptions output when the test code is executed;
  • the error location module is used to locate errors in the test code based on the execution information and obtain the location information of the error code.
  • the model repair module is used to extract context information based on the location information of the error code.
  • the context information includes at least one of the error test case, error description, or error content.
  • the module then uses a prompt input language model built based on the context information to perform reasoning to obtain a first repair code.
  • the first repair code is obtained by the language model repairing the error code in the test code.
  • the code development platform also includes a feedback module:
  • the running module is also used to execute the first repair code or the test code repaired using the first repair code;
  • the feedback module is used to present the first repair code to the user when the execution fails, receive feedback from the user on the first repair code, and obtain the updated first repair code.
  • the code development platform also includes:
  • the template matching and repair module is used to determine the error type of the error code, and repair the error code according to the repair template corresponding to the error type to obtain a second repair code;
  • the model repair module is specifically used for:
  • the context information is extracted based on the location information of the error code.
  • the error type of the error code includes assertion failure
  • the template matching and repair module is specifically used for:
  • the expected value in the assertion parameter of the erroneous assertion is replaced with the actual value to obtain the second repair code.
  • the template matching repair module is further used for:
  • a second repair code is generated based on the assertion parameters in the error assertion and the second assertion repair template corresponding to the first assertion repair template used by the error assertion.
  • the Boolean logic of the second assertion repair template is the opposite of the Boolean logic of the first assertion repair template.
  • the error type of the error code includes an exception
  • the second repair code includes an exception handling code block corresponding to the exception
  • the template matching and repair module is specifically used for:
  • the code development platform also includes:
  • a compilation module is used to compile the test code and obtain compilation information of the test code.
  • the compilation information includes error logs output by the compiler when compiling the test code, and the error logs record the error types of the error codes.
  • the second repair code includes an import statement
  • the template matching and repair module is specifically used for:
  • the missing class name is matched with the symbol index to obtain the fully qualified name corresponding to the missing class name;
  • model repair module is also used for:
  • the code repair is re-executed for the test code until the test code is successfully repaired or the number of retries reaches the target value.
  • this application provides a computing device cluster.
  • the computing device cluster includes at least one computing device, and the at least one computing device includes at least one processor and at least one memory.
  • the at least one processor and the at least one memory communicate with each other.
  • the at least one processor is used to execute instructions stored in the at least one memory to cause the computing device or the computing device cluster to perform the test code repair method as described in the first aspect or any implementation thereof.
  • this application provides a computer-readable storage medium storing instructions that instruct a computing device or a cluster of computing devices to execute the test code repair method described in the first aspect or any implementation thereof.
  • this application provides a computer program product containing instructions that, when run on a computing device or a cluster of computing devices, causes the computing device or cluster of computing devices to execute the test code repair method described in the first aspect or any implementation thereof.
  • Figure 1 is a schematic diagram of the architecture of a code development platform provided in this application.
  • FIG. 2 is a flowchart of a test code repair method provided in this application.
  • FIG. 3 is a schematic diagram of a code editing interface provided in this application.
  • Figure 4 is a schematic diagram of a code editing interface provided in this application.
  • Figure 5 is a schematic diagram of a prompt template provided in this application.
  • Figure 6 is a schematic diagram of test code repair based on assertion repair template provided in this application.
  • Figure 7 is a schematic diagram of test code repair based on assertion repair template provided in this application.
  • Figure 8 is a schematic diagram of test code repair based on an exception repair template provided in this application.
  • Figure 9 is a schematic diagram of test code repair based on an exception repair template provided in this application.
  • Figure 10 is a schematic diagram of the structure of a computing device provided in this application.
  • Figure 11 is a schematic diagram of the structure of a computing device cluster provided in this application.
  • Figure 12 is a schematic diagram of another computing device cluster provided in this application.
  • Figure 13 is a schematic diagram of another computing device cluster provided in this application.
  • first and second used in the embodiments of this application are for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of indicated technical features. Therefore, a feature defined with “first” and “second” may explicitly or implicitly include one or more of that feature.
  • Software testing is a technique that uses test code to check whether software (or a software system) meets user requirements.
  • Software testing can be divided into several phases, such as unit testing, integration testing, system testing, and acceptance testing.
  • Unit testing refers to testing the smallest testable unit in the software, which can be a function, a method, or a class. Unit testing is usually performed during the development process and aims to verify whether the module's functionality is correct.
  • Integration testing is the process of verifying whether the interaction between multiple modules works as expected. Integration testing aims to discover dependencies and communication problems between modules.
  • System testing is performed on the entire software system and aims to verify whether the entire software system works as required and expected by the user.
  • Acceptance testing also known as delivery testing, is usually the last testing operation before deploying the software. The purpose of acceptance testing is to ensure that the software is ready and can be used by end users to perform the software's intended functions and tasks.
  • Test code includes test classes and test methods to implement testing functionality. To improve code development efficiency, test code can be developed based on a testing framework. Taking Java as an example, Java supports the development of unit test code using multiple testing frameworks, with JUnit being a mainstream example. Therefore, when developing test code, you can import the JUnit package, create test classes, and write test methods within those classes. Test methods can use methods such as ⁇ assertEquals() ⁇ , ⁇ assertTrue() ⁇ , or ⁇ assertFalse() ⁇ to check whether the tested software meets expectations. Test classes and test methods can be annotated with appropriate tags.
  • test code can include test case code.
  • a test case describes a specific software testing task and typically includes the test objective, test environment, test inputs, test steps, and expected results. Test cases are used to verify whether the software under test meets a specific software requirement. For example, executing the test case code in the test environment obtains the actual output corresponding to the test inputs. Based on the actual output and expected results, the test case verifies whether the software under test meets the test objective (e.g., a specific software requirement).
  • test objective e.g., a specific software requirement
  • NPE Null Pointer Exception
  • the test verification module After the test verification module starts the test case, it verifies whether the test passes. If no execution exception is detected during the test case execution, the test passes and the process ends. If the test fails, the process jumps to the exception handling module.
  • the exception handling module captures the type of the exception detected during the test, determines whether the exception is an NPE, and if it is, the process jumps to the NPE handling module; otherwise, it outputs the exception information for developers to manually fix.
  • the NPE handling module automatically handles the captured NPE exception, and after processing and fixing it, it executes the test verification again. If no exception is found, the test passes; if an exception is found, the above steps are repeated until the exception is resolved or thrown.
  • NPE Non-Proof-of-Specification
  • software testing can encounter various types of errors, such as assertion failures, type mismatches, and array out-of-bounds errors.
  • Test remediation schemes based on manual intervention or heuristic methods lack versatility and flexibility, limiting their application scope. Furthermore, because these schemes primarily detect specific error types and perform targeted remediation, their remediation efficiency is low, and their accuracy is not high.
  • this application provides a method for repairing test code.
  • This method can be executed by a code development platform.
  • a code development platform is typically used to develop and maintain test code.
  • the code development platform can be a standalone software system, such as an integrated development environment (IDE) or a code editor.
  • IDE integrated development environment
  • the code development platform can be provided to users as a software package, which users can deploy themselves, for example, on a local computing device, to achieve comprehensive repair of the test code.
  • the local computing device is a computing device directly controlled by the user, including but not limited to personal computers (PCs), laptops, and personal workstations.
  • the code development platform can also be integrated into other software or platforms, for example, as a plugin or component. This allows for a seamless repair experience for users through an embedded solution.
  • the code development platform can also be deployed in a cloud environment and provided to users as a cloud service for subscription.
  • the cloud environment can be a cloud computing cluster formed by multiple computing devices, including but not limited to a central cloud (a cloud computing cluster formed by central computing devices) and an edge cloud (a cloud computing cluster formed by edge computing devices).
  • the cloud service subscription model allows users to access corresponding cloud services via the internet to execute the test code repair method of this application, without the need for local software package installation, offering high flexibility and scalability.
  • the code development platform can also be a hardware system with test code development capabilities, such as a cluster of computing devices capable of test code development. When the computing device cluster is running, it executes the test code repair method of this application.
  • the code development platform obtains the test code corresponding to the source code. This test code is used to test the functionality and/or performance of the source code. The platform then executes the test code to obtain execution information, including stack trace information of any exceptions output during the execution of the test code.
  • Stack trace information also known as stack backtracking information, describes the active stack frames at a specific point in time during the program's (e.g., the test code's) execution.
  • Stack frame information can include the exception type, the location of the exception (e.g., class name, method name, line number), and the method call chain that caused the exception.
  • the code development platform can then locate the error in the test code based on the execution information, obtaining the location information of the erroneous code.
  • the code development platform extracts context information, which includes at least one of the following: the erroneous test case, the error description, or the error content.
  • the code development platform inputs a prompt constructed based on the context information into a language model (LM) for inference, obtaining a first corrective code.
  • LM language model
  • This first corrective code can be obtained by the language model correcting the erroneous code in the test code.
  • This method first locates errors by combining execution information from the test code, then extracts rich contextual information based on the error code's location. Using this contextual information, it generates more precise and complex repair code through an advanced language model to adapt to various complex error scenarios, not limited to specific error types. This reduces manual intervention, improves the automation level of test code repair, thereby increasing repair efficiency and accuracy, accelerating software development and testing iterations, and enhancing overall software quality. Furthermore, this method can repair different error types, demonstrating strong versatility and adaptability.
  • the code development platform 10 includes an interactive device 100 and a test code repair device 200.
  • the interactive device 100 can be deployed as a plugin on a client, which can be an IDE or a code editor; therefore, the interactive device 100 can also be called a plugin.
  • the test code repair device 200 can be deployed on a server; therefore, the test code repair device 200 can also be called a server.
  • the test code repair device 200 may include an error location module (not shown in Figure 1) and a model repair module 201. Further, the test code repair device 200 may also include a template matching repair module 203.
  • the interaction device 100 coordinates the workflow of the functional modules (such as the model repair module 201 and the template matching repair module 203) in the test code repair device 200, interacts with other hardware devices, and collects user information in real time.
  • the interaction device 100 can also run the test code to obtain its execution information (or running information) and synchronize and interact with the server (including the central server and edge servers), so that the server-side test code repair device 200 can repair the test code based on the execution information.
  • the interaction device 100 may include a test code selection module 102 and a running module 104.
  • the test code may be compiled before running, and the interaction device 100 may also include a compilation module 103.
  • the server-side test code repair device 200 can then repair the test code based on the compiled information.
  • the interactive device 100 may also include a repair strategy selection module 106.
  • the interactive device 100 can coordinate the workflow of the repair module in the test code repair device 200 according to the repair strategy.
  • the interactive device 100 may also include a feedback module 108.
  • the feedback module 108 supports the introduction of a mechanism for manually repairing test code on top of automated test code repair.
  • the test code selection module 102 is used to obtain the test code corresponding to the source code.
  • the source code can be the source code of functions, methods, or classes of the software under test, or it can be the project-level code of the software under test.
  • the test code selection module 102 can respond to the user's selection operation and select the test code to be tested and fixed.
  • the test code can differ depending on the stage of software testing. Taking unit testing as an example, the test code can be the test case code in the unit test. This test code can be manually developed or automatically generated.
  • the user can input the source code of the software under test, preprocess the source code (e.g., extract key information from the source code to construct prompts), and then input the prompts into a language model, especially a large language model (LLM).
  • LLM large language model
  • the compilation module 103 is used to perform compilation operations on the test code and obtain compilation information.
  • This compilation information includes error logs output by the compiler during the compilation of the test code.
  • the error logs record the error types of the error codes. For example, error types may include missing class references, which is a compilation error.
  • the error logs also record the location information of the error codes, thereby enabling error localization.
  • the execution module 104 is used to perform execution operations on the test code. Specifically, the execution module 104 can call the executor to execute the test code. The execution module 104 can run the test code when it has been successfully compiled. This embodiment decouples the compilation and execution of the test code, enabling more accurate problem localization and allowing for categorized handling of different types of problems.
  • the compilation module 103 and the execution module 104 can also be coupled together; the coupled module is called the compilation and execution module, used to implement compilation, execution, and other functions.
  • the repair strategy selection module 106 is used to select a repair strategy and provide it to the test code repair device 200.
  • the repair strategy may include, but is not limited to, directly using the language model for repair, directly using template matching for repair, or prioritizing template matching repair followed by model repair. Prioritizing template matching repair means using the repair template first; if that fails, the language model is then used. Prioritizing model repair means using the language model first.
  • Different repair strategies provided by the repair strategy selection module 106 can lead to different workflows for the functional modules in the test code repair device 200.
  • the error localization module is used to obtain execution information of the test code, including stack trace information of exceptions output during test code execution. Based on this execution information, the module locates errors in the test code to obtain the position information of the erroneous code. This error code position information is then input into the model repair module 201 or the template matching repair module 203 for test code repair.
  • the model repair module 201 is used to extract context information based on the location information of the error code.
  • This context information includes at least one of the following: the erroneous test case, the error description, or the error content.
  • the prompt constructed based on the context information is then input into a language model for inference to obtain a first repair code.
  • This first repair code can be obtained by the language model repairing the error code in the test code.
  • the template matching and repair module 203 is used to determine the error type of the error code, and repair the error code according to the repair template corresponding to the error type to obtain the second repair code.
  • the first and second repair codes can be incremental code for repairing the error code, or full code (the complete test code after repair).
  • the template matching repair module 203 can also return the second repair code to the interactive device 100.
  • the interactive device 100 determines whether the second repair code was successfully repaired by executing a test operation on the test code (e.g., the second repair code, or both the test code and the second repair code) repaired by the template matching repair module 203. If the execution passes, the repair is successful; if the execution fails, the repair fails.
  • the model repair module 201 is specifically used to extract context information based on the location information of the error code when the second repair code fails, and to perform reasoning on the prompt input language model constructed based on the context information to obtain the first repair code.
  • the model repair module 201 is also used to return the first repair code to the interactive device 100.
  • the execution module 104 in the interactive device 100 is also used to execute the first repair code or test code repaired using the first repair code.
  • the feedback module 108 in the interactive device 100 is used to present the first repair code to the user when execution fails, receive feedback from the user on the first repair code, and obtain the updated first repair code.
  • this application provides a test code repair method.
  • the test code repair method of this application will be described below with reference to the accompanying drawings.
  • a flowchart of a test code repair method is shown. This method is executed by a code development platform 10, which includes an interactive device 100 (such as a plugin) and a test code repair device 200 (such as a server). The method includes the following steps:
  • Interactive device 100 obtains the test code corresponding to the source code.
  • the source code can be the code of the software under test (such as project-level code), or the code of one or more modules (or the smallest testable unit) of the software under test.
  • Test code can be code used to test the software or one or more modules of the software. Test code is used to test the functionality and/or performance of the source code. Functional testing focuses on verifying whether the behavior of the software under test meets design and user requirements, mainly checking that each function of the software under test works correctly as required. Performance testing evaluates the response speed, stability, reliability, resource consumption, and scalability of the software under test under specific conditions, involving the efficiency of the software under test running under high load or stress conditions.
  • test code can be unit test code, integration test code, or system test code.
  • the interactive device 100 can support user selection of test code.
  • This test code can be manually written by the user or automatically generated.
  • an example of automatically generated test code is used.
  • the code editing interface 300 includes a code editing window 302 and a toolbar 304.
  • the code editing window 302 can include the code 3022 of the software under test
  • the toolbar 304 can include a test code generation control 3042 and a test code repair control.
  • the interactive device 100 can present the code of the software under test to the user through the code editing window 302 of the code editing interface 300.
  • the user can select a code block to be used to generate test code from the code presented in the code editing window 302, such as a function code block or a method class code block, and then click the test code generation control 3042 to trigger the test code generation operation.
  • the interactive device 100 In response to the test code generation operation, the interactive device 100 generates test code based on the code block to be used.
  • the interactive device 100 can construct prompts based on code blocks, input the prompts into a trained LLM used to generate test code, and obtain the test code.
  • Figure 3 uses a shopping system as an example of the software under test.
  • the shopping system includes a product class named Product, which has the following attributes: product name, price, and inventory.
  • the interactive device 100 can display the test code 3024 of the user-selected code block in the code 3022 of the software under test through the code editing window 302.
  • the test code can be generated based on a testing framework (such as the JUnit testing framework).
  • the test code includes a Product object, which has attributes such as name, price, and inventory. Assert statements (such as assert statements) are used in the test code to determine whether the actual result matches the expected result.
  • test code could be:
  • ⁇ testProductName() ⁇ tests whether the ⁇ getName() ⁇ method of the ⁇ Product ⁇ object can correctly return the name of the product
  • ⁇ testProductPrice() ⁇ tests whether the ⁇ getPrice() ⁇ method of the ⁇ Product ⁇ object can correctly return the price of the product
  • ⁇ testProductStock() ⁇ tests whether the ⁇ getStock() ⁇ method of the ⁇ Product ⁇ object can correctly return the inventory of the product
  • ⁇ testProductOutOfStock() ⁇ tests whether the ⁇ isOutOfStock() ⁇ method of the ⁇ Product ⁇ object can correctly determine whether the inventory of the product is 0.
  • the interactive device 100 can invoke a compiler to compile the test code.
  • the compiler can be a local compiler or a remote compiler (e.g., a cloud compiler).
  • the interactive device 100 can select a compiler that matches the language of the test code (e.g., a programming language or program language). For example, if the test code is developed in Java, the interactive device 100 can select a Java compiler and then invoke the Java compiler to compile the test code.
  • Interactive device 100 determines whether a compilation error has occurred. If yes, proceed to S209; otherwise, proceed to S206.
  • the interactive device 100 can determine whether a compilation error has occurred by interacting with the compiler.
  • the compiler can output an error log when a compilation error occurs.
  • the error log can include the error type and error location.
  • the interactive device 100 can determine whether a compilation error has occurred by reading the error log. If the error log is empty, or no error log is read, it means that compilation is successful and there is no compilation error. If the error log is not empty, it means that compilation fails and there is a compilation error.
  • the interactive device 100 can listen for events reported by the compiler. If a warning event is detected, it means that compilation has failed; if no warning event is detected, it means that compilation is successful.
  • test code repair method of this application may be implemented without executing the above steps.
  • the interactive device 100 may not execute S202 and S204.
  • the interactive device 100 can invoke an executor to execute test code.
  • the interactive device 100 can invoke the executor to execute the compiled test code (usually executable machine code) and obtain the execution result.
  • the interactive device 100 can directly invoke the executor to execute the test code.
  • An executor is a tool for executing test code. It is typically a virtual machine; for example, if the test code is Java code, the executor could be a Java Virtual Machine (JVM).
  • the interactive device 100 can use a local compiler or a remote compiler (such as a cloud compiler) to execute the test code (e.g., compiled test code).
  • the interactive device 100 can select an executor that matches the language of the test code (e.g., programming language or program language) to execute the test code.
  • Interactive device 100 determines whether an execution error has occurred. If yes, then execute S210; otherwise, then execute S224.
  • the interactive device 100 can determine whether an execution error has occurred by interacting with the executor. For example, the interactive device 100 can listen for events reported by the executor. If an error event (such as an exception event) is detected, it indicates that an execution error exists. If no error event is detected, it indicates that no execution error exists and the test code executes successfully.
  • an error event such as an exception event
  • test code repair method of this application may also be performed without performing the above steps.
  • the software under test is software that has been launched in the production environment
  • the user may also download the above test code and its compilation information or execution information from the production environment and input it into the test code repair device 200 to perform test code repair.
  • the test code repair device 200 obtains the compilation information of the test code, locates errors in the test code based on the compilation information, and obtains the location information of the error code. Then, S212 is executed.
  • the test code repair device 200 obtains the execution information of the test code, locates errors in the test code based on the execution information, and obtains the location information of the error code. Then, S212 is executed.
  • Compilation information includes error logs output by the compiler when compiling the test code.
  • the error log records the error type of the error code, and may also record at least one of the following: the location of the error code, and related warning information.
  • the location of the error code can be represented by at least one of the following: class name, method name, or line number. Warning information may include an error description and suggested fixes.
  • Execution information includes stack traces of exceptions output during the execution of test code. Exceptions are a different type of error from errors such as missing class references (compile-time errors) and assertion failures (or assertion errors). Stack traces describe the active stack frames at a specific point in time during the program's (e.g., test code) execution. Stack frame information can include the exception type, its location (e.g., class name, method name, line number), and the method call chain that caused the exception.
  • the test code repair device 200 can parse the compilation output error log to locate the error in the test code and obtain the location information of the error code.
  • the test code repair device 200 can parse the stack trace information and obtain the location information of the error code through the location of the occurrence in the stack frame information of the stack trace information.
  • the location information of the error code can be represented by class name, method name, or line number.
  • S209 is an optional step in this application, and the test code repair method of this application may not require S209.
  • the test code is executable code, including but not limited to machine code
  • the test code repair device 200 may not need to execute S209.
  • S201 to S210 described above are specific implementations in this application's embodiments of obtaining the test code corresponding to the source code, executing the test code to obtain the execution information of the test code, and performing error location based on the execution information to obtain the location information of the error code. In practical applications, error location can also be performed in other ways to obtain the location information of the error code.
  • the code development platform 10 provides the code to users through a cloud service subscription
  • the user can pass in the test code through the interface exposed by the cloud service.
  • the cloud service can execute the test code, obtain the execution information of the test code, and perform error location based on the execution information to obtain the location information of the error code.
  • the test code repair device 200 determines the error type of the error code, repairs the error code according to the repair template corresponding to the error type, and obtains the second repair code.
  • the test code repair device 200 can obtain the error type by parsing error logs or stack trace information. For some error types, the test code repair device 200 supports using the corresponding repair template to repair the erroneous code.
  • the error types supported by the template repair device 200 can form an error type set, which includes at least one error type.
  • the error type set may include missing class references, assertion failures, or exceptions.
  • Exceptions may include runtime exceptions, also known as unchecked exceptions. Runtime exceptions are usually caused by design flaws or code logic errors. Common runtime exceptions include null pointer exceptions (NPE), array index out of bounds exceptions, type conversion exceptions, and data storage exceptions (inconsistent types when operating on arrays).
  • the test code repair device 200 can determine whether the error type of the erroneous code matches the error type set. Specifically, the test code repair device 200 can compare the error type of the erroneous code with the error type set. If the error type of the erroneous code matches any error type in the error type set, it means that the error type matches the error type set, and the test code repair device 200 can repair the erroneous code according to the repair template corresponding to the error type to obtain a second repair code.
  • test code repair device 200 can use other methods to repair the erroneous code, such as using a language model to repair the erroneous code.
  • test code repair device 200 determines whether the second repair code has been successfully repaired. If yes, then execute S224; if no, then execute S216.
  • the test code repair device 200 can return second repair code to the interactive device 100.
  • the second repair code can be either the full code after repairing the test code or incremental code that repairs the test code.
  • the repaired test code can be the second repair code; when the second repair code is incremental code, the repaired test code can be either the test code or the second repair code.
  • the interactive device 100 can determine whether the second repair code was successfully repaired by executing the repaired test code, such as the second repair code or test code repaired using the second repair code. In some examples, the interactive device 100 can compile the repaired test code (such as the second repair code or test code repaired using the second repair code). If the compilation is successful, the repaired test code continues to be executed.
  • the interactive device 100 can determine whether the second repair code was successfully repaired based on the execution result and return the repair result to the test code repair device 200. If the repair is successful, the test code repair device 200 can stop repairing, and the interactive device 100 can save the second repair code. If the repair is unsuccessful, the test code repair can continue.
  • the code development platform 10 can also be configured with a maximum number of retries, for example, the maximum number of retries can be configured as a target value. Based on this, the test code repair device 200 can obtain the compilation information or execution information of the second repair code. When the compilation information or execution information indicates that the second repair code has failed to repair, the test code repair device 200 can re-execute the code repair for the test code until the test code is successfully repaired or the number of retries reaches the target value.
  • the test code repair device 200 extracts context information based on the location information of the error code.
  • the context information includes at least one of the following: erroneous test cases, error descriptions, or error content.
  • the error description may include the error type and the location information of the error code.
  • the test code repair device 200 can obtain the error content based on the location information of the error code.
  • the error content can be content related to the error code in the compilation or execution information, such as an error record in the compilation or execution information that includes the aforementioned location information. This error record not only records the location information of the error code but may also record the error type (such as exception type) and the method call chain that caused the exception.
  • the test code repair device 200 can also generate an error description based on the compilation or execution information of the test code.
  • the test code repair device 200 obtains the erroneous test cases based on the code file where the error code is located.
  • the test cases may include the test objective, test environment, test input, and expected result.
  • the test code repair device 200 can construct a contextual information set, denoted as "C".
  • C includes the erroneous test case T ⁇ error ⁇ , the error description D ⁇ e ⁇ , and the error content C_e, as shown below:
  • Test code repair device 200 constructs a prompt based on context information.
  • the test code repair device 200 can construct prompts based on context information and a prompt template.
  • the context information can include different types, and the test code repair device 200 can fill the corresponding fields of the prompt template with different pieces of context information to obtain the prompts.
  • the prompt template may include error messages and error information.
  • Error messages indicate that errors exist in the language model test code and need to be fixed.
  • Error information provides information that can be used to fix the erroneous code, such as context information.
  • Error information may include multiple fields, such as test case, error description, and error content.
  • the test code repair device 200 fills the test case field with the erroneous test case T ⁇ error ⁇ from the context information, fills the error description field with the error type, error code location information, etc., and fills the error content field with the error from the compilation or execution information. This provides clues for error localization and analysis in the language model.
  • the prompt template may also include a fix requirement field.
  • the fix requirement field is used to populate a fix requirement for the test code that caused the error.
  • the fix requirement could be to require the language model (such as LLM) to modify the test code and output the complete test code as a code block.
  • Figure 5 shows a schematic diagram of a prompt template.
  • test template 500 can include error prompt 502, error message 504, and fix requirement 506.
  • Error prompt 502 is used to indicate that the test code has generated an error.
  • error prompt 502 can also indicate the error type.
  • error prompt 502 could be “There may be assertion errors./Your unit test has encountered an error,” where “There may be assertion errors” indicates that there may be assertion errors (assertion failure), and “Your unit test has encountered an error” indicates that the unit test code may have an error.
  • the error type “assertion” in error prompt 502 can be filled in based on context information.
  • Error message 504 can include a padding description and a region to be filled (as shown in " ⁇ error_message ⁇ " in section 5). The padding description indicates the location to fill in the error message, and the region to be filled can be filled with context information.
  • Repair request 506 can be "Modify your test code accordingly and output completed test code in a code cell," indicating a request for the language model to repair the test code and output the complete test code as a code block.
  • the test code repair device 200 requests the LLM to repair according to the prompt and obtains the first repair code.
  • the test code repair device 200 can input a prompt into the LLM to request the LLM to repair the test code based on the prompt.
  • the test code repair device 200 can use the prompt as an application programming interface (API) parameter to generate an API call request, and then invoke the LLM through the API call request to receive the first repair code returned by the LLM.
  • the first repair code is obtained by the LLM repairing the errors in the test code.
  • API application programming interface
  • the test code repair device 200 can also use a high-precision, high-performance small language model (SLM) for inference to obtain the first repair code.
  • SLM small language model
  • the steps S216 to S220 described above are a specific implementation of extracting context information based on the location information of the error code, and then using the prompt input language model constructed based on the context information for reasoning to obtain the first repair code.
  • the first repair code can also be obtained through other methods.
  • the code development platform 10 e.g., the test code repair device 200
  • the code development platform 10 can obtain the error code based on its location information, directly input the error code into the language model for reasoning, and obtain the first repair code.
  • the test code repair device 200 determines whether the first repair code was successfully repaired. If yes, then execute S224; if no, then execute S226.
  • the test code repair device 200 can return first repair code to the interaction device 100.
  • the first repair code can be either the full code after repairing the test code or incremental code that repairs the test code.
  • the repaired test code can be the first repair code.
  • the second repair code is incremental code
  • the repaired test code can be the test code repaired using the first repair code, such as a code block formed by inserting the first repair code into the test code.
  • the interaction device 100 can determine whether the first repair code was successfully repaired by executing the repaired test code, such as the first repair code or the test code repaired using the first repair code.
  • the interactive device 100 compiles the repaired test code (such as the first repaired code, or the test code repaired using the first repaired code). If the compilation succeeds, the repaired test code continues to be executed. The interactive device 100 can determine whether the first repaired code was successfully repaired based on the execution result and return the repair result to the test code repair device 200. If the repair is successful, the test code repair device 200 can stop the repair, and the interactive device 100 can save the first repaired code. If the repair is unsuccessful, the test code repair can continue.
  • the repaired test code such as the first repaired code, or the test code repaired using the first repaired code.
  • the code development platform 10 can also configure a maximum number of retries (upper limit on the number of retries) for the language model.
  • the maximum number of retries can be configured as a target value. Based on this, when the first code repair fails, the test code repair device 200 can re-execute code repair based on the LLM or other language models for the test code until the test code is successfully repaired or the number of retries reaches the target value.
  • the interactive device 100 can also present the first repair code to the user when the first repair code or the test code repaired using the first repair code fails to execute, receive feedback from the user on the first repair code, and obtain an updated first repair code.
  • the interactive device 100 can present the first repair code to the user when the number of retries reaches the target number and the repaired test code (such as the first repair code or the test code repaired using the first repair code) still fails to execute. The user can then manually modify the first repair code, and the interactive device 100 can receive feedback from the user on the first repair code and obtain an updated first repair code.
  • the interactive device 100 saves the test code that has passed execution.
  • the interactive device 100 can save the test code.
  • the second repair code is determined to be successfully repaired, the interactive device 100 can save the successfully repaired test code. If the second repair code is a full code, the successfully repaired test code can be the second repair code itself; if the second repair code is an incremental code, the successfully repaired test code can be both the second repair code and the test code.
  • the interactive device 100 can save the successfully repaired test code. If the first repair code is a full code, the successfully repaired test code can be the first repair code itself; if the first repair code is an incremental code, the successfully repaired test code can be both the first repair code and the test code.
  • test code repair method of this application may also omit the above steps S224 and S226.
  • this application provides a test code repair method.
  • This method combines template matching repair technology and language model repair technology to achieve comprehensive repair of test code.
  • the template repair technology relies on preset repair templates and can quickly locate and repair common error types.
  • the language model repair technology utilizes advanced language models to generate more accurate and complex repair solutions by analyzing error information and code context. Therefore, the test code repair method of this application is not only suitable for repairing specific types of errors but can also handle various complex error scenarios, providing more intelligent and flexible repair strategies, and has strong versatility and adaptability. This method can significantly improve the automation level of test code repair, reduce manual intervention, accelerate the iteration speed of software development and testing, and improve the overall quality of software.
  • the embodiment shown in Figure 2 illustrates how language model repair is used as a supplementary means to further improve the success rate of test code repair when template matching repair fails.
  • the code development platform can also provide template matching repair-related information, such as second repair code or intermediate template matching results, as part of the context information to the language model, thereby generating more accurate first repair code.
  • the code development platform 10 can also directly use the language model for test code repair, or directly use the repair template for test code repair; this application does not impose any limitations on this.
  • Error types can include missing class references (or compilation errors), assertion failures (assertion errors), or exceptions.
  • repair templates can include import repair templates, assertion repair templates, or exception repair templates.
  • the error type of the error code includes missing class references, and correspondingly, the second repair code may include import statements.
  • the code development platform 10 can determine the missing class name and construct a symbol index based on project dependency libraries, development tool libraries, or third-party libraries.
  • the symbol index includes the fully qualified name of the accessible class.
  • the fully qualified name also called the fully qualified class name, usually refers to the fully qualified class name and typically includes the package path.
  • the fully qualified name of a Java class could be java.lang.String.
  • the missing class name refers to the class name of the missing class reference. This class name is usually an unqualified class name, also called a short name, and typically does not include the package path or package name.
  • the unqualified class name of a Java class could be String.
  • the code development platform 10 matches the missing class name with the symbol index to obtain the fully qualified name corresponding to the missing class name. Then, the code development platform 10 inserts this fully qualified name into the import repair template to obtain the import statement.
  • the code development platform 10 can repair the test code using either incremental updates or full updates.
  • the second fix code can be incremental code, in which case it includes the aforementioned import statements.
  • the second fix code can be full code, in which case it can include test code and import statements.
  • code development platform 10 can insert import statements into test code to obtain the second fix code.
  • the import repair template is a strategy to fix "symbol not found" errors caused by missing class or interface imports during compilation.
  • the core of this template is to identify missing class references and automatically insert the corresponding import statements. An example is provided below to illustrate this.
  • p represents the file path
  • N ⁇ row ⁇ and N ⁇ col ⁇ represent the line number and column number where the error occurred, respectively, and the missing class name or interface name S.
  • the code development platform 10 performs the following steps to implement test code repair based on the imported package repair template.
  • Step 1 The code development platform 10 constructs a symbol index (Index, I) based on the project dependency library, development tool library, and third-party library.
  • the development toolkit is related to the programming language used in development.
  • the DMP could be the Java Development Kit (JDK) library.
  • JDK Java Development Kit
  • This index contains the fully qualified names of all accessible Java classes, implementing a mapping from S to R, where R represents the fully qualified name of the symbol S.
  • Step 2 The code development platform 10 uses regular expressions to extract the missing class name S from the error message, matches it in the symbol index I, and finds the corresponding fully qualified name R.
  • Step 3 The code development platform 10 fills the fully qualified name R of the matching import repair template, generates a complete import statement, and inserts the import statement after the existing import statement in file p.
  • the error type of the error code includes assertion failure.
  • the code development platform 10 can determine the assertion type of the erroneous assertion in the error code, and then, based on the assertion type, choose to update the assertion repair template or update the assertion parameters, thereby repairing the erroneous assertion.
  • the code development platform 10 can extract the expected value of the erroneous assertion from the error code and the actual value of the erroneous assertion from the test report. Then, based on the assertion repair template corresponding to the assertion type, it replaces the expected value in the assertion parameters of the erroneous assertion with the actual value. In other words, for equality-type erroneous assertions, the code development platform 10 uses the existing assertion template as the assertion repair template and replaces the assertion parameters of the erroneous assertion, such as replacing the expected value with the actual value, thereby achieving rapid repair of equality-type erroneous assertions.
  • the code development platform 10 can generate second repair code based on the assertion parameters in the erroneous assertion and the second assertion repair template corresponding to the first assertion repair template used by the erroneous assertion.
  • the Boolean logic of the second assertion repair template is the opposite of that of the first assertion repair template.
  • the code development platform 10 achieves rapid repair of Boolean type erroneous assertions by changing the template while keeping the assertion parameters unchanged.
  • the assertion repair template is a strategy for repairing assertion failures in unit tests.
  • the core of the assertion repair template is to identify the cause of the assertion failure and automatically adjust the expected result of the assertion to match the actual test result.
  • the expected result can be an expected value
  • the actual result can be an actual value.
  • Step 1 The code development platform 10 determines the assertion type of the error assertion.
  • the assertion type is an equality type
  • the expected value V ⁇ expected ⁇ of the error assertion is extracted from the error assertion, and the corresponding actual value V ⁇ actual ⁇ is extracted from the test report, and then Step 2 is executed; when the assertion type is a boolean type, Step 3 is executed.
  • the assertion type can include, but is not limited to, boolean type and equality type.
  • Boolean type can include assertTrue, assertFalse, assertNull, and assertNotNull, and equality type can include assertEquals.
  • Step 2 In the assertion repair template corresponding to the assertion type, the code development platform 10 replaces V ⁇ expected ⁇ in the assertion parameter of the erroneous assertion with V ⁇ actual ⁇ .
  • Step 3 The code development platform 10 generates the second repair code based on the assertion parameters in the error assertion and the second assertion repair template corresponding to the first assertion repair template used by the error assertion.
  • the Boolean logic of the second assertion repair template is the opposite of that of the first assertion repair template.
  • the code development platform 10 uses regular expressions to extract the actual value in the test report, processes the extracted actual value, such as removing redundant parentheses or special characters, and then constructs a replacement string according to the type of the actual value.
  • the replacement string can be represented as actualValue.
  • the replacement string is used to replace the first parameter expectedValue in the assertEquals method with actualValue.
  • the error type of the error code includes exceptions
  • the repair template can include an exception repair template
  • the second repair code can include the exception handling code block corresponding to the exception.
  • the exception repair template is a repair strategy for exception error types. It can catch and handle these exceptions by inserting or improving exception handling mechanisms around code blocks that may throw exceptions, thereby preventing the program from terminating due to unhandled exceptions.
  • the code development platform 10 can determine the exception type from the exception's stack trace information, fill the exception type into the exception repair template, and obtain the exception handling code block (e.g., an exception handling statement).
  • the second repair code is incremental code, it can include the aforementioned exception handling code block.
  • the second repair code is full code, it can include test code and the exception handling code block. For example, the code development platform 10 can insert an exception handling code block after the error code in the test code to obtain the second repair code.
  • Step 1 The code development platform 10 fills the exception type E into the exception repair template, generates a complete exception handling code block, and inserts the exception handling code block into the file p.
  • the exception handling code block can be located before code block C.
  • Step 2 After the insertion is completed, the code development platform 10 performs a syntax check to ensure that the new code snippet conforms to the Java syntax specification and avoids introducing new compilation errors.
  • the code development platform 10 can recompile and execute the repaired test code to verify whether the repair was successful. If the compilation and execution are successful, the repair process ends; if there are still errors, the code development platform 10 can return to the exception information extraction stage and continue to process the next error.
  • the exception when an exception is thrown in a line of code in the test code, the exception can be caught and repaired by inserting exception handling statements.
  • the code development platform 10 can use try-catch statements to include the line of code that may throw an exception and handle the expected exception type in the catch block.
  • the aforementioned repair templates are examples of preset static repair templates.
  • the code development platform 10 can generate dynamic repair templates in real time based on the error type, without relying on preset static repair templates, thus improving the flexibility and accuracy of repair.
  • the code development platform 10 can use the interactive device 100 to allow developers to interact more deeply with the backend repair templates or models, propose modifications, or select multiple possible repair solutions, thereby enabling more precise control over the test code repair process.
  • test code repair method of this application is not only applicable to the repair of Java unit test code, but can also be widely applied to other technical fields, such as embedded system development, mobile application development, and network security.
  • code often needs to be optimized to meet memory and processing power limitations. Therefore, the test code repair method of this application can not only fix errors, but also optimize the code to reduce resource consumption.
  • the repair template can include preset templates for resource optimization, while language model repair can be trained to identify and propose solutions to reduce the resource requirements of code execution.
  • template repair based on user interface (UI) templates/user experience (UX) templates can be used, specifically for repairing code defects that may affect the user interface.
  • Language model repair can optimize repair suggestions by analyzing error information related to the user interface, ensuring smooth application operation.
  • code repair needs to address not only functional errors, but also issues that may lead to security vulnerabilities.
  • Template repair can introduce repair templates for common security vulnerabilities, such as defense against SQL injection or cross-site scripting (XSS) attacks.
  • Language model repair can be further developed to generate repair code based on specific information about security vulnerabilities, thereby improving system security.
  • this application also provides a code development platform 10.
  • the code development platform 10 is used to integrate functions into applications. As shown in Figure 1, the code development platform 10 includes:
  • the test code selection module 102 is used to obtain the test code corresponding to the source code, and the test code is used to test the functionality and/or performance of the source code;
  • the execution module 104 is used to execute the test code and obtain the execution information of the test code, the execution information including the stack trace information of the exceptions output when the test code is executed;
  • the error location module is used to locate errors in the test code based on the execution information and obtain the location information of the error code.
  • the model repair module 201 is used to extract context information based on the location information of the error code.
  • the context information includes at least one of the error test case, error description, or error content.
  • the module then uses a prompt input language model built based on the context information to perform reasoning to obtain a first repair code.
  • the first repair code is obtained by the language model repairing the error code in the test code.
  • test code selection module 102 execution module 104, error location module, and model repair module 201 can be implemented in hardware or software.
  • the test code selection module 102, execution module 104, error location module, and model repair module 201 can be applications running on computing devices, such as computing engines. These applications can also be virtualized and provided to users as virtualization services.
  • Virtualization services can include virtual machine (VM) services, bare metal server (BMS) services, or container services.
  • VM services can be services that use virtualization technology to create virtual machine (VM) resource pools on multiple physical hosts to provide VMs for users to use on demand.
  • BMS services are services that use virtualization technology to create BMS resource pools on multiple physical hosts to provide BMS for users to use on demand.
  • Container services are services that use virtualization technology to create container resource pools on multiple physical hosts to provide containers for users to use on demand.
  • a VM is a simulated virtual computer, that is, a logical computer.
  • a BMS is a scalable, high-performance computing service with computing performance indistinguishable from traditional physical machines and features secure physical isolation.
  • Containers are a kernel virtualization technology that provides lightweight virtualization to isolate user space, processes, and resources. It should be understood that the VM service, BMS service, and container service mentioned above are merely specific examples. In practical applications, virtualization services can also include other lightweight or heavyweight virtualization services, which are not specifically limited here.
  • the test code selection module 102, the execution module 104, the error location module, and the model repair module 201 may include at least one computing device, such as a server.
  • the test code selection module 102, the execution module 104, the error location module, and the model repair module 201 may also be implemented using an application-specific integrated circuit (ASIC) or a programmable logic device (PLD).
  • ASIC application-specific integrated circuit
  • PLD programmable logic device
  • the PLD may be a complex programmable logical device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), or any combination thereof.
  • the code development platform 10 further includes a feedback module 108:
  • the running module 104 is further configured to execute the first repair code or the test code repaired using the first repair code;
  • the feedback module 108 is used to present the first repair code to the user when the execution fails, receive feedback from the user on the first repair code, and obtain the updated first repair code.
  • the feedback module 108 can be implemented in software or hardware.
  • the feedback module 108 can be an application running on a computing device, such as a computing engine. This application can also be virtualized and provided to users as a virtualization service via VMs, containers, etc.
  • the feedback module 108 can include at least one computing device, such as a server.
  • the code development platform 10 also includes:
  • the template matching and repair module 203 is used to determine the error type of the error code, repair the error code according to the repair template corresponding to the error type, and obtain a second repair code;
  • the model repair module 201 is specifically used for:
  • the context information is extracted based on the location information of the error code.
  • the error type of the error code includes assertion failure
  • the template matching and repair module 203 is specifically used for:
  • the expected value in the assertion parameter of the erroneous assertion is replaced with the actual value to obtain the second repair code.
  • the template matching and repair module 203 can be implemented in software or hardware.
  • the template matching and repair module 203 can be an application running on a computing device, such as a computing engine. This application can also be virtualized and provided to users as a virtualization service via VMs, containers, etc.
  • the template matching and repair module 203 can include at least one computing device, such as a server.
  • the template matching and repair module 203 is further configured to:
  • a second repair code is generated based on the assertion parameters in the error assertion and the second assertion repair template corresponding to the first assertion repair template used by the error assertion.
  • the Boolean logic of the second assertion repair template is the opposite of the Boolean logic of the first assertion repair template.
  • the error type of the error code includes an exception
  • the second repair code includes an exception handling code block corresponding to the exception
  • the template matching and repair module is specifically used for:
  • the code development platform 10 also includes:
  • the compilation module 103 is used to compile the test code and obtain the compilation information of the test code.
  • the compilation information includes the error log output by the compiler when compiling the test code.
  • the error log records the error type of the error code.
  • the second repair code includes an import statement
  • the template matching and repair module 203 is specifically used for:
  • the missing class name is matched with the symbol index to obtain the fully qualified name corresponding to the missing class name;
  • the compilation module 103 can be implemented in software or hardware.
  • the compilation module 103 can be an application running on a computing device, such as a computing engine. This application can also be virtualized and provided to users as a virtualization service via VMs, containers, etc.
  • the compilation module 103 can include at least one computing device, such as a server.
  • the compilation module 103 and the runtime module 104 in Figure 1 can also be coupled into a single module, for example, coupled into a compilation and runtime module.
  • Figure 1 is merely one specific implementation of the code development platform 10. In other possible implementations of this application, the compilation and execution of test code can also be performed in other ways.
  • model repair module 201 is further configured to:
  • the code repair is re-executed for the test code until the test code is successfully repaired or the number of retries reaches the target value.
  • the computing device 1000 includes: a bus 1002, a processor 1004, a memory 1006, and a communication interface 1008.
  • the processor 1004, the memory 1006, and the communication interface 1008 communicate with each other via the bus 1002.
  • the computing device 1000 can be a server or a terminal device. It should be understood that this application does not limit the number of processors and memories in the computing device 1000.
  • Bus 1002 can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. Buses can be categorized as address buses, data buses, control buses, etc. For ease of illustration, only one line is used in Figure 10, but this does not imply that there is only one bus or one type of bus. Bus 1002 can include pathways for transmitting information between various components of computing device 1000 (e.g., memory 1006, processor 1004, communication interface 1008).
  • PCI Peripheral Component Interconnect
  • EISA Extended Industry Standard Architecture
  • the processor 1004 may include any one or more of the following processors: central processing unit (CPU), graphics processing unit (GPU), microprocessor (MP), or digital signal processor (DSP).
  • CPU central processing unit
  • GPU graphics processing unit
  • MP microprocessor
  • DSP digital signal processor
  • the memory 1006 may include volatile memory, such as random access memory (RAM).
  • the memory 1006 may also include non-volatile memory, such as read-only memory (ROM), flash memory, hard disk drive (HDD), or solid-state drive (SSD).
  • ROM read-only memory
  • HDD hard disk drive
  • SSD solid-state drive
  • the memory 1006 stores executable program code, which the processor 1004 executes to implement the aforementioned code generation method.
  • the memory 1006 stores instructions from the code development platform 10 for executing the code generation method.
  • the communication interface 1008 uses transceiver modules such as, but not limited to, network interface cards and transceivers to enable communication between the computing device 1000 and other devices or communication networks.
  • the computing device cluster includes at least one computing device.
  • the computing device can be a server, such as a central server, an edge server, or a local server in a local data center.
  • the computing device can also be a terminal device such as a desktop computer, a laptop computer, or a smartphone.
  • the computing device cluster includes at least one computing device 1000.
  • the memory 1006 of one or more computing devices 1000 in the computing device cluster may store instructions from the same code development platform 10 for executing code generation methods.
  • one or more computing devices 1000 in the computing device cluster can also be used to execute some of the instructions used by the code development platform 10 to execute the code generation method.
  • a combination of one or more computing devices 1000 can jointly execute the instructions used by the code development platform 10 to execute the code generation method.
  • the memory 1006 in different computing devices 1000 in the computing device cluster can store different instructions for executing some functions of the code development platform 10.
  • Figure 12 illustrates one possible implementation.
  • two computing devices 1000A and 1000B are connected via a communication interface 1008.
  • the memory in computing device 1000A stores instructions for executing the functions of the test code selection module 102 and the execution module 104.
  • the memory in computing device 1000B stores instructions for executing the functions of the error location module and the model repair module 201.
  • the memory in computing device 1000A also stores instructions for executing the functions of the compilation module 103, the repair strategy selection module 106, and the feedback module 108, while the memory in computing device 1000B also stores instructions for executing the function of the template matching repair module 203.
  • the memory 1006 of computing devices 1000A and 1000B jointly stores the instructions used by the code development platform 10 to execute the code generation method.
  • connection method between the computing device clusters shown in Figure 12 can be considered because the code generation method provided in this application requires a lot of resources to run the language model, thereby realizing the generation of the first repair code based on language model reasoning. Therefore, it is considered to dedicate the functions implemented by the error location module and the model repair module 201 in the test code repair device 200 to independent computing devices. For example, the functions implemented by the relevant modules in the interaction device 100 are executed by computing device 1000A, and the functions implemented by the relevant modules in the test code repair device 200 are executed by computing device 1000B.
  • computing device 1000A shown in Figure 12 can also be performed by multiple computing devices 1000.
  • computing device 1000B can also be performed by multiple computing devices 1000.
  • one or more computing devices in a computing device cluster can be connected via a network.
  • This network can be a wide area network (WAN) or a local area network (LAN), etc.
  • Figure 13 illustrates one possible implementation.
  • two computing devices 1000C and 1000D are connected via a network. Specifically, they are connected to the network through communication interfaces in each computing device.
  • the memory 1006 in computing device 1000C stores instructions for executing the functions of relevant modules in the interactive device 100, such as instructions for executing the functions of the test code selection module 102 and the execution module 104.
  • the memory 1006 in computing device 1000C also stores instructions for executing the functions of the compilation module 103, the repair strategy selection module 106, and the feedback module 108.
  • the memory 1006 in the computing device 1000D stores instructions for executing the functions of relevant modules in the test code repair device 200.
  • the memory of the computing device 1000D stores instructions for executing the functions of the error location module and the model repair module 201.
  • the memory of the computing device 1000D also stores instructions for executing the functions of the template matching repair module 203.
  • connection method between the computing device clusters shown in Figure 13 can be considered as follows: taking into account that the code generation method provided in this application requires a lot of resources for reasoning to generate the first repair code, it is considered that the functions implemented by the relevant modules in the test code repair device 200 are handed over to the computing device 1000D for execution.
  • computing device 1000C shown in Figure 13 can also be performed by multiple computing devices 1000.
  • computing device 1000D can also be performed by multiple computing devices 1000.
  • the computer-readable storage medium can be any available medium that a computing device can store, or a data storage device such as a data center containing one or more available media.
  • the available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid-state drive).
  • the computer-readable storage medium includes instructions that instruct the computing device to execute the code generation method described above applied to the code development platform 10.
  • the computer program product may be a software or program product containing instructions, capable of running on a computing device or stored on any usable medium.
  • the computer program product When the computer program product is run on at least one computing device, it causes the at least one computing device to execute the above-described code generation method.

Landscapes

  • Debugging And Monitoring (AREA)

Abstract

The present application discloses a test code repairing method applied to a code development platform. The method comprises: obtaining a test code corresponding to a source code, and then executing the test code to obtain execution information of the test code, wherein the execution information comprises abnormal stack tracking information output during execution of the test code; on the basis of the execution information, performing fault localization on the test code to obtain location information of a faulty code; on the basis of the location information of the faulty code, extracting context information, wherein the context information comprises at least one of a faulty test case, a fault description, or the faulty content; and inputting a prompt constructed on the basis of the context information into a language model and performing inference, so as to obtain a first repaired code. The method is used to perform fault localization in light of the execution information, extract the context information on the basis of the location information of the faulty code, and, on the basis of the context information, generate accurate and complex repaired code via an advanced language model, thereby adapting to various complex fault scenarios and improving repair efficiency and accuracy.

Description

一种测试代码修复方法及相关设备A test code repair method and related equipment

本申请要求于2024年05月29日提交国家知识产权局、申请号为202410683284.2、发明名称为“一种单元测试修复方法及相关设备”的中国专利申请的优先权,以及要求于2024年7月17日提交国家知识产权局、申请号为202410961426.7、发明名称为“一种测试代码修复方法及相关设备”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims priority to Chinese Patent Application No. 202410683284.2, filed on May 29, 2024, entitled "A Unit Test Repair Method and Related Equipment", and to Chinese Patent Application No. 202410961426.7, filed on July 17, 2024, entitled "A Test Code Repair Method and Related Equipment", the entire contents of which are incorporated herein by reference.

技术领域Technical Field

本申请涉及人工智能(artificial intelligence,AI)技术领域,尤其涉及一种测试代码修复方法、代码开发平台、计算设备集群、计算机可读存储介质以及计算机程序产品。This application relates to the field of artificial intelligence (AI) technology, and in particular to a test code repair method, a code development platform, a computing device cluster, a computer-readable storage medium, and a computer program product.

背景技术Background Technology

随着计算机技术的不断演进,软件(software)变得日益复杂,对软件质量的要求也越来越高。作为确保软件质量的基本手段,软件测试尤其是单元测试对于早期发现错误并修复错误至关重要。尽管软件测试具有极高的价值,但是测试代码可能存在错误,该错误可能是由于逻辑错误、编码失误或是环境配置问题引起。错误的测试代码不仅不能正确地检测出软件中的问题,反而可能引导开发者进行错误的代码修改,导致软件质量下降,甚至引入新的错误。As computer technology continues to evolve, software is becoming increasingly complex, and the requirements for software quality are also rising. As a fundamental means of ensuring software quality, software testing, especially unit testing, is crucial for early detection and fix of errors. Although software testing is extremely valuable, test code may contain errors, which could be caused by logical flaws, coding mistakes, or environment configuration issues. Incorrect test code not only fails to accurately detect problems in the software but may also lead developers to make incorrect code modifications, resulting in decreased software quality or even introducing new errors.

由于软件规模的不断增大和复杂度的不断提升,手动编写和维护测试代码需要开发者投入大量时间检查和修复测试代码中的错误。如此,不仅降低了开发效率,也增加了软件的整体成本。构建自动化的测试代码修复技术有助于减轻开发者负担,提高测试的效率和准确性。As software grows in size and complexity, manually writing and maintaining test code requires developers to invest significant time in checking and fixing errors. This not only reduces development efficiency but also increases the overall cost of the software. Developing automated test code fixing techniques can help alleviate the burden on developers and improve the efficiency and accuracy of testing.

目前,自动化的测试代码修复方法大多依赖于人工干预或者启发式算法,修复效率低下,准确率不足。Currently, most automated test code repair methods rely on manual intervention or heuristic algorithms, resulting in low repair efficiency and insufficient accuracy.

发明内容Summary of the Invention

本申请提供了一种测试代码修复方法,该方法通过结合执行信息进行错误定位,根据错误代码的位置信息提取上下文信息,基于该上下文信息,通过先进的语言模型生成更加精确和复杂的修复代码,以适应各种复杂的错误场景,不局限于特定的错误类型,进而提高修复效率和准确性。本申请还提供了与上述方法对应的代码开发平台、计算设备集群、计算机可读存储介质以及计算机程序产品。This application provides a test code repair method. This method locates errors by combining execution information, extracts context information based on the location of the error code, and generates more accurate and complex repair code using an advanced language model based on this context information. This adapts to various complex error scenarios, is not limited to specific error types, and thus improves repair efficiency and accuracy. This application also provides a code development platform, computing device cluster, computer-readable storage medium, and computer program product corresponding to the above method.

第一方面,本申请提供一种测试代码修复方法。该方法可以由代码开发平台执行。代码开发平台通常用于开发并维护测试代码。代码开发平台可以通过不同形态提供给用户使用。例如,代码开发平台可以是独立的软件系统,包括但不限于集成开发环境(integrated development environment,IDE)或者是代码编辑器。在该形态下,开发者可以提供代码开发平台的软件包给用户,由用户自行部署,例如是部署在本地计算设备,以实现对测试代码的全面修复。又例如,代码开发平台也可以集成于其他软件或平台,例如以插件、组件的形式集成于测试平台。如此可以实现通过嵌入式方案为用户提供无缝的修复体验。还例如,代码开发平台可以部署在云环境,以云服务的形式提供给用户订阅使用。其中,云环境可以是多个计算设备形成的云计算集群,包括但不限于中心云(中心计算设备形成的云计算集群)、边缘云(边缘计算设备形成的云计算集群)。云服务订阅模式允许用户通过互联网访问相应的云服务,以执行本申请的测试代码修复方法,无需本地安装软件包,具有较高灵活性和可扩展性。在一些可能的实现方式中,代码开发平台也可以是具有测试代码开发能力的硬件系统,例如是具有测试代码开发能力的计算设备集群。计算设备集群运行时,执行本申请的测试代码修复方法。Firstly, this application provides a method for repairing test code. This method can be executed by a code development platform. Code development platforms are typically used to develop and maintain test code. Code development platforms can be provided to users in different forms. For example, a code development platform can be a standalone software system, including but not limited to an integrated development environment (IDE) or a code editor. In this form, the developer can provide the code development platform software package to the user, who can then deploy it themselves, for example, on a local computing device, to achieve comprehensive repair of the test code. Alternatively, the code development platform can be integrated into other software or platforms, for example, as a plugin or component. This allows for a seamless repair experience for users through an embedded solution. Furthermore, the code development platform can be deployed in a cloud environment and provided to users for subscription as a cloud service. The cloud environment can be a cloud computing cluster formed by multiple computing devices, including but not limited to a central cloud (a cloud computing cluster formed by central computing devices) and an edge cloud (a cloud computing cluster formed by edge computing devices). The cloud service subscription model allows users to access the corresponding cloud service via the Internet to execute the test code repair method of this application, without the need for local software package installation, offering high flexibility and scalability. In some possible implementations, the code development platform can also be a hardware system with test code development capabilities, such as a cluster of computing devices with test code development capabilities. When the computing device cluster is running, it executes the test code repair method of this application.

具体地,代码开发平台可以获取源代码对应的测试代码,改测试代码用于对源代码的功能和/或性能进行测试,然后代码开发平台执行测试代码,获得测试代码的执行信息。其中,执行信息包括执行测试代码时输出的异常的堆栈追踪信息。然后代码开发平台可以根据执行信息对测试代码进行错误定位,获得错误代码的位置信息,根据错误代码的位置信息,提取上下文信息。其中,上下文信息包括错误的测试用例、错误描述或错误内容中的至少一种。接着代码开发平台可以将基于上下文信息构建的提示输入语言模型进行推理,获得第一修复代码。该第一修复代码为语言模型对测试代码中的错误代码进行修复得到。Specifically, the code development platform can obtain the test code corresponding to the source code. This test code is used to test the functionality and/or performance of the source code. The platform then executes the test code and obtains its execution information, including stack traces of any exceptions output during execution. The platform can then locate errors in the test code based on this information, obtaining the location of the erroneous code. Based on this location, it extracts contextual information, including at least one of the following: erroneous test cases, error descriptions, or error content. The platform can then use a language model built based on this contextual information to reason and obtain a first corrective code. This first corrective code is obtained by the language model correcting the erroneous code in the test code.

该方法通过先结合测试代码的执行信息进行错误定位,然后根据错误代码的位置信息提取上下文信息,基于该上下文信息,通过先进的语言模型生成更加精确和复杂的修复代码,以适应各种复杂的错误场景,不局限于特定的错误类型,如此可以减少人工干预,提高测试代码修复的自动化水平,进而提高修复效率和准确性,加快软件开发和测试的迭代速度,提升软件的整体质量。而且,还方法可以针对不同错误类型进行修复,具有很强的通用性和适应性。This method first locates errors by combining the execution information of the test code, then extracts contextual information based on the location of the error code. Based on this contextual information, it generates more accurate and complex repair code using an advanced language model to adapt to various complex error scenarios, not limited to specific error types. This reduces manual intervention, improves the automation level of test code repair, and thus improves repair efficiency and accuracy, accelerates the iteration speed of software development and testing, and enhances the overall quality of the software. Furthermore, this method can repair different error types, demonstrating strong versatility and adaptability.

在一些可能的实现方式中,代码开发平台还可以执行第一修复代码或者使用第一修复代码修复的测试代码。其中,第一修复代码为全量代码时,代码开发平台可以执行该第一修复代码。第一修复代码为增量代码时,代码开发平台可以执行使用第一修复代码修复的测试代码,例如是测试代码中插入第一修复代码形成的代码块,或者是是测试代码中使用第一修复代码替换错误代码的代码块。当执行不通过,代码开发平台向用户呈现第一修复代码,接收用户对第一修复代码的反馈,获得更新后的第一修复代码。In some possible implementations, the code development platform can also execute the first fix code or test code fixed using the first fix code. Specifically, if the first fix code is the full code, the code development platform can execute it. If the first fix code is incremental code, the code development platform can execute the test code fixed using the first fix code, such as inserting a code block containing the first fix code into the test code, or replacing an erroneous code block with the first fix code in the test code. If execution fails, the code development platform presents the first fix code to the user, receives user feedback on the first fix code, and obtains an updated first fix code.

该方法在自动修复测试代码基础上,还引入人工修复通道,支持用户对第一修复代码进行修改等反馈操作,以进一步提高修复准确度和修复效率。In addition to automatically repairing test code, this method also introduces a manual repair channel, allowing users to provide feedback such as modifying the first repair code, thereby further improving the accuracy and efficiency of the repair.

在一些可能的实现方式中,代码开发平台还可以确定错误代码的错误类型,根据错误类型对应的修复模板对错误代码进行修复,获得第二修复代码。相应地,当第二修复代码修复失败,代码开发平台可以根据错误代码的位置信息,提取上下文信息。In some possible implementations, the code development platform can also determine the error type of the error code, fix the error code according to the corresponding repair template, and obtain a second repair code. Correspondingly, if the second repair code fails to fix the error, the code development platform can extract context information based on the location information of the error code.

该方法结合模板修复技术和语言模型修复技术,实现了对测试代码的全面修复。其中,模板修复技术依赖于预设的修复模板,能够快速定位并修复常见类型的错误,语言模型修复技术可以生成更加精确和复杂的修复方案,应对复杂的错误场景。This method combines template repair and language model repair techniques to achieve comprehensive repair of test code. Template repair relies on pre-defined repair templates to quickly locate and fix common error types, while language model repair can generate more precise and complex repair solutions to handle complex error scenarios.

在一些可能的实现方式中,错误代码的错误类型包括断言失败。相应地,代码开发平台可以先确定错误代码中错误断言的断言类型。当断言类型为相等类型,代码开发平台从错误代码中提取错误断言的预期值,从测试报告中提取错误断言的实际值,然后根据断言类型对应的断言修复模板,将错误断言的断言参数中的预期值替换为实际值,获得第二修复代码。In some possible implementations, the error type of the error code includes assertion failure. Accordingly, the code development platform can first determine the assertion type of the erroneous assertion in the error code. When the assertion type is an equality type, the code development platform extracts the expected value of the erroneous assertion from the error code, extracts the actual value of the erroneous assertion from the test report, and then replaces the expected value in the assertion parameter of the erroneous assertion with the actual value according to the assertion repair template corresponding to the assertion type, thus obtaining the second repair code.

在该方法中,针对相等类型的错误断言,代码开发平台可以使用原有的断言模板作为断言修复模板,将错误断言的断言参数进行替换,例如是将预期值替换为实际值,从而实现相等类型的错误断言的快速修复。In this method, for erroneous assertions of the equality type, the code development platform can use the original assertion template as the assertion repair template to replace the assertion parameters of the erroneous assertion, such as replacing the expected value with the actual value, thereby achieving rapid repair of erroneous assertions of the equality type.

在一些可能的实现方式中,当所述断言类型为布尔类型,代码开发平台可以根据错误断言中的断言参数以及错误断言使用的第一断言修复模板对应的第二断言修复模板,生成第二修复代码,其中,第二断言修复模板的布尔逻辑与所述第一断言修复模板的布尔逻辑相反。In some possible implementations, when the assertion type is Boolean, the code development platform can generate second repair code based on the assertion parameters in the error assertion and the second assertion repair template corresponding to the first assertion repair template used by the error assertion, wherein the Boolean logic of the second assertion repair template is opposite to that of the first assertion repair template.

在该方法中,针对布尔类型的错误断言,代码开发平台可以通过更换模板(例如是将错误断言使用的断言修复模板更换为布尔逻辑相反的断言修复模板),保持断言参数不变的方式快速修复布尔类型的错误断言。In this method, for Boolean type error assertions, the code development platform can quickly fix Boolean type error assertions by changing the template (for example, changing the assertion repair template used by the error assertion to an assertion repair template with the opposite Boolean logic) while keeping the assertion parameters unchanged.

在一些可能的实现方式中,所述错误代码的错误类型包括异常,第二修复代码可以包括异常对应的异常处理代码块。代码开发平台可以从异常的堆栈追踪信息中确定异常类型,然后将异常类型填充到异常修复模板,获得异常处理代码块。其中,第二修复代码为增量代码时,第二修复代码可以包括上述异常处理代码块。第二修复代码为全量代码时,第二修复代码可以包括测试代码和异常处理代码块,例如,代码开发平台在测试代码中的错误代码之后插入异常处理代码块,获得第二修复代码。In some possible implementations, the error type of the error code includes an exception, and the second fix code may include the exception handling code block corresponding to the exception. The code development platform can determine the exception type from the exception's stack trace information, and then fill the exception type into the exception fix template to obtain the exception handling code block. When the second fix code is incremental code, it may include the aforementioned exception handling code block. When the second fix code is full code, it may include test code and the exception handling code block; for example, the code development platform inserts an exception handling code block after the error code in the test code to obtain the second fix code.

该方法针对异常类型的错误代码,可以通过将异常类型填充至异常修复模板,从而实现异常处理,由此实现快速修复异常类型的错误代码。需要说明,该方法的异常修复模板支持对不同异常类型进行快速修复,而不局限于空指针异常等特定异常类型,具有较高可用性。This method addresses error codes related to exception types. By filling the exception type into an exception repair template, exception handling is achieved, thus enabling rapid repair of error codes of exception types. It should be noted that the exception repair template of this method supports rapid repair of various exception types, and is not limited to specific exception types such as null pointer exceptions, thus possessing high usability.

在一些可能的实现方式中,代码开发平台还可以编译测试代码,获得测试代码的编译信息。其中,编译信息包括编译器对测试代码进行编译输出的错误日志,该错误日志记录有错误代码的错误类型。当错误代码的错误类型包括缺失类引用,第二修复代码可以包括导入语句。其中,代码开发平台可以确定缺失的类名,基于项目依赖库、开发工具库或者三方库,构建符号索引。其中,符号索引包括可访问类的完全限定名,然后将缺失的类名和符号索引进行匹配,获得缺失的类名对应的完全限定名。代码开发平台可以将完全限定名插入导包修复模板,获得导入语句。需要说明的是,第二修复代码可以是增量代码,在该情况下,第二修复代码可以包括上述导入语句。第二修复代码也可以是全量代码,在该情况下,第二修复代码可以包括测试代码和导入语句。例如,代码开发平台可以在测试代码中插入导入语句,获得第二修复代码。In some possible implementations, the code development platform can also compile test code to obtain compilation information. This compilation information includes error logs output by the compiler, which record the error type of the erroneous code. When the error type includes a missing class reference, the second fix can include import statements. The code development platform can determine the missing class name and construct a symbol index based on project dependencies, development tool libraries, or third-party libraries. This symbol index includes the fully qualified names of accessible classes. The platform then matches the missing class name with the symbol index to obtain the fully qualified name corresponding to the missing class name. The code development platform can insert this fully qualified name into the import fix template to obtain the import statement. It should be noted that the second fix can be incremental code, in which case it can include the aforementioned import statements. Alternatively, the second fix can be full code, in which case it can include both test code and import statements. For example, the code development platform can insert import statements into the test code to obtain the second fix.

该方法还支持针对缺失类引用等编译类型的错误代码,通过导包修复模板生成导入语句,从而实现快速修复缺失类引用的错误代码。This method also supports generating import statements using import repair templates for compilation error codes such as missing class references, thereby enabling rapid repair of error codes with missing class references.

在一些可能的实现方式中,当第一修复代码修复失败,代码开发平台还可以针对测试代码重新执行代码修复,直至测试代码被修复成功或者重试次数达到目标值。In some possible implementations, if the first code fix fails, the code development platform can re-execute the code fix for the test code until the test code is successfully fixed or the number of retries reaches the target value.

该方法支持设置最大重试次数,代码开发平台可以基于语言模型对测试代码进行多次修复,由此可以提高修复成功率和自动化程度。This method supports setting a maximum number of retries, and the code development platform can perform multiple repairs on the test code based on the language model, thereby improving the repair success rate and the degree of automation.

第二方面,本申请提供一种代码开发平台。所述代码开发平台包括:Secondly, this application provides a code development platform. The code development platform includes:

测试代码选取模块,用于获取源代码对应的测试代码,所述测试代码用于对所述源代码的功能和/或性能进行测试;The test code selection module is used to obtain the test code corresponding to the source code, and the test code is used to test the functionality and/or performance of the source code;

运行模块,用于执行所述测试代码,获得所述测试代码的执行信息,所述执行信息包括执行所述测试代码时输出的异常的堆栈追踪信息;The execution module is used to execute the test code and obtain the execution information of the test code, including the stack trace information of the exceptions output when the test code is executed;

错误定位模块,用于根据所述执行信息对所述测试代码进行错误定位,获得错误代码的位置信息;The error location module is used to locate errors in the test code based on the execution information and obtain the location information of the error code.

模型修复模块,用于根据所述错误代码的位置信息,提取上下文信息,所述上下文信息包括错误的测试用例、错误描述或所述错误内容中的至少一种,将基于所述上下文信息构建的提示输入语言模型进行推理,获得第一修复代码,所述第一修复代码为所述语言模型对所述测试代码中的所述错误代码进行修复得到。The model repair module is used to extract context information based on the location information of the error code. The context information includes at least one of the error test case, error description, or error content. The module then uses a prompt input language model built based on the context information to perform reasoning to obtain a first repair code. The first repair code is obtained by the language model repairing the error code in the test code.

在一些可能的实现方式中,所述代码开发平台还包括反馈模块:In some possible implementations, the code development platform also includes a feedback module:

所述运行模块,还用于执行所述第一修复代码或者使用所述第一修复代码修复的所述测试代码;The running module is also used to execute the first repair code or the test code repaired using the first repair code;

所述反馈模块,用于当执行不通过,向所述用户呈现所述第一修复代码,接收所述用户对所述第一修复代码的反馈,获得更新后的所述第一修复代码。The feedback module is used to present the first repair code to the user when the execution fails, receive feedback from the user on the first repair code, and obtain the updated first repair code.

在一些可能的实现方式中,所述代码开发平台还包括:In some possible implementations, the code development platform also includes:

模板匹配修复模块,用于确定所述错误代码的错误类型,根据所述错误类型对应的修复模板对所述错误代码进行修复,获得第二修复代码;The template matching and repair module is used to determine the error type of the error code, and repair the error code according to the repair template corresponding to the error type to obtain a second repair code;

所述模型修复模块具体用于:The model repair module is specifically used for:

当所述第二修复代码修复失败,根据所述错误代码的位置信息,提取上下文信息。If the second repair code fails to repair, the context information is extracted based on the location information of the error code.

在一些可能的实现方式中,所述错误代码的错误类型包括断言失败;In some possible implementations, the error type of the error code includes assertion failure;

所述模板匹配修复模块具体用于:The template matching and repair module is specifically used for:

确定所述错误代码中错误断言的断言类型;Determine the assertion type of the error assertion in the error code;

当所述断言类型为相等类型,从所述错误代码中提取所述错误断言的预期值,从测试报告中提取所述错误断言的实际值;When the assertion type is an equality type, extract the expected value of the error assertion from the error code and extract the actual value of the error assertion from the test report;

在所述断言类型对应的断言修复模板中将所述错误断言的断言参数中的所述预期值替换为所述实际值,获得第二修复代码。In the assertion repair template corresponding to the assertion type, the expected value in the assertion parameter of the erroneous assertion is replaced with the actual value to obtain the second repair code.

在一些可能的实现方式中,所述模板匹配修复模块还用于:In some possible implementations, the template matching repair module is further used for:

当所述断言类型为布尔类型,根据所述错误断言中的断言参数以及所述错误断言使用的第一断言修复模板对应的第二断言修复模板,生成第二修复代码,所述第二断言修复模板的布尔逻辑与所述第一断言修复模板的布尔逻辑相反。When the assertion type is Boolean, a second repair code is generated based on the assertion parameters in the error assertion and the second assertion repair template corresponding to the first assertion repair template used by the error assertion. The Boolean logic of the second assertion repair template is the opposite of the Boolean logic of the first assertion repair template.

在一些可能的实现方式中,所述错误代码的错误类型包括异常,所述第二修复代码包括所述异常对应的异常处理代码块;In some possible implementations, the error type of the error code includes an exception, and the second repair code includes an exception handling code block corresponding to the exception;

所述模板匹配修复模块具体用于:The template matching and repair module is specifically used for:

从所述异常的堆栈追踪信息中确定异常类型;Determine the exception type from the stack trace information of the exception;

将所述异常类型填充到异常修复模板,获得所述异常处理代码块。Fill the exception type into the exception repair template to obtain the exception handling code block.

在一些可能的实现方式中,所述代码开发平台还包括:In some possible implementations, the code development platform also includes:

编译模块,用于编译所述测试代码,获得所述测试代码的编译信息,所述编译信息包括编译器对所述测试代码进行编译输出的错误日志,所述错误日志记录有所述错误代码的错误类型;A compilation module is used to compile the test code and obtain compilation information of the test code. The compilation information includes error logs output by the compiler when compiling the test code, and the error logs record the error types of the error codes.

当所述错误代码的错误类型包括缺失类引用,所述第二修复代码包括导入语句;When the error code includes a missing class reference, the second repair code includes an import statement;

所述模板匹配修复模块具体用于:The template matching and repair module is specifically used for:

确定缺失的类名;Determine the missing class name;

基于项目依赖库、开发工具库或者三方库,构建符号索引,所述符号索引包括可访问类的完全限定名;Based on project dependency libraries, development tool libraries, or third-party libraries, construct a symbol index, which includes the fully qualified names of accessible classes;

将所述缺失的类名和所述符号索引进行匹配,获得所述缺失的类名对应的完全限定名;The missing class name is matched with the symbol index to obtain the fully qualified name corresponding to the missing class name;

将所述完全限定名插入导包修复模板,获得所述导入语句。Insert the fully qualified name into the import package repair template to obtain the import statement.

在一些可能的实现方式中,所述模型修复模块还用于:In some possible implementations, the model repair module is also used for:

当所述第一修复代码修复失败,针对所述测试代码重新执行代码修复,直至所述测试代码被修复成功或者重试次数达到目标值。If the first repair code fails to repair, the code repair is re-executed for the test code until the test code is successfully repaired or the number of retries reaches the target value.

第三方面,本申请提供一种计算设备集群。该计算设备集群包括至少一台计算设备,至少一台计算设备包括至少一个处理器和至少一个存储器。至少一个处理器、至少一个存储器进行相互的通信。至少一个处理器用于执行至少一个存储器中存储的指令,以使得计算设备或计算设备集群执行如第一方面或第一方面的任一种实现方式所述的测试代码修复方法。Thirdly, this application provides a computing device cluster. The computing device cluster includes at least one computing device, and the at least one computing device includes at least one processor and at least one memory. The at least one processor and the at least one memory communicate with each other. The at least one processor is used to execute instructions stored in the at least one memory to cause the computing device or the computing device cluster to perform the test code repair method as described in the first aspect or any implementation thereof.

第四方面,本申请提供一种计算机可读存储介质,计算机可读存储介质中存储有指令,该指令指示计算设备或计算设备集群执行上述第一方面或第一方面的任一种实现方式所述的测试代码修复方法。Fourthly, this application provides a computer-readable storage medium storing instructions that instruct a computing device or a cluster of computing devices to execute the test code repair method described in the first aspect or any implementation thereof.

第五方面,本申请提供了一种包含指令的计算机程序产品,当其在计算设备或计算设备集群上运行时,使得计算设备或计算设备集群执行上述第一方面或第一方面的任一种实现方式所述的测试代码修复方法。Fifthly, this application provides a computer program product containing instructions that, when run on a computing device or a cluster of computing devices, causes the computing device or cluster of computing devices to execute the test code repair method described in the first aspect or any implementation thereof.

本申请在上述各方面提供的实现方式的基础上,还可以进行进一步组合以提供更多实现方式。Based on the implementation methods provided in the above aspects, this application can be further combined to provide more implementation methods.

附图说明Attached Figure Description

为了更清楚地说明本申请的技术方法,下面将对所需使用的附图进行简单介绍。To more clearly illustrate the technical methods of this application, the accompanying drawings used will be briefly described below.

图1为本申请提供的一种代码开发平台的架构示意图;Figure 1 is a schematic diagram of the architecture of a code development platform provided in this application;

图2为本申请提供的一种测试代码修复方法的流程图;Figure 2 is a flowchart of a test code repair method provided in this application;

图3为本申请提供的一种代码编辑界面的示意图;Figure 3 is a schematic diagram of a code editing interface provided in this application;

图4为本申请提供的一种代码编辑界面的示意图;Figure 4 is a schematic diagram of a code editing interface provided in this application;

图5为本申请提供的一种提示模板的示意图;Figure 5 is a schematic diagram of a prompt template provided in this application;

图6为本申请提供的一种基于断言修复模板进行测试代码修复的示意图;Figure 6 is a schematic diagram of test code repair based on assertion repair template provided in this application;

图7为本申请提供的一种基于断言修复模板进行测试代码修复的示意图;Figure 7 is a schematic diagram of test code repair based on assertion repair template provided in this application;

图8为本申请提供的一种基于异常修复模板进行测试代码修复的示意图;Figure 8 is a schematic diagram of test code repair based on an exception repair template provided in this application;

图9为本申请提供的一种基于异常修复模板进行测试代码修复的示意图;Figure 9 is a schematic diagram of test code repair based on an exception repair template provided in this application;

图10为本申请提供的一种计算设备的结构示意图;Figure 10 is a schematic diagram of the structure of a computing device provided in this application;

图11为本申请提供的一种计算设备集群的结构示意图;Figure 11 is a schematic diagram of the structure of a computing device cluster provided in this application;

图12为本申请提供的另一种计算设备集群的结构示意图;Figure 12 is a schematic diagram of another computing device cluster provided in this application;

图13为本申请提供的又一种计算设备集群的结构示意图。Figure 13 is a schematic diagram of another computing device cluster provided in this application.

具体实施方式Detailed Implementation

本申请实施例中的术语“第一”、“第二”仅用于描述目的,而不能理解为指示或暗示相对重要性或者隐含指明所指示的技术特征的数量。由此,限定有“第一”、“第二”的特征可以明示或者隐含地包括一个或者更多个该特征。The terms "first" and "second" used in the embodiments of this application are for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of indicated technical features. Therefore, a feature defined with "first" and "second" may explicitly or implicitly include one or more of that feature.

首先对本申请实施例中所涉及到的一些技术术语进行介绍。First, some technical terms involved in the embodiments of this application will be introduced.

软件测试,是一种通过测试代码来检测软件(或称作软件系统)是否满足用户需求的技术。软件测试可以分为多个阶段,例如为单元测试(unit test)、集成测试(integration test)、系统测试(system test)、验收测试。其中,单元测试是指对软件中的最小可测试单元进行测试,最小可测试单元可以是一个函数、一个方法或一个类。单元测试通常在开发过程中进行,旨在验证模块的功能是否正确。集成测试是验证多个模块之间的交互是否按照预期工作的过程。集成测试旨在发现模块之间的依赖和通信问题。系统测试是在整个软件系统上执行的测试,旨在验证整个软件系统是否按照用户需求和预期工作。验收测试,也称作交付测试,通常是部署软件之前的最后一个测试操作,验收测试的目的是确保软件准备就绪,并且可以让最终用户将其用于执行软件的既定功能和任务。Software testing is a technique that uses test code to check whether software (or a software system) meets user requirements. Software testing can be divided into several phases, such as unit testing, integration testing, system testing, and acceptance testing. Unit testing refers to testing the smallest testable unit in the software, which can be a function, a method, or a class. Unit testing is usually performed during the development process and aims to verify whether the module's functionality is correct. Integration testing is the process of verifying whether the interaction between multiple modules works as expected. Integration testing aims to discover dependencies and communication problems between modules. System testing is performed on the entire software system and aims to verify whether the entire software system works as required and expected by the user. Acceptance testing, also known as delivery testing, is usually the last testing operation before deploying the software. The purpose of acceptance testing is to ensure that the software is ready and can be used by end users to perform the software's intended functions and tasks.

测试代码包括用于实现测试功能的测试类和测试方法。为了提高代码开发效率,可以基于测试框架开发测试代码。以Java语言为例,Java可以支持使用多个测试框架开发单元测试的测试代码,其中,主流的测试框架可以包括Junit。为此,在进行测试代码开发时,可以导入Junit包,然后创建测试类,并在测试类中编写测试方法。测试方法可以使用assertEquals()、assertTrue()或者assertFalse()等方法来检测所测试的软件是否符合预期。其中,测试类、测试方法可以通过相应的标记进行注解。Test code includes test classes and test methods to implement testing functionality. To improve code development efficiency, test code can be developed based on a testing framework. Taking Java as an example, Java supports the development of unit test code using multiple testing frameworks, with JUnit being a mainstream example. Therefore, when developing test code, you can import the JUnit package, create test classes, and write test methods within those classes. Test methods can use methods such as `assertEquals()`, `assertTrue()`, or `assertFalse()` to check whether the tested software meets expectations. Test classes and test methods can be annotated with appropriate tags.

针对单元测试、集成测试或系统测试等,测试代码可以包括测试用例(test case)的用例代码。其中,测试用例是对一项特定的软件进行测试任务的描述,通常包括测试目标、测试环境、测试输入、测试步骤、预期结果。测试用例用于核实被测软件是否满足某个特定软件需求。例如,在测试环境中执行用例代码,获得与测试输入对应的实际输出结果,基于实际输出结果和预期结果,核实被测软件是否满足测试目标(例如是某个特定软件需求)。For unit testing, integration testing, or system testing, test code can include test case code. A test case describes a specific software testing task and typically includes the test objective, test environment, test inputs, test steps, and expected results. Test cases are used to verify whether the software under test meets a specific software requirement. For example, executing the test case code in the test environment obtains the actual output corresponding to the test inputs. Based on the actual output and expected results, the test case verifies whether the software under test meets the test objective (e.g., a specific software requirement).

随着软件规模的增大和复杂度的提升,手动编写和维护测试代码愈发困难。开发者需要投入大量时间和精力,用于检查测试代码中的错误,并修复错误。如此,降低了开发效率,也增加了软件的整体成本。为此,业界提出了一些自动化的测试修复方案,以减少开发者开发和维护测试代码的工作量,提高软件测试的效率和准确性。As software grows in size and complexity, manually writing and maintaining test code becomes increasingly difficult. Developers need to invest significant time and effort in checking and fixing errors in the test code. This reduces development efficiency and increases the overall cost of the software. To address this, the industry has proposed several automated test fixing solutions to reduce the workload of developers in creating and maintaining test code, thereby improving the efficiency and accuracy of software testing.

自动化的测试修复方案通常依赖人工干预或启发式方法。以针对空指针异常(Null Pointer Exception,NPE)的单元测试自动修复方法示例说明。该示例中,测试校验模块启动测试用例后,校验测试是否通过。测试用例执行过程中没有检测到执行异常,则表示测试通过,流程结束,若测试不通过,流程跳转到异常捕获模块。异常捕获模块对测试中检测到的异常进行类型捕获,判断异常是否是NPE,若是NPE,则流程跳转至NPE处理模块,若否,则输出异常信息以供开发者手动修复异常。NPE处理模块对捕获到的NPE异常进行自动处理,处理修复后再次执行测试校验,若无异常,则通过测试;若有异常,则重复上述步骤,直至解决异常或抛出异常。Automated test remediation solutions typically rely on manual intervention or heuristic methods. An example of an automated unit test remediation method for Null Pointer Exception (NPE) is provided. In this example, after the test verification module starts the test case, it verifies whether the test passes. If no execution exception is detected during the test case execution, the test passes and the process ends. If the test fails, the process jumps to the exception handling module. The exception handling module captures the type of the exception detected during the test, determines whether the exception is an NPE, and if it is, the process jumps to the NPE handling module; otherwise, it outputs the exception information for developers to manually fix. The NPE handling module automatically handles the captured NPE exception, and after processing and fixing it, it executes the test verification again. If no exception is found, the test passes; if an exception is found, the above steps are repeated until the exception is resolved or thrown.

上述方法通常只能对有限的错误类型进行检测和修复。例如,针对NPE的单元测试自动修复方法专注于解决单元测试中的NPE问题。然而,软件测试可能出现多种类型的错误,如断言失败、类型不匹配、数组越界。基于人工干预或启发式方法的测试修复方案缺乏通用性和灵活性,应用范围受到限制,而且,由于上述方案主要检测特定的错误类型并进行针对性修复,因而修复效率较低,且修复准确度不高。The methods described above typically only detect and fix a limited number of error types. For example, automated unit test remediation methods for Non-Proof-of-Specification (NPE) errors focus on resolving NPE issues in unit tests. However, software testing can encounter various types of errors, such as assertion failures, type mismatches, and array out-of-bounds errors. Test remediation schemes based on manual intervention or heuristic methods lack versatility and flexibility, limiting their application scope. Furthermore, because these schemes primarily detect specific error types and perform targeted remediation, their remediation efficiency is low, and their accuracy is not high.

有鉴于此,本申请提供一种测试代码修复方法。该方法可以由代码开发平台执行。代码开发平台通常用于开发并维护测试代码。代码开发平台可以是独立的软件系统,例如为集成开发环境(integrated development environment,IDE)或者是代码编辑器。代码开发平台可以以软件包的形式提供给用户,由用户自行部署,例如是部署在本地计算设备,以实现对测试代码的全面修复。其中,本地计算设备是用户直接控制的计算设备,包括但不限于个人计算机(personal computer,PC)、笔记本、个人工作站等。代码开发平台也可以集成于其他软件或平台,例如以插件、组件的形式集成于测试平台。如此可以实现通过嵌入式方案为用户提供无缝的修复体验。代码开发平台也可以部署在云环境,以云服务的形式提供给用户订阅使用。其中,云环境可以是多个计算设备形成的云计算集群,包括但不限于中心云(中心计算设备形成的云计算集群)、边缘云(边缘计算设备形成的云计算集群)。云服务订阅模式允许用户通过互联网访问相应的云服务,以执行本申请的测试代码修复方法,无需本地安装软件包,具有较高灵活性和可扩展性。在一些可能的实现方式中,代码开发平台也可以是具有测试代码开发能力的硬件系统,例如是具有测试代码开发能力的计算设备集群。计算设备集群运行时,执行本申请的测试代码修复方法。In view of this, this application provides a method for repairing test code. This method can be executed by a code development platform. A code development platform is typically used to develop and maintain test code. The code development platform can be a standalone software system, such as an integrated development environment (IDE) or a code editor. The code development platform can be provided to users as a software package, which users can deploy themselves, for example, on a local computing device, to achieve comprehensive repair of the test code. The local computing device is a computing device directly controlled by the user, including but not limited to personal computers (PCs), laptops, and personal workstations. The code development platform can also be integrated into other software or platforms, for example, as a plugin or component. This allows for a seamless repair experience for users through an embedded solution. The code development platform can also be deployed in a cloud environment and provided to users as a cloud service for subscription. The cloud environment can be a cloud computing cluster formed by multiple computing devices, including but not limited to a central cloud (a cloud computing cluster formed by central computing devices) and an edge cloud (a cloud computing cluster formed by edge computing devices). The cloud service subscription model allows users to access corresponding cloud services via the internet to execute the test code repair method of this application, without the need for local software package installation, offering high flexibility and scalability. In some possible implementations, the code development platform can also be a hardware system with test code development capabilities, such as a cluster of computing devices capable of test code development. When the computing device cluster is running, it executes the test code repair method of this application.

具体地,代码开发平台获取源代码对应的测试代码,该测试代码用于对源代码的功能和/或性能进行测试,然后执行测试代码,获得测试代码的执行信息,其中,执行信息包括执行测试代码时输出的异常的堆栈追踪信息。堆栈追踪信息,也称作堆栈回溯信息,是对程序(例如为测试代码)运行过程中的某个时间点上活跃栈帧信息的描述。其中,栈帧信息可以包括异常类型、发生位置(如类名、方法名、行号等)以及导致异常的方法调用链。然后,代码开发平台可以根据执行信息对测试代码进行错误定位,获得错误代码的位置信息。接着代码开发平台根据错误代码的位置信息,提取上下文信息,该上下文信息包括错误的测试用例、错误描述或错误内容中的至少一种。代码开发平台将基于上下文信息构建的提示(prompt)输入语言模型(language model,LM)进行推理,获得第一修复代码。该第一修复代码可以为语言模型对测试代码中的错误代码进行修复得到。Specifically, the code development platform obtains the test code corresponding to the source code. This test code is used to test the functionality and/or performance of the source code. The platform then executes the test code to obtain execution information, including stack trace information of any exceptions output during the execution of the test code. Stack trace information, also known as stack backtracking information, describes the active stack frames at a specific point in time during the program's (e.g., the test code's) execution. Stack frame information can include the exception type, the location of the exception (e.g., class name, method name, line number), and the method call chain that caused the exception. The code development platform can then locate the error in the test code based on the execution information, obtaining the location information of the erroneous code. Next, based on the location information of the erroneous code, the code development platform extracts context information, which includes at least one of the following: the erroneous test case, the error description, or the error content. The code development platform inputs a prompt constructed based on the context information into a language model (LM) for inference, obtaining a first corrective code. This first corrective code can be obtained by the language model correcting the erroneous code in the test code.

该方法通过先结合测试代码的执行信息进行错误定位,然后根据错误代码的位置信息提取丰富的上下文信息,基于该上下文信息,通过先进的语言模型生成更加精确和复杂的修复代码,以适应各种复杂的错误场景,不局限于特定的错误类型,如此可以减少人工干预,提高测试代码修复的自动化水平,进而提高修复效率和准确性,加快软件开发和测试的迭代速度,提升软件的整体质量。而且,还方法可以针对不同错误类型进行修复,具有很强的通用性和适应性。This method first locates errors by combining execution information from the test code, then extracts rich contextual information based on the error code's location. Using this contextual information, it generates more precise and complex repair code through an advanced language model to adapt to various complex error scenarios, not limited to specific error types. This reduces manual intervention, improves the automation level of test code repair, thereby increasing repair efficiency and accuracy, accelerating software development and testing iterations, and enhancing overall software quality. Furthermore, this method can repair different error types, demonstrating strong versatility and adaptability.

为了使得本申请的技术方案更加清楚、易于理解,下面先结合附图对本申请的代码开发平台的系统架构进行介绍。To make the technical solution of this application clearer and easier to understand, the system architecture of the code development platform of this application will be introduced below with reference to the accompanying drawings.

参见图1所示的一种代码开发平台的架构示意图,代码开发平台10包括交互装置100和测试代码修复装置200。其中,交互装置100可以以插件形式部署于客户端,客户端可以是IDE或代码编辑器,基于此,交互装置100也可以称作插件端,测试代码修复装置200可以部署于服务器,因此,测试代码修复装置200也可以称作服务端。Referring to Figure 1, which shows a schematic diagram of the architecture of a code development platform, the code development platform 10 includes an interactive device 100 and a test code repair device 200. The interactive device 100 can be deployed as a plugin on a client, which can be an IDE or a code editor; therefore, the interactive device 100 can also be called a plugin. The test code repair device 200 can be deployed on a server; therefore, the test code repair device 200 can also be called a server.

其中,测试代码修复装置200可以包括错误定位模块(图1中未示出)和模型修复模块201,进一步地,测试代码修复装置200还可以包括模板匹配修复模块203。交互装置100用于协调测试代码修复装置200中功能模块(如模型修复模块201、模板匹配修复模块203)的工作流,并与其他硬件设备进行数据交互,实时收集用户信息。交互装置100还可以对测试代码进行运行操作,获得测试代码的执行信息(或称作运行信息),并与服务器(包括中心服务器、边缘服务器)进行数据同步、交互,如此服务器端的测试代码修复装置200可以基于执行信息进行测试代码修复。其中,交互装置100可以包括测试代码选取模块102、运行模块104。在一些可能的实现方式中,测试代码运行之前可以先进行编译,交互装置100还可以包括编译模块103。服务器端的测试代码修复装置200可以基于编译信息进行测试代码修复。进一步地,交互装置100还可以包括修复策略选取模块106。交互装置100可以根据修复策略协同测试代码修复装置200中修复模块的工作流。此外,交互装置100还可以包括反馈模块108。反馈模块108支持在自动化修复测试代码基础上,引入人工修复测试代码的机制。The test code repair device 200 may include an error location module (not shown in Figure 1) and a model repair module 201. Further, the test code repair device 200 may also include a template matching repair module 203. The interaction device 100 coordinates the workflow of the functional modules (such as the model repair module 201 and the template matching repair module 203) in the test code repair device 200, interacts with other hardware devices, and collects user information in real time. The interaction device 100 can also run the test code to obtain its execution information (or running information) and synchronize and interact with the server (including the central server and edge servers), so that the server-side test code repair device 200 can repair the test code based on the execution information. The interaction device 100 may include a test code selection module 102 and a running module 104. In some possible implementations, the test code may be compiled before running, and the interaction device 100 may also include a compilation module 103. The server-side test code repair device 200 can then repair the test code based on the compiled information. Furthermore, the interactive device 100 may also include a repair strategy selection module 106. The interactive device 100 can coordinate the workflow of the repair module in the test code repair device 200 according to the repair strategy. In addition, the interactive device 100 may also include a feedback module 108. The feedback module 108 supports the introduction of a mechanism for manually repairing test code on top of automated test code repair.

下面对各个模块的功能以及模块之间的协作流程进行介绍。The functions of each module and the collaboration process between modules are described below.

测试代码选取模块102用于获取源代码对应的测试代码。其中,源代码可以是被测软件的函数、方法或类的源代码,或者是被测软件的项目级代码。具体实现时,测试代码选取模块102可以响应于用户的选取操作,选取待检测并修复的测试代码。针对软件测试的不同阶段,测试代码可以不同。以单元测试为例,测试代码可以是单元测试的测试用例中的用例代码。该测试代码可以是手动开发,也可以是自动生成。例如,用户可以输入被测软件的源代码,通过对该源代码进行预处理,例如是从源代码中提取关键信息,以构建提示词,接着将提示词输入语言模型,尤其是大语言模型(large language model,LLM),通过LLM的文本理解与生成能力,生成测试用例。The test code selection module 102 is used to obtain the test code corresponding to the source code. The source code can be the source code of functions, methods, or classes of the software under test, or it can be the project-level code of the software under test. Specifically, the test code selection module 102 can respond to the user's selection operation and select the test code to be tested and fixed. The test code can differ depending on the stage of software testing. Taking unit testing as an example, the test code can be the test case code in the unit test. This test code can be manually developed or automatically generated. For example, the user can input the source code of the software under test, preprocess the source code (e.g., extract key information from the source code to construct prompts), and then input the prompts into a language model, especially a large language model (LLM). Through the text understanding and generation capabilities of the LLM, test cases are generated.

编译模块103用于对测试代码执行编译操作,获得编译信息。其中,编译信息包括编译器对所述测试代码进行编译输出的错误日志。错误日志记录有错误代码的错误类型。例如,错误类型可以包括缺失类引用,该错误类型属于编译错误。错误日志还记录有错误代码的位置信息,由此可以实现错误定位。The compilation module 103 is used to perform compilation operations on the test code and obtain compilation information. This compilation information includes error logs output by the compiler during the compilation of the test code. The error logs record the error types of the error codes. For example, error types may include missing class references, which is a compilation error. The error logs also record the location information of the error codes, thereby enabling error localization.

运行模块104用于对测试代码执行运行操作。具体实现时,运行模块104可以调用执行器以执行测试代码。其中,运行模块104可以是在测试代码编译通过时,运行测试代码。本实施例通过将测试代码的编译和执行解耦,可以实现更准确的问题定位,进而针对不同类型的问题进行分类处理。在一些可能的实现方式中,编译模块103、运行模块104也可以耦合在一起,耦合后的模块称为编译与运行模块,用于实现编译、执行等功能。The execution module 104 is used to perform execution operations on the test code. Specifically, the execution module 104 can call the executor to execute the test code. The execution module 104 can run the test code when it has been successfully compiled. This embodiment decouples the compilation and execution of the test code, enabling more accurate problem localization and allowing for categorized handling of different types of problems. In some possible implementations, the compilation module 103 and the execution module 104 can also be coupled together; the coupled module is called the compilation and execution module, used to implement compilation, execution, and other functions.

修复策略选取模块106用于选取修复策略,并提供该修复策略至测试代码修复装置200。其中,修复策略可以包括但不限于直接使用语言模型修复,直接使用模板匹配修复,或者是模板匹配修复优先、模型修复优先。模板匹配修复优先是指优先使用修复模板进行修复,当修复不成功,再使用语言模型进行修复。模型修复优先是指优先使用语言模型进行修复。修复策略选取模块106提供的修复策略不同,测试代码修复装置200中功能模块的工作流可以不同。The repair strategy selection module 106 is used to select a repair strategy and provide it to the test code repair device 200. The repair strategy may include, but is not limited to, directly using the language model for repair, directly using template matching for repair, or prioritizing template matching repair followed by model repair. Prioritizing template matching repair means using the repair template first; if that fails, the language model is then used. Prioritizing model repair means using the language model first. Different repair strategies provided by the repair strategy selection module 106 can lead to different workflows for the functional modules in the test code repair device 200.

错误定位模块用于获取测试代码的执行信息,其中,执行信息包括执行测试代码时输出的异常的堆栈追踪信息,然后根据执行信息对测试代码进行错误定位,获得错误代码的位置信息。其中,错误代码的位置信息用于输入模型修复模块201或模板匹配修复模块203进行测试代码修复。The error localization module is used to obtain execution information of the test code, including stack trace information of exceptions output during test code execution. Based on this execution information, the module locates errors in the test code to obtain the position information of the erroneous code. This error code position information is then input into the model repair module 201 or the template matching repair module 203 for test code repair.

模型修复模块201用于根据错误代码的位置信息,提取上下文信息,该上下文信息包括错误的测试用例、错误描述或错误内容的至少一种,将基于上下文信息构建的提示输入语言模型进行推理,获得第一修复代码。该第一修复代码可以为语言模型对测试代码中的错误代码进行修复得到。The model repair module 201 is used to extract context information based on the location information of the error code. This context information includes at least one of the following: the erroneous test case, the error description, or the error content. The prompt constructed based on the context information is then input into a language model for inference to obtain a first repair code. This first repair code can be obtained by the language model repairing the error code in the test code.

模板匹配修复模块203用于确定错误代码的错误类型,根据错误类型对应的修复模板对错误代码进行修复,获得第二修复代码。其中,第一修复代码、第二修复代码可以是对错误代码进行修复的增量代码,或者是全量代码(修复后的完整的测试代码)。The template matching and repair module 203 is used to determine the error type of the error code, and repair the error code according to the repair template corresponding to the error type to obtain the second repair code. The first and second repair codes can be incremental code for repairing the error code, or full code (the complete test code after repair).

需要说明的是,当修复策略为模板匹配修复优先时,模板匹配修复模块203还可以返回第二修复代码至交互装置100,交互装置100通过对模板匹配修复模块203修复后的测试代码(例如是第二修复代码,或者是测试代码和第二修复代码)执行运行操作,从而确定第二修复代码是否修复成功。当执行通过,则表示修复成功,当执行不通过,则表示修复失败。It should be noted that when the repair strategy prioritizes template matching repair, the template matching repair module 203 can also return the second repair code to the interactive device 100. The interactive device 100 determines whether the second repair code was successfully repaired by executing a test operation on the test code (e.g., the second repair code, or both the test code and the second repair code) repaired by the template matching repair module 203. If the execution passes, the repair is successful; if the execution fails, the repair fails.

相应地,模型修复模块201具体用于当第二修复代码修复失败,根据错误代码的位置信息,提取上下文信息,将基于上下文信息构建的提示输入语言模型进行推理,获得第一修复代码。Accordingly, the model repair module 201 is specifically used to extract context information based on the location information of the error code when the second repair code fails, and to perform reasoning on the prompt input language model constructed based on the context information to obtain the first repair code.

在一些可能的实现方式中,模型修复模块201还用于向交互装置100返回第一修复代码。交互装置100中的运行模块104还用于执行第一修复代码或者使用第一修复代码修复的测试代码。交互装置100中的反馈模块108用于当执行不通过,向用户呈现第一修复代码,接收用户对第一修复代码的反馈,获得更新后的第一修复代码。In some possible implementations, the model repair module 201 is also used to return the first repair code to the interactive device 100. The execution module 104 in the interactive device 100 is also used to execute the first repair code or test code repaired using the first repair code. The feedback module 108 in the interactive device 100 is used to present the first repair code to the user when execution fails, receive feedback from the user on the first repair code, and obtain the updated first repair code.

基于图1所示的代码开发平台10,本申请提供一种测试代码修复方法。下面结合附图,对本申请的测试代码修复方法进行介绍。Based on the code development platform 10 shown in Figure 1, this application provides a test code repair method. The test code repair method of this application will be described below with reference to the accompanying drawings.

参见图2所示的一种测试代码修复方法的流程图,该方法由代码开发平台10执行,代码开发平台10包括交互装置100(如插件端)和测试代码修复装置200(如服务端),该方法包括如下步骤:Referring to Figure 2, a flowchart of a test code repair method is shown. This method is executed by a code development platform 10, which includes an interactive device 100 (such as a plugin) and a test code repair device 200 (such as a server). The method includes the following steps:

S201、交互装置100获取源代码对应的测试代码。S201, Interactive device 100 obtains the test code corresponding to the source code.

其中,源代码可以是被测软件的代码(如项目级代码),或者是被测软件的一个或多个模块(或者最小可测试单元)的代码。测试代码可以是对软件或者软件的一个或多个模块进行测试的代码。测试代码用于对源代码的功能和/或性能进行测试。其中,功能测试专注于验证被测软件的行为是否符合设计和用户需求,主要检查被测软件的每个功能按照要求正确工作。性能测试则评估被测软件在特定条件下的响应速度、稳定性、可靠性、资源消耗和扩展性,涉及被测软件在高负载或压力条件下运行的效率。根据测试阶段不同,测试代码可以是单元测试的测试代码,或者是集成测试的测试代码,又或者是系统测试的测试代码。The source code can be the code of the software under test (such as project-level code), or the code of one or more modules (or the smallest testable unit) of the software under test. Test code can be code used to test the software or one or more modules of the software. Test code is used to test the functionality and/or performance of the source code. Functional testing focuses on verifying whether the behavior of the software under test meets design and user requirements, mainly checking that each function of the software under test works correctly as required. Performance testing evaluates the response speed, stability, reliability, resource consumption, and scalability of the software under test under specific conditions, involving the efficiency of the software under test running under high load or stress conditions. Depending on the testing phase, test code can be unit test code, integration test code, or system test code.

针对一个软件项目,交互装置100可以支持用户选择测试代码。该测试代码可以是用户手动编写的测试代码,或者是自动生成的测试代码。为了便于描述,以自动生成的测试代码示例说明。具体地,参见图3所示的一种代码编辑界面的示意图,代码编辑界面300包括代码编辑窗口302和工具栏304,其中,代码编辑窗口302可以包括被测软件的代码3022,工具栏304可以包括测试代码生成控件3042和测试代码修复控件。交互装置100可以通过代码编辑界面300的代码编辑窗口302向用户呈现被测软件的代码,用户可以从代码编辑窗口302呈现的代码中选择待生成测试代码的代码块,例如是一个函数代码块,或者是一个方法类代码块,然后点击测试代码生成控件3042,触发测试代码生成操作。交互装置100响应于测试代码生成操作,基于待生成测试代码的代码块,生成测试代码。其中,交互装置100可以根据代码块构造提示,将提示输入训练好的、用于生成测试代码的LLM,获得测试代码。For a software project, the interactive device 100 can support user selection of test code. This test code can be manually written by the user or automatically generated. For ease of description, an example of automatically generated test code is used. Specifically, referring to a schematic diagram of a code editing interface shown in Figure 3, the code editing interface 300 includes a code editing window 302 and a toolbar 304. The code editing window 302 can include the code 3022 of the software under test, and the toolbar 304 can include a test code generation control 3042 and a test code repair control. The interactive device 100 can present the code of the software under test to the user through the code editing window 302 of the code editing interface 300. The user can select a code block to be used to generate test code from the code presented in the code editing window 302, such as a function code block or a method class code block, and then click the test code generation control 3042 to trigger the test code generation operation. In response to the test code generation operation, the interactive device 100 generates test code based on the code block to be used. The interactive device 100 can construct prompts based on code blocks, input the prompts into a trained LLM used to generate test code, and obtain the test code.

为了便于理解,图3以被测软件为购物系统示例说明,购物系统包括一个商品类,类名为Product,商品类具有如下属性:商品的名称、价格、库存。当生成测试代码后,交互装置100可以通过代码编辑窗口302展示被测软件的代码3022中用户选择的代码块的测试代码3024。仍以购物系统示例说明,测试代码可以是基于测试框架(如Junit测试框架)生成。测试代码中包括一个Product对象,针对Product对象设置有名称、价格、库存等属性,测试代码中使用断言语句(如assert语句)判断实际结果与预期结果是否一致。For ease of understanding, Figure 3 uses a shopping system as an example of the software under test. The shopping system includes a product class named Product, which has the following attributes: product name, price, and inventory. After the test code is generated, the interactive device 100 can display the test code 3024 of the user-selected code block in the code 3022 of the software under test through the code editing window 302. Again using the shopping system example, the test code can be generated based on a testing framework (such as the JUnit testing framework). The test code includes a Product object, which has attributes such as name, price, and inventory. Assert statements (such as assert statements) are used in the test code to determine whether the actual result matches the expected result.

在图4的示例,测试代码可以为:
In the example of Figure 4, the test code could be:

其中,testProductName()用于测试Product对象的getName()方法是否能够正确返回商品的名称,testProductPrice()用于测试Product对象的get Price()方法是否能够正确返回商品的价格,testProductStock()用于测试Product对象的getStock()方法是否能够正确返回商品的库存,testProductOutOfStock()用于测试Product对象的isOutOfStock()方法是否能正确判断商品的库存是否为0。Specifically, `testProductName()` tests whether the `getName()` method of the `Product` object can correctly return the name of the product; `testProductPrice()` tests whether the `getPrice()` method of the `Product` object can correctly return the price of the product; `testProductStock()` tests whether the `getStock()` method of the `Product` object can correctly return the inventory of the product; and `testProductOutOfStock()` tests whether the `isOutOfStock()` method of the `Product` object can correctly determine whether the inventory of the product is 0.

S202、交互装置100编译测试代码。S202, Compile test code for interactive device 100.

具体地,交互装置100可以调用编译器对测试代码进行编译。其中,编译器可以是本地的编译器,或者是远端的编译器(例如是云编译器)。在进行编译时,交互装置100可以根据测试代码的语言(如编程语言或程序语言),选择与该语言匹配的编译器进行编译。例如,测试代码为Java语言开发时,交互装置100可以选择Java编译器,然后调用Java编译器对测试代码进行编译。Specifically, the interactive device 100 can invoke a compiler to compile the test code. The compiler can be a local compiler or a remote compiler (e.g., a cloud compiler). During compilation, the interactive device 100 can select a compiler that matches the language of the test code (e.g., a programming language or program language). For example, if the test code is developed in Java, the interactive device 100 can select a Java compiler and then invoke the Java compiler to compile the test code.

S204、交互装置100确定是否产生编译错误。若是,则执行S209;若否,则执行S206。S204. Interactive device 100 determines whether a compilation error has occurred. If yes, proceed to S209; otherwise, proceed to S206.

交互装置100可以通过与编译器交互,从而确定是否产生编译错误。例如,编译器可以在编译错误时,输出错误日志。错误日志中可以包括错误类型和错误位置。交互装置100可以通过读取错误日志,确定是否产生编译错误。当错误日志为空,或未读取到错误日志,则表示编译通过,不存在编译错误。当错误日志非空,则表示编译不通过,存在编译错误。又例如,交互装置100可以监听编译器上报的事件,若监听到告警事件,则表示编译不通过,若未监听到告警事件,则表示编译通过。The interactive device 100 can determine whether a compilation error has occurred by interacting with the compiler. For example, the compiler can output an error log when a compilation error occurs. The error log can include the error type and error location. The interactive device 100 can determine whether a compilation error has occurred by reading the error log. If the error log is empty, or no error log is read, it means that compilation is successful and there is no compilation error. If the error log is not empty, it means that compilation fails and there is a compilation error. Alternatively, the interactive device 100 can listen for events reported by the compiler. If a warning event is detected, it means that compilation has failed; if no warning event is detected, it means that compilation is successful.

上述S202、S204为本申请的可选步骤,执行本申请的测试代码修复方法也可以不执行上述步骤。例如,测试代码采用非编译型语言开发时,交互装置100可以不执行S202、S204。The steps S202 and S204 described above are optional steps in this application. The test code repair method of this application may be implemented without executing the above steps. For example, when the test code is developed using a non-compiled language, the interactive device 100 may not execute S202 and S204.

S206、交互装置100执行测试代码。S206, Interactive device 100 executes test code.

具体地,交互装置100可以调用执行器,以执行测试代码。其中,测试代码为编译型语言开发的测试代码时,交互装置100可以调用执行器,执行编译后的测试代码(通常是可执行的机器码),从而获得执行结果。测试代码为非编译型语言开发的测试代码时,例如测试代码是机器码时,交互装置100可以直接调用执行器,执行测试代码。Specifically, the interactive device 100 can invoke an executor to execute test code. When the test code is developed in a compiled language, the interactive device 100 can invoke the executor to execute the compiled test code (usually executable machine code) and obtain the execution result. When the test code is developed in a non-compiled language, such as machine code, the interactive device 100 can directly invoke the executor to execute the test code.

执行器是执行测试代码的工具。通常可以是虚拟机,例如测试代码为Java代码时,执行器可以是Java虚拟机(Java virtual machine,JVM)。实际应用时,交互装置100可以采用本地的编译器,或者是远端的编译器(例如是云编译器),执行测试代码(如编译后的测试代码)。在执行测试代码时,交互装置100可以根据测试代码的语言(如编程语言或程序语言),选择与该语言匹配的执行器来执行测试代码。An executor is a tool for executing test code. It is typically a virtual machine; for example, if the test code is Java code, the executor could be a Java Virtual Machine (JVM). In practical applications, the interactive device 100 can use a local compiler or a remote compiler (such as a cloud compiler) to execute the test code (e.g., compiled test code). When executing the test code, the interactive device 100 can select an executor that matches the language of the test code (e.g., programming language or program language) to execute the test code.

S208、交互装置100确定是否产生执行错误。若是,则执行S210;若否,则执行S224。S208. Interactive device 100 determines whether an execution error has occurred. If yes, then execute S210; otherwise, then execute S224.

交互装置100可以通过与执行器交互,从而确定是否产生执行错误。例如,交互装置100可以监听执行器上报的事件,若监听到错误事件(如异常事件),则表示存在执行错误,若未监听到错误事件,则表示不存在执行错误,测试代码执行通过。The interactive device 100 can determine whether an execution error has occurred by interacting with the executor. For example, the interactive device 100 can listen for events reported by the executor. If an error event (such as an exception event) is detected, it indicates that an execution error exists. If no error event is detected, it indicates that no execution error exists and the test code executes successfully.

上述S206、S208为本申请实施例的可选步骤,执行本申请的测试代码修复方法也可以不执行上述步骤,例如,被测软件为生产环境中已上线的软件时,用户也可以从生产环境下载上述测试代码及其编译信息或执行信息,并输入测试代码修复装置200进行测试代码修复。S206 and S208 described above are optional steps in the embodiments of this application. The test code repair method of this application may also be performed without performing the above steps. For example, when the software under test is software that has been launched in the production environment, the user may also download the above test code and its compilation information or execution information from the production environment and input it into the test code repair device 200 to perform test code repair.

S209、测试代码修复装置200获取测试代码的编译信息,根据编译信息对测试代码进行错误定位,获得错误代码的位置信息。然后执行S212。S209, the test code repair device 200 obtains the compilation information of the test code, locates errors in the test code based on the compilation information, and obtains the location information of the error code. Then, S212 is executed.

S210、测试代码修复装置200获取测试代码的执行信息,根据执行信息对测试代码进行错误定位,获得错误代码的位置信息。然后执行S212。S210, the test code repair device 200 obtains the execution information of the test code, locates errors in the test code based on the execution information, and obtains the location information of the error code. Then, S212 is executed.

编译信息包括编译器对测试代码进行编译输出的错误日志。其中,错误日志记录有错误代码的错误类型,错误日志还可以记录错误代码的位置信息以及与错误相关的告警信息中的至少一项。错误代码的位置信息可以通过类名、方法名或行号中的至少一项表示。告警信息可以包括错误描述、错误修复建议。Compilation information includes error logs output by the compiler when compiling the test code. The error log records the error type of the error code, and may also record at least one of the following: the location of the error code, and related warning information. The location of the error code can be represented by at least one of the following: class name, method name, or line number. Warning information may include an error description and suggested fixes.

执行信息包括执行测试代码时输出的异常的堆栈追踪信息。其中,异常是区别于缺失类引用导致的编译错误、断言失败(或称作断言错误)等错误类型的另一种错误类型,堆栈追踪信息是对程序(例如为测试代码)运行过程中的某个时间点上活跃栈帧信息的描述。其中,栈帧信息可以包括异常类型、发生位置(如类名、方法名、行号等)以及导致异常的方法调用链。Execution information includes stack traces of exceptions output during the execution of test code. Exceptions are a different type of error from errors such as missing class references (compile-time errors) and assertion failures (or assertion errors). Stack traces describe the active stack frames at a specific point in time during the program's (e.g., test code) execution. Stack frame information can include the exception type, its location (e.g., class name, method name, line number), and the method call chain that caused the exception.

当编译发生错误时,测试代码修复装置200可以解析编译输出的错误日志,以对测试代码进行错误定位,获得错误代码的位置信息。当执行发生错误时,测试代码修复装置200可以解析堆栈追踪信息,通过堆栈追踪信息的栈帧信息中的发生位置,获得错误代码的位置信息。错误代码的位置信息可以通过类名、方法名或行号表征。When a compilation error occurs, the test code repair device 200 can parse the compilation output error log to locate the error in the test code and obtain the location information of the error code. When an execution error occurs, the test code repair device 200 can parse the stack trace information and obtain the location information of the error code through the location of the occurrence in the stack frame information of the stack trace information. The location information of the error code can be represented by class name, method name, or line number.

需要说明的是,S209为本申请的可选步骤,执行本申请的测试代码修复方法也可以不执行S209。例如,测试代码为可执行代码,包括但不限于机器码时,测试代码修复装置200可以不执行S209。此外,上述S201至S210为本申请实施例中获取源代码对应的测试代码,执行测试代码获得测试代码的执行信息,根据测试代码的执行信息进行错误定位,获得错误代码的位置信息的一种具体实现,实际应用时也可以通过其他方式进行错误定位,获得错误代码的位置信息。例如,代码开发平台10采用云服务订阅方式提供给用户时,用户可以通过云服务开放的接口传入的测试代码,云服务可以执行测试代码,获得测试代码的执行信息,并根据执行信息进行对测试代码错误定位,获得错误代码的位置信息。It should be noted that S209 is an optional step in this application, and the test code repair method of this application may not require S209. For example, when the test code is executable code, including but not limited to machine code, the test code repair device 200 may not need to execute S209. Furthermore, S201 to S210 described above are specific implementations in this application's embodiments of obtaining the test code corresponding to the source code, executing the test code to obtain the execution information of the test code, and performing error location based on the execution information to obtain the location information of the error code. In practical applications, error location can also be performed in other ways to obtain the location information of the error code. For example, when the code development platform 10 provides the code to users through a cloud service subscription, the user can pass in the test code through the interface exposed by the cloud service. The cloud service can execute the test code, obtain the execution information of the test code, and perform error location based on the execution information to obtain the location information of the error code.

S212、测试代码修复装置200确定错误代码的错误类型,根据错误类型对应的修复模板对错误代码进行修复,获得第二修复代码。S212, The test code repair device 200 determines the error type of the error code, repairs the error code according to the repair template corresponding to the error type, and obtains the second repair code.

具体地,测试代码修复装置200可以通过解析错误日志或堆栈追踪信息,获得错误类型。针对一些错误类型,测试代码修复装置200支持使用该错误类型对应的修复模板对错误代码进行修复。其中,测试代码修复装置200支持模板修复的错误类型可以形成一个错误类型集合,该错误类型集合包括至少一种错误类型。例如,错误类型集合可以包括缺失类引用、断言失败或者是异常。其中,异常可以包括运行时异常,也称作不可查异常(unchecked exception)。运行时异常通常是程序的设计漏洞、代码逻辑错误导致,常见的运行时异常包括空指针异常NPE、数组下标越界异常、类型转换异常、数据存储异常(操作数组时类型不一致)。Specifically, the test code repair device 200 can obtain the error type by parsing error logs or stack trace information. For some error types, the test code repair device 200 supports using the corresponding repair template to repair the erroneous code. The error types supported by the template repair device 200 can form an error type set, which includes at least one error type. For example, the error type set may include missing class references, assertion failures, or exceptions. Exceptions may include runtime exceptions, also known as unchecked exceptions. Runtime exceptions are usually caused by design flaws or code logic errors. Common runtime exceptions include null pointer exceptions (NPE), array index out of bounds exceptions, type conversion exceptions, and data storage exceptions (inconsistent types when operating on arrays).

基于此,测试代码修复装置200可以确定错误代码的错误类型是否在错误类型集合命中。具体地,测试代码修复装置200可以比较错误代码的错误类型和错误类型集合。若错误代码的错误类型与错误类型集合中的错误类型匹配成功,则表示错误类型在错误类型集合中命中,测试代码修复装置200可以根据错误类型对应的修复模板对错误代码进行修复,获得第二修复代码。若错误代码的错误类型与错误类型集合中的任意错误类型均未匹配成功,则表示错误类型在错误类型集合中未命中,测试代码修复装置200可以使用其他方式对错误代码进行修复,例如可以使用语言模型对错误代码进行修复。Based on this, the test code repair device 200 can determine whether the error type of the erroneous code matches the error type set. Specifically, the test code repair device 200 can compare the error type of the erroneous code with the error type set. If the error type of the erroneous code matches any error type in the error type set, it means that the error type matches the error type set, and the test code repair device 200 can repair the erroneous code according to the repair template corresponding to the error type to obtain a second repair code. If the error type of the erroneous code does not match any error type in the error type set, it means that the error type does not match the error type set, and the test code repair device 200 can use other methods to repair the erroneous code, such as using a language model to repair the erroneous code.

S214、测试代码修复装置200确定第二修复代码是否修复成功。若是,则执行S224;若否,则执行S216。S214. The test code repair device 200 determines whether the second repair code has been successfully repaired. If yes, then execute S224; if no, then execute S216.

其中,测试代码修复装置200可以将第二修复代码返回交互装置100,第二修复代码可以是对测试代码修复后的全量代码,或者是对测试代码进行修复的增量代码。当第二修复代码为全量代码,则修复后的测试代码可以为第二修复代码,当第二修复代码为增量代码,则修复后的测试代码可以为测试代码和第二修复代码。交互装置100可以通过执行修复后的测试代码,例如是第二修复代码或者是使用第二修复代码修复的测试代码,确定第二修复代码是否修复成功。在一些示例中,交互装置100可以对修复后的测试代码(如第二修复代码,或者是使用第二修复代码修复的测试代码)进行编译,若编译通过,则继续执行该修复后的测试代码。交互装置100可以根据执行结果,确定第二修复代码是否修复成功,并将修复结果返回测试代码修复装置200。若修复成功,则测试代码修复装置200可以停止修复,交互装置100可以保存第二修复代码。若修复不成功,可以继续进行测试代码修复。The test code repair device 200 can return second repair code to the interactive device 100. The second repair code can be either the full code after repairing the test code or incremental code that repairs the test code. When the second repair code is the full code, the repaired test code can be the second repair code; when the second repair code is incremental code, the repaired test code can be either the test code or the second repair code. The interactive device 100 can determine whether the second repair code was successfully repaired by executing the repaired test code, such as the second repair code or test code repaired using the second repair code. In some examples, the interactive device 100 can compile the repaired test code (such as the second repair code or test code repaired using the second repair code). If the compilation is successful, the repaired test code continues to be executed. The interactive device 100 can determine whether the second repair code was successfully repaired based on the execution result and return the repair result to the test code repair device 200. If the repair is successful, the test code repair device 200 can stop repairing, and the interactive device 100 can save the second repair code. If the repair is unsuccessful, the test code repair can continue.

在一些可能的实现方式中,代码开发平台10还可以配置最大重试次数,例如最大重试次数可以配置为目标值。基于此,测试代码修复装置200可以获取第二修复代码的编译信息或执行信息,当编译信息或执行信息指示第二修复代码修复失败,测试代码修复装置200可以针对测试代码重新执行代码修复,直至测试代码被修复成功或者重试次数达到目标值。In some possible implementations, the code development platform 10 can also be configured with a maximum number of retries, for example, the maximum number of retries can be configured as a target value. Based on this, the test code repair device 200 can obtain the compilation information or execution information of the second repair code. When the compilation information or execution information indicates that the second repair code has failed to repair, the test code repair device 200 can re-execute the code repair for the test code until the test code is successfully repaired or the number of retries reaches the target value.

S216、测试代码修复装置200根据错误代码的位置信息,提取上下文信息。S216. The test code repair device 200 extracts context information based on the location information of the error code.

上下文信息包括错误的测试用例、错误描述或错误内容中的至少一种。错误描述可以包括错误类型、错误代码的位置信息。具体地,测试代码修复装置200可以根据错误代码的位置信息,获取错误内容。其中,错误内容可以是编译信息或执行信息中与错误代码相关的内容,例如是编译信息或执行信息中包括上述位置信息的错误记录,该错误记录不仅记录错误代码的位置信息,还可以记录错误类型(如异常类型)、导致异常的方法调用链。测试代码修复装置200还可以根据测试代码的编译信息或执行信息生成错误描述。此外,测试代码修复装置200根据错误代码所在代码文件,获取错误的测试用例,测试用例可以包括测试目标、测试环境、测试输入、预期结果。The context information includes at least one of the following: erroneous test cases, error descriptions, or error content. The error description may include the error type and the location information of the error code. Specifically, the test code repair device 200 can obtain the error content based on the location information of the error code. The error content can be content related to the error code in the compilation or execution information, such as an error record in the compilation or execution information that includes the aforementioned location information. This error record not only records the location information of the error code but may also record the error type (such as exception type) and the method call chain that caused the exception. The test code repair device 200 can also generate an error description based on the compilation or execution information of the test code. Furthermore, the test code repair device 200 obtains the erroneous test cases based on the code file where the error code is located. The test cases may include the test objective, test environment, test input, and expected result.

其中,为了给语言模型如LLM提供足够的上下文信息,测试代码修复装置200可以构建一个上下文信息集,记作“C”。“C”包括错误的测试用例T{error}、错误描述D{e}和错误内容C_e,具体如下所示:To provide sufficient contextual information for language models such as LLM, the test code repair device 200 can construct a contextual information set, denoted as "C". "C" includes the erroneous test case T{error}, the error description D{e}, and the error content C_e, as shown below:

C={T{error},D{e},C_{e}}。C = {T{error}, D{e}, C_{e}}.

S218、测试代码修复装置200根据上下文信息构建提示。S218, Test code repair device 200 constructs a prompt based on context information.

测试代码修复装置200可以根据上下文信息和提示模板构建提示。其中,上下文信息可以包括不同类型,测试代码修复装置200可以将上下文信息的不同信息,填充至提示模板的相应字段,从而获得提示。The test code repair device 200 can construct prompts based on context information and a prompt template. The context information can include different types, and the test code repair device 200 can fill the corresponding fields of the prompt template with different pieces of context information to obtain the prompts.

在一些示例中,提示模板可以包括错误提示和错误信息。错误提示用于提示语言模型测试代码存在错误,需要进行修复。错误信息用于提供对错误代码进行修复可使用的信息,例如是上下文信息。错误信息可以包括多个字段,例如是测试用例、错误描述、错误内容。测试代码修复装置200以将上下文信息集中错误的测试用例T{error}填充至测试用例字段,将错误类型、错误代码的位置信息等错误描述填充至错误描述字段,将编译信息或执行信息中的错误内容填充至错误内容字段。如此可以为语言模型进行错误定位和分析提供线索。In some examples, the prompt template may include error messages and error information. Error messages indicate that errors exist in the language model test code and need to be fixed. Error information provides information that can be used to fix the erroneous code, such as context information. Error information may include multiple fields, such as test case, error description, and error content. The test code repair device 200 fills the test case field with the erroneous test case T{error} from the context information, fills the error description field with the error type, error code location information, etc., and fills the error content field with the error from the compilation or execution information. This provides clues for error localization and analysis in the language model.

在一些可能的实现方式中,提示模板还可以包括修复要求字段。修复要求字段用于填充对发生错误的测试代码的修复要求。例如,修复要求可以为要求语言模型(如LLM)修改测试代码,并以代码块的形式输出完整的测试代码。图5示出了一种提示模板的示意图,如图5所示,测试模板500可以错误提示502、错误信息504和修复要求506。其中,错误提示502用于提示测试代码产生错误,在一些示例中,错误提示502还可以提示错误类型。在图5的示例中,错误提示502可以为“There may be assertion errors./Your unit test has encountered an error”,其中,There may be assertion errors表示可能存在断言错误(断言失败),Your unit test has encountered an error表示单元测试的测试代码可能发生错误。其中,错误提示502中的错误类型“assertion”可以是根据上下文信息填充。错误信息504可以包括填充说明和待填充区域(如5中“{error_message}”所示),填充说明用于指示填充错误信息的位置,待填充区域可以填充上下文信息。修复要求506可以为“Modify your test code accordingly and output completed test code in a code cell”,表示要求语言模型修复测试代码,并以代码块的形式输出完整的测试代码。In some possible implementations, the prompt template may also include a fix requirement field. The fix requirement field is used to populate a fix requirement for the test code that caused the error. For example, the fix requirement could be to require the language model (such as LLM) to modify the test code and output the complete test code as a code block. Figure 5 shows a schematic diagram of a prompt template. As shown in Figure 5, test template 500 can include error prompt 502, error message 504, and fix requirement 506. Error prompt 502 is used to indicate that the test code has generated an error. In some examples, error prompt 502 can also indicate the error type. In the example in Figure 5, error prompt 502 could be “There may be assertion errors./Your unit test has encountered an error,” where “There may be assertion errors” indicates that there may be assertion errors (assertion failure), and “Your unit test has encountered an error” indicates that the unit test code may have an error. The error type “assertion” in error prompt 502 can be filled in based on context information. Error message 504 can include a padding description and a region to be filled (as shown in "{error_message}" in section 5). The padding description indicates the location to fill in the error message, and the region to be filled can be filled with context information. Repair request 506 can be "Modify your test code accordingly and output completed test code in a code cell," indicating a request for the language model to repair the test code and output the complete test code as a code block.

S220、测试代码修复装置200根据提示请求LLM进行修复,获得第一修复代码。S220, the test code repair device 200 requests the LLM to repair according to the prompt and obtains the first repair code.

具体地,测试代码修复装置200可以根据将提示输入LLM,以请求LLM根据提示对测试代码进行修复。其中,测试代码修复装置200可以将提示作为应用程序编程接口(application programming interface,API)参数,生成API调用请求,通过API调用请求调用LLM,接收LLM返回的第一修复代码。第一修复代码为LLM对测试代码中的错误代码进行修复得到。Specifically, the test code repair device 200 can input a prompt into the LLM to request the LLM to repair the test code based on the prompt. The test code repair device 200 can use the prompt as an application programming interface (API) parameter to generate an API call request, and then invoke the LLM through the API call request to receive the first repair code returned by the LLM. The first repair code is obtained by the LLM repairing the errors in the test code.

其中,LLM仅仅是语言模型的一个示例。实际应用时,测试代码修复装置200也可以使用高精度、高性能的小型语言模型(small language model,SLM)进行推理,获得第一修复代码。LLM is just one example of a language model. In practical applications, the test code repair device 200 can also use a high-precision, high-performance small language model (SLM) for inference to obtain the first repair code.

上述S216至S220为根据错误代码的位置信息,提取上下文信息,将基于上下文信息构建的提示输入语言模型进行推理,获得第一修复代码的一种具体实现。实际应用时,也可以通过其他方式获得第一修复代码。例如,在一些情况下,代码开发平台10(例如是测试代码修复装置200)可以根据错误代码的位置信息获取错误代码,将错误代码直接输入语言模型进行推理,获得第一修复代码。The steps S216 to S220 described above are a specific implementation of extracting context information based on the location information of the error code, and then using the prompt input language model constructed based on the context information for reasoning to obtain the first repair code. In practical applications, the first repair code can also be obtained through other methods. For example, in some cases, the code development platform 10 (e.g., the test code repair device 200) can obtain the error code based on its location information, directly input the error code into the language model for reasoning, and obtain the first repair code.

S222、测试代码修复装置200确定第一修复代码是否修复成功。若是,则执行S224;若否,则执行S226。S222, The test code repair device 200 determines whether the first repair code was successfully repaired. If yes, then execute S224; if no, then execute S226.

其中,测试代码修复装置200可以将第一修复代码返回交互装置100,第一修复代码可以是对测试代码修复后的全量代码,或者是对测试代码进行修复的增量代码。当第一修复代码为全量代码,则修复后的测试代码可以为第一修复代码,当第二修复代码为增量代码,则修复后的测试代码可以为使用第一修复代码修复的测试代码,例如是测试代码中插入第一修复代码形成的代码块。交互装置100可以通过执行修复后的测试代码,例如是第一修复代码或者是使用第一修复代码修复的测试代码,确定第一修复代码是否修复成功。The test code repair device 200 can return first repair code to the interaction device 100. The first repair code can be either the full code after repairing the test code or incremental code that repairs the test code. When the first repair code is the full code, the repaired test code can be the first repair code. When the second repair code is incremental code, the repaired test code can be the test code repaired using the first repair code, such as a code block formed by inserting the first repair code into the test code. The interaction device 100 can determine whether the first repair code was successfully repaired by executing the repaired test code, such as the first repair code or the test code repaired using the first repair code.

具体地,交互装置100对修复后的测试代码(如第一修复代码,或者是使用第一修复代码修复的测试代码)执行编译,若编译通过,则继续执行该修复后的测试代码。交互装置100可以根据执行结果,确定第一修复代码是否修复成功,并将修复结果返回测试代码修复装置200。若修复成功,则测试代码修复装置200可以停止修复,交互装置100可以保存第一修复代码。若修复不成功,可以继续进行测试代码修复。Specifically, the interactive device 100 compiles the repaired test code (such as the first repaired code, or the test code repaired using the first repaired code). If the compilation succeeds, the repaired test code continues to be executed. The interactive device 100 can determine whether the first repaired code was successfully repaired based on the execution result and return the repair result to the test code repair device 200. If the repair is successful, the test code repair device 200 can stop the repair, and the interactive device 100 can save the first repaired code. If the repair is unsuccessful, the test code repair can continue.

在一些可能的实现方式中,代码开发平台10还可以针对语言模型,配置最大重试次数(重试次数上限)。例如,最大重试次数可以配置为目标值。基于此,当第一修复代码修复失败,测试代码修复装置200可以针对测试代码重新基于LLM等语言模型执行代码修复,直至测试代码被修复成功或者重试次数达到目标值。In some possible implementations, the code development platform 10 can also configure a maximum number of retries (upper limit on the number of retries) for the language model. For example, the maximum number of retries can be configured as a target value. Based on this, when the first code repair fails, the test code repair device 200 can re-execute code repair based on the LLM or other language models for the test code until the test code is successfully repaired or the number of retries reaches the target value.

进一步地,交互装置100还可以在第一修复代码或者使用第一修复代码修复的测试代码执行不通过时,向用户呈现第一修复代码,接收用户对所述第一修复代码的反馈,获得更新后的第一修复代码。例如,交互装置100可以在重试次数达到目标次数,且修复后的测试代码(如第一修复代码或者使用第一修复代码修复的测试代码)仍未执行通过的情况下,向用户呈现第一修复代码,用户可以人工对第一修复代码进行修改,然后交互装置100接收用户对第一修复代码的反馈,获得更新后的第一修复代码。Furthermore, the interactive device 100 can also present the first repair code to the user when the first repair code or the test code repaired using the first repair code fails to execute, receive feedback from the user on the first repair code, and obtain an updated first repair code. For example, the interactive device 100 can present the first repair code to the user when the number of retries reaches the target number and the repaired test code (such as the first repair code or the test code repaired using the first repair code) still fails to execute. The user can then manually modify the first repair code, and the interactive device 100 can receive feedback from the user on the first repair code and obtain an updated first repair code.

S224、交互装置100保存执行通过的测试代码。S224. The interactive device 100 saves the test code that has passed execution.

其中,交互装置100可以在执行S208时,若测试代码执行通过,则保存该测试代码。或者,交互装置100可以在执行S214时,若确定第二修复代码修复成功,则保存修复成功的测试代码,其中,第二修复代码为全量代码时,修复成功的测试代码可以为第二修复代码,第二修复代码为增量代码时,修复成功的测试代码为第二修复代码和测试代码。或者,交互装置100可以在执行S222时,若确定第一修复代码修复成功,则保存修复成功的测试代码,其中,第一修复代码为全量代码时,修复成功的测试代码可以为第一修复代码,第一修复代码为增量代码时,修复成功的测试代码为第一修复代码和测试代码。In S208, if the test code executes successfully, the interactive device 100 can save the test code. Alternatively, in S214, if the second repair code is determined to be successfully repaired, the interactive device 100 can save the successfully repaired test code. If the second repair code is a full code, the successfully repaired test code can be the second repair code itself; if the second repair code is an incremental code, the successfully repaired test code can be both the second repair code and the test code. Alternatively, in S222, if the first repair code is determined to be successfully repaired, the interactive device 100 can save the successfully repaired test code. If the first repair code is a full code, the successfully repaired test code can be the first repair code itself; if the first repair code is an incremental code, the successfully repaired test code can be both the first repair code and the test code.

S226、交互装置100结束测试代码修复。S226, Interactive device 100 end test code repair.

上述S224、S226为本申请实施例的可选步骤,执行本申请的测试代码修复方法也可以不执行上述S224、S226。The above steps S224 and S226 are optional steps in the embodiments of this application. The test code repair method of this application may also omit the above steps S224 and S226.

基于上述内容描述,本申请实施例提供一种测试代码修复方法。该方法通过结合模板匹配修复技术和语言模型修复技术,实现了对测试代码的全面修复。其中,模板修复技术依赖于预设的修复模板,能够快速定位并修复常见错误类型的错误。语言模型修复技术则利用先进的语言模型,通过分析错误信息和代码上下文,生成更加精确和复杂的修复方案。如此,本申请的测试代码修复方法不仅适用于修复特定类型的错误,还能够处理各种复杂的错误场景,提供更加智能和灵活的修复策略,具有很强的通用性和适应性。通过该方法,可以显著提高测试代码修复的自动化水平,减少人工干预,加快软件开发和测试的迭代速度,提升软件的整体质量。Based on the above description, this application provides a test code repair method. This method combines template matching repair technology and language model repair technology to achieve comprehensive repair of test code. The template repair technology relies on preset repair templates and can quickly locate and repair common error types. The language model repair technology utilizes advanced language models to generate more accurate and complex repair solutions by analyzing error information and code context. Therefore, the test code repair method of this application is not only suitable for repairing specific types of errors but can also handle various complex error scenarios, providing more intelligent and flexible repair strategies, and has strong versatility and adaptability. This method can significantly improve the automation level of test code repair, reduce manual intervention, accelerate the iteration speed of software development and testing, and improve the overall quality of software.

需要说明的是,图2所示实施例是以模板匹配修复失败的情况下,使用语言模型修复作为补充手段,以进一步提高测试代码的修复成功率示例说明。为了提高修复成功率,代码开发平台还可以将模板匹配修复相关信息如第二修复代码或者是模板匹配的中间结果也作为上下文信息的一部分提供至语言模型,从而生成更精准的第一修复代码。在一些可能的实现方式中,代码开发平台10也可以直接使用语言模型进行测试代码修复,或者直接使用修复模板进行测试代码修复,本申请对此不作限制。It should be noted that the embodiment shown in Figure 2 illustrates how language model repair is used as a supplementary means to further improve the success rate of test code repair when template matching repair fails. To further improve the repair success rate, the code development platform can also provide template matching repair-related information, such as second repair code or intermediate template matching results, as part of the context information to the language model, thereby generating more accurate first repair code. In some possible implementations, the code development platform 10 can also directly use the language model for test code repair, or directly use the repair template for test code repair; this application does not impose any limitations on this.

接下来,以不同错误类型为例,对基于修复模板进行测试代码修复示例说明。其中,错误类型可以包括缺失类引用(或编译错误)、断言失败(断言错误)或异常。相应地,修复模板可以包括导包修复模板、断言修复模板或者是异常修复模板。下面依次进行说明。Next, we will use different error types as examples to illustrate test code repair based on repair templates. Error types can include missing class references (or compilation errors), assertion failures (assertion errors), or exceptions. Correspondingly, repair templates can include import repair templates, assertion repair templates, or exception repair templates. These will be explained in turn below.

在一些可能的实现方式中,错误代码的错误类型包括缺失类引用,相应地,第二修复代码可以包括导入(import)语句。代码开发平台10可以确定缺失的类名,基于项目依赖库、开发工具库或者三方库,构建符号索引,其中,符号索引包括可访问类的完全限定名。其中,完全限定名也称作全限定名、全限定类名,通常是指类名全称,通常携带包路径。例如,一个Java类的完全限定名可以为java.lang.String。缺失的类名是指缺失类引用的类名,该类名通常为非限定类名,也称短名,非限定类名通常不携带包路径或包名。例如,一个Java类的非限定类名可以为String。代码开发平台10将缺失的类名和符号索引进行匹配,获得所述缺失的类名对应的完全限定名。然后代码开发平台10将该完全限定名插入导包修复模板,获得导入语句。代码开发平台10可以采用增量更新方式修复测试代码,或者全量更新方式修复测试代码。在一些示例中,第二修复代码可以为增量代码,在该情况下,第二修复代码包括上述导入语句。在另一些示例中,第二修复代码可以为全量代码,在该情况下,第二修复代码可以包括测试代码和导入语句。例如,代码开发平台10可以在测试代码中插入导入语句,获得第二修复代码。In some possible implementations, the error type of the error code includes missing class references, and correspondingly, the second repair code may include import statements. The code development platform 10 can determine the missing class name and construct a symbol index based on project dependency libraries, development tool libraries, or third-party libraries. The symbol index includes the fully qualified name of the accessible class. The fully qualified name, also called the fully qualified class name, usually refers to the fully qualified class name and typically includes the package path. For example, the fully qualified name of a Java class could be java.lang.String. The missing class name refers to the class name of the missing class reference. This class name is usually an unqualified class name, also called a short name, and typically does not include the package path or package name. For example, the unqualified class name of a Java class could be String. The code development platform 10 matches the missing class name with the symbol index to obtain the fully qualified name corresponding to the missing class name. Then, the code development platform 10 inserts this fully qualified name into the import repair template to obtain the import statement. The code development platform 10 can repair the test code using either incremental updates or full updates. In some examples, the second fix code can be incremental code, in which case it includes the aforementioned import statements. In other examples, the second fix code can be full code, in which case it can include test code and import statements. For example, code development platform 10 can insert import statements into test code to obtain the second fix code.

其中,导包修复模板是针对编译时因缺少必要类或接口导入而引发的“无法找到符号”错误的修复策略。该导包修复模板的核心在于识别缺失的类引用,并自动插入相应的导入语句。下面结合一示例进行说明。The import repair template is a strategy to fix "symbol not found" errors caused by missing class or interface imports during compilation. The core of this template is to identify missing class references and automatically insert the corresponding import statements. An example is provided below to illustrate this.

在该示例中,代码开发平台10解析编译器输出的错误日志,获得错误类型T和错误代码的位置信息L{c}=(p,N{row},N{col})。其中,p表示文件路径,N{row}和N_{col}分别表示错误发生的行号和列号,以及缺失的类名或接口名S。然后,代码开发平台10执行下述步骤,以实现基于导包修复模板进行测试代码修复。In this example, the code development platform 10 parses the compiler's error log to obtain the error type T and the location information L{c} = (p, N{row}, N{col}). Here, p represents the file path, N{row} and N{col} represent the line number and column number where the error occurred, respectively, and the missing class name or interface name S. Then, the code development platform 10 performs the following steps to implement test code repair based on the imported package repair template.

步骤1、代码开发平台10基于项目依赖库、开发工具库以及第三方库,构建符号索引(Index,I)。Step 1: The code development platform 10 constructs a symbol index (Index, I) based on the project dependency library, development tool library, and third-party library.

其中,开发工具库与开发使用的编程语言相关,例如使用Java语言时,开发工具库可以为Java开发套件(Java development kit,JDK)库。该索引包含了所有可访问的Java类的完全限定名,实现S→R的映射,其中R表示符号S的完全限定名。The development toolkit (DMP) is related to the programming language used in development. For example, when using Java, the DMP could be the Java Development Kit (JDK) library. This index contains the fully qualified names of all accessible Java classes, implementing a mapping from S to R, where R represents the fully qualified name of the symbol S.

步骤2、代码开发平台10利用正则表达式从错误信息中提取缺失的类名S,在符号索引I中进行匹配,找到对应的完全限定名R。Step 2: The code development platform 10 uses regular expressions to extract the missing class name S from the error message, matches it in the symbol index I, and finds the corresponding fully qualified name R.

步骤3、代码开发平台10将匹配的完全限定名R填充至导包修复模板,生成完整的导入语句,并将导入语句插入到文件p已有的导包语句后。Step 3: The code development platform 10 fills the fully qualified name R of the matching import repair template, generates a complete import statement, and inserts the import statement after the existing import statement in file p.

在另一些可能的实现方式中,错误代码的错误类型包括断言失败。代码开发平台10可以确定错误代码中错误断言的断言类型,然后根据断言类型,选择更新断言修复模板或者是更新断言参数,从而实现修复错误断言。In some other possible implementations, the error type of the error code includes assertion failure. The code development platform 10 can determine the assertion type of the erroneous assertion in the error code, and then, based on the assertion type, choose to update the assertion repair template or update the assertion parameters, thereby repairing the erroneous assertion.

例如,断言类型为相等类型,代码开发平台10可以从错误代码中提取错误断言的预期值,从测试报告中提取错误断言的实际值,接着根据断言类型对应的断言修复模板,将错误断言的断言参数中的预期值替换为实际值。换言之,针对相等类型的错误断言,代码开发平台10使用原有的断言模板作为断言修复模板,将错误断言的断言参数进行替换,例如是将预期值替换为实际值,从而实现相等类型的错误断言的快速修复。For example, if the assertion type is equality, the code development platform 10 can extract the expected value of the erroneous assertion from the error code and the actual value of the erroneous assertion from the test report. Then, based on the assertion repair template corresponding to the assertion type, it replaces the expected value in the assertion parameters of the erroneous assertion with the actual value. In other words, for equality-type erroneous assertions, the code development platform 10 uses the existing assertion template as the assertion repair template and replaces the assertion parameters of the erroneous assertion, such as replacing the expected value with the actual value, thereby achieving rapid repair of equality-type erroneous assertions.

又例如,断言类型为布尔类型,代码开发平台10可以根据错误断言中的断言参数以及错误断言使用的第一断言修复模板对应的第二断言修复模板,生成第二修复代码,其中,第二断言修复模板的布尔逻辑与第一断言修复模板的布尔逻辑相反。换言之,针对布尔类型的错误断言,代码开发平台10通过更换模板,保持断言参数不变的方式实现快速修复布尔类型的错误断言。以单元测试示例说明,断言修复模板是针对单元测试中断言失败的情况进行修复的策略。断言修复模板的核心在于识别断言失败的原因,并自动调整断言的预期结果以匹配实际的测试结果。其中,预期结果可以是预期值,实际结果可以是实际值。For example, if the assertion type is Boolean, the code development platform 10 can generate second repair code based on the assertion parameters in the erroneous assertion and the second assertion repair template corresponding to the first assertion repair template used by the erroneous assertion. The Boolean logic of the second assertion repair template is the opposite of that of the first assertion repair template. In other words, for Boolean type erroneous assertions, the code development platform 10 achieves rapid repair of Boolean type erroneous assertions by changing the template while keeping the assertion parameters unchanged. Using a unit test example, the assertion repair template is a strategy for repairing assertion failures in unit tests. The core of the assertion repair template is to identify the cause of the assertion failure and automatically adjust the expected result of the assertion to match the actual test result. The expected result can be an expected value, and the actual result can be an actual value.

在通过错误定位,确定包括错误断言的测试代码行的位置信息L{f}=(p,N{row},N{col})后,可以执行如下步骤进行测试代码修复:After determining the location information L{f}=(p,N{row},N{col}) of the test code line containing the erroneous assertion through error localization, the following steps can be performed to repair the test code:

步骤1、代码开发平台10确定错误断言的断言类型。当断言类型为相等类型,从错误断言中提取该错误断言的预期值V{expected},从测试报告中提取出对应的实际值V{actual},然后执行步骤2;当断言类型为布尔类型,执行步骤3。Step 1: The code development platform 10 determines the assertion type of the error assertion. When the assertion type is an equality type, the expected value V{expected} of the error assertion is extracted from the error assertion, and the corresponding actual value V{actual} is extracted from the test report, and then Step 2 is executed; when the assertion type is a boolean type, Step 3 is executed.

其中,断言类型可以包括但不限于布尔类型、相等类型,布尔类型可以包括assertTrue、assertFalse、assertNull、assertNotNull,相等类型可以包括assertEquals。The assertion type can include, but is not limited to, boolean type and equality type. Boolean type can include assertTrue, assertFalse, assertNull, and assertNotNull, and equality type can include assertEquals.

步骤2、代码开发平台10在断言类型对应的断言修复模板中将错误断言的断言参数中的V{expected}替换为V{actual}。Step 2: In the assertion repair template corresponding to the assertion type, the code development platform 10 replaces V{expected} in the assertion parameter of the erroneous assertion with V{actual}.

步骤3、代码开发平台10根据错误断言中的断言参数以及错误断言使用的第一断言修复模板对应的第二断言修复模板,生成第二修复代码。Step 3: The code development platform 10 generates the second repair code based on the assertion parameters in the error assertion and the second assertion repair template corresponding to the first assertion repair template used by the error assertion.

其中,第二断言修复模板的布尔逻辑与第一断言修复模板的布尔逻辑相反。The Boolean logic of the second assertion repair template is the opposite of that of the first assertion repair template.

如图6所示,测试代码中使用assertEquals方法进行断言时,通常需要比较两个值是否相等,代码开发平台10使用正则表达式提取测试报告中实际值,对提取的实际值进行处理,例如是去除多余的括号或特殊字符,然后根据实际值的类型构造替换字符串,替换字符串可以表示为actualValue,使用替换字符串将assertEquals方法中的第一个参数expectedValue替换为actualValue。As shown in Figure 6, when using the assertEquals method for assertion in the test code, it is usually necessary to compare whether two values are equal. The code development platform 10 uses regular expressions to extract the actual value in the test report, processes the extracted actual value, such as removing redundant parentheses or special characters, and then constructs a replacement string according to the type of the actual value. The replacement string can be represented as actualValue. The replacement string is used to replace the first parameter expectedValue in the assertEquals method with actualValue.

如图7所示,当在测试代码中使用assertNull方法或者assertTrue方法进行断言时,如果测试失败,意味着被检查的对象与预期矛盾。在这种情况下,代码开发平台10可以将assertNull更正为assertNotNull,将assertTrue更正为assertFalse,由此可以实现快速修复。相反,如果在断言中使用assertNotNull或assertFalse测试失败,则代码开发平台10可以将assertNotNull更正为assertNull,assertFalse更正为assertTrue。As shown in Figure 7, when using the `assertNull` or `assertTrue` method for assertions in test code, if the test fails, it means that the object being checked contradicts expectations. In this case, the code development platform 10 can correct `assertNull` to `assertNotNull` and `assertTrue` to `assertFalse`, thus achieving quick repair. Conversely, if the test fails when using `assertNotNull` or `assertFalse` in the assertions, the code development platform 10 can correct `assertNotNull` to `assertNull` and `assertFalse` to `assertTrue`.

在一些可能的实现方式中,错误代码的错误类型包括异常,修复模板可以包括异常修复模板,相应地,第二修复代码可以包括异常对应的异常处理代码块。其中,异常修复模板是针对异常错误类型的修复策略,可以通过在可能抛出异常的代码块周围插入或完善异常处理机制,以捕获并处理这些异常,从而避免程序因未处理的异常而终止。代码开发平台10可以从异常的堆栈追踪信息中确定异常类型,将异常类型填充到异常修复模板,获得异常处理代码块(例如是异常处理语句)。其中,第二修复代码为增量代码时,第二修复代码可以包括上述异常处理代码块。第二修复代码为全量代码时,第二修复代码可以包括测试代码和异常处理代码块。例如,代码开平台10可以在测试代码中的错误代码之后插入异常处理代码块,获得第二修复代码。In some possible implementations, the error type of the error code includes exceptions, the repair template can include an exception repair template, and correspondingly, the second repair code can include the exception handling code block corresponding to the exception. The exception repair template is a repair strategy for exception error types. It can catch and handle these exceptions by inserting or improving exception handling mechanisms around code blocks that may throw exceptions, thereby preventing the program from terminating due to unhandled exceptions. The code development platform 10 can determine the exception type from the exception's stack trace information, fill the exception type into the exception repair template, and obtain the exception handling code block (e.g., an exception handling statement). When the second repair code is incremental code, it can include the aforementioned exception handling code block. When the second repair code is full code, it can include test code and the exception handling code block. For example, the code development platform 10 can insert an exception handling code block after the error code in the test code to obtain the second repair code.

其中,在通过错误定位,确定异常类型E和异常发生的代码块的位置信息L{e}=(p,N{row},N{col})后,可以执行如下步骤进行测试代码修复:After determining the exception type E and the location information L{e}=(p,N{row},N{col}) of the code block where the exception occurred through error localization, the following steps can be performed to repair the test code:

步骤1、代码开发平台10将异常类型E填充到异常修复模板中,生成完整的异常处理代码块,并将异常处理代码块插入到文件p中。Step 1: The code development platform 10 fills the exception type E into the exception repair template, generates a complete exception handling code block, and inserts the exception handling code block into the file p.

其中,异常处理代码块可以位于代码块C之前。The exception handling code block can be located before code block C.

步骤2、当插入完成后,代码开发平台10进行语法检查,确保新的代码片段符合Java语法规范,避免引入新的编译错误。Step 2: After the insertion is completed, the code development platform 10 performs a syntax check to ensure that the new code snippet conforms to the Java syntax specification and avoids introducing new compilation errors.

修复完成后,代码开发平台10还可以重新编译、执行修复后的测试代码,验证修复是否成功。如果编译成功且执行成功,则修复过程结束;如果仍有错误,代码开发平台10可以返回到异常信息提取阶段,继续处理下一个错误。After the repair is complete, the code development platform 10 can recompile and execute the repaired test code to verify whether the repair was successful. If the compilation and execution are successful, the repair process ends; if there are still errors, the code development platform 10 can return to the exception information extraction stage and continue to process the next error.

如图8所示,当测试代码中的某行代码抛出异常时,通过插入异常处理语句,可以捕获该异常,达到修复的目的。具体地,代码开发平台10可以通过使用try-catch语句包括可能抛出异常的代码行,并在catch块中处理预期的异常类型。As shown in Figure 8, when an exception is thrown in a line of code in the test code, the exception can be caught and repaired by inserting exception handling statements. Specifically, the code development platform 10 can use try-catch statements to include the line of code that may throw an exception and handle the expected exception type in the catch block.

如图9所示,在某些情况下,已有的异常处理语句可能无法完全覆盖代码执行过程中实际抛出的所有异常类型。为了进一步提高测试用例的健壮性,添加catch语句可以确保原有的异常处理逻辑保持完整,同时避免修改引入新的错误、扩大了异常处理的覆盖范围,使测试用例能够应对更多的错误场景。As shown in Figure 9, in some cases, existing exception handling statements may not fully cover all exception types actually thrown during code execution. To further improve the robustness of test cases, adding catch statements can ensure that the original exception handling logic remains intact, while avoiding the introduction of new errors through modifications, expanding the coverage of exception handling, and enabling test cases to handle more error scenarios.

其中,上述修复模板是以预设的静态修复模板示例说明。实际应用时,代码开发平台10可以不依赖于预设的静态修复模板,而是能够根据错误类型实时生成动态修复模板,提高修复的灵活性和准确性。例如,代码开发平台10可以通过交互装置100,使得开发者能够与后端的修复模板或模型进行更深入的交互,提出修改意见或选择多个可能的修复方案,从而更加精细地控制测试代码修复的过程。The aforementioned repair templates are examples of preset static repair templates. In practical applications, the code development platform 10 can generate dynamic repair templates in real time based on the error type, without relying on preset static repair templates, thus improving the flexibility and accuracy of repair. For example, the code development platform 10 can use the interactive device 100 to allow developers to interact more deeply with the backend repair templates or models, propose modifications, or select multiple possible repair solutions, thereby enabling more precise control over the test code repair process.

需要说明的是,本申请的测试代码修复方法不仅适用于Java单元测试代码的修复,还可以广泛应用于其他技术领域,如嵌入式系统开发、移动应用开发、网络安全等。在嵌入式系统中,代码通常需要优化以满足内存和处理能力的限制。因此,本申请的测试代码修复方法不仅可以修复错误,还优化代码以减少资源消耗。因此,修复模板可以包括针对资源优化的预设模板,而语言模型修复可以训练以识别并提出减少代码运行资源需求的解决方案。对于移动应用,为了确保应用的用户界面和用户体验不受代码错误的影响,可以使用基于用户界面设计(user interface,UI)模板/用户体验设计(userexperience,UX)模板的模板修复,专门用于修复可能影响用户界面的代码缺陷。语言模型修复则可以通过分析用户界面相关的错误信息来优化修复建议,确保应用的流畅运行。在网络安全领域,代码修复不仅需要处理功能性错误,还要解决可能导致安全漏洞的问题。模板修复可以引入针对常见安全漏洞的修复模板,如SQL注入或跨站脚本(Cross-site Scripting,XSS)攻击的防御。语言模型修复则可以进一步发展,以便能够根据安全漏洞的特定信息生成修复代码,提高系统的安全性。It should be noted that the test code repair method of this application is not only applicable to the repair of Java unit test code, but can also be widely applied to other technical fields, such as embedded system development, mobile application development, and network security. In embedded systems, code often needs to be optimized to meet memory and processing power limitations. Therefore, the test code repair method of this application can not only fix errors, but also optimize the code to reduce resource consumption. Thus, the repair template can include preset templates for resource optimization, while language model repair can be trained to identify and propose solutions to reduce the resource requirements of code execution. For mobile applications, to ensure that the application's user interface and user experience are not affected by code errors, template repair based on user interface (UI) templates/user experience (UX) templates can be used, specifically for repairing code defects that may affect the user interface. Language model repair can optimize repair suggestions by analyzing error information related to the user interface, ensuring smooth application operation. In the field of network security, code repair needs to address not only functional errors, but also issues that may lead to security vulnerabilities. Template repair can introduce repair templates for common security vulnerabilities, such as defense against SQL injection or cross-site scripting (XSS) attacks. Language model repair can be further developed to generate repair code based on specific information about security vulnerabilities, thereby improving system security.

基于前述的代码生成方法,本申请还提供一种代码开发平台10。代码开发平台10用于集成功能至应用,如图1所示,该代码开发平台10包括:Based on the aforementioned code generation method, this application also provides a code development platform 10. The code development platform 10 is used to integrate functions into applications. As shown in Figure 1, the code development platform 10 includes:

测试代码选取模块102,用于获取源代码对应的测试代码,所述测试代码用于对所述源代码的功能和/或性能进行测试;The test code selection module 102 is used to obtain the test code corresponding to the source code, and the test code is used to test the functionality and/or performance of the source code;

运行模块104,用于执行所述测试代码,获得所述测试代码的执行信息,所述执行信息包括执行所述测试代码时输出的异常的堆栈追踪信息;The execution module 104 is used to execute the test code and obtain the execution information of the test code, the execution information including the stack trace information of the exceptions output when the test code is executed;

错误定位模块,用于根据所述执行信息对所述测试代码进行错误定位,获得错误代码的位置信息;The error location module is used to locate errors in the test code based on the execution information and obtain the location information of the error code.

模型修复模块201,用于根据所述错误代码的位置信息,提取上下文信息,所述上下文信息包括错误的测试用例、错误描述或所述错误内容中的至少一种,将基于所述上下文信息构建的提示输入语言模型进行推理,获得第一修复代码,所述第一修复代码为所述语言模型对所述测试代码中的所述错误代码进行修复得到。The model repair module 201 is used to extract context information based on the location information of the error code. The context information includes at least one of the error test case, error description, or error content. The module then uses a prompt input language model built based on the context information to perform reasoning to obtain a first repair code. The first repair code is obtained by the language model repairing the error code in the test code.

示例性地,上述测试代码选取模块102、运行模块104和错误定位模块、模型修复模块201。测试代码选取模块102、运行模块104和错误定位模块、模型修复模块201可以通过硬件实现,或者可以通过软件实现。For example, the above-mentioned test code selection module 102, execution module 104, error location module, and model repair module 201 can be implemented in hardware or software.

当通过软件实现时,测试代码选取模块102、运行模块104和错误定位模块、模型修复模块201可以是运行在计算设备上的应用程序,如计算引擎等。上述应用程序还可以进行虚拟化,以虚拟化服务形式提供给用户使用。虚拟化服务可以包括虚拟机(virtual machine,VM)服务、裸金属服务器(bare metal server,BMS)服务或容器(container)服务。其中,VM服务可以是通过虚拟化技术在多个物理主机上虚拟出虚拟机(virtual machine,VM)资源池以为用户按需提供VM进行使用的服务。BMS服务是在多个物理主机上虚拟出BMS资源池以为用户按需提供BMS进行使用的服务。容器服务是在多个物理主机上虚拟出容器资源池以为用户按需提供容器进行使用的服务。VM是模拟出来的一台虚拟的计算机,也即逻辑上的一台计算机。BMS是一种可弹性伸缩的高性能计算服务,计算性能与传统物理机无差别,具有安全物理隔离的特点。容器是一种内核虚拟化技术,可以提供轻量级的虚拟化,以达到隔离用户空间、进程和资源的目的。应理解,上述虚拟化服务中的VM服务、BMS服务以及容器服务仅仅是作为具体的事例,在实际应用中,虚拟化服务还可以其他轻量级或者重量级的虚拟化服务,此处不作具体限定。When implemented in software, the test code selection module 102, execution module 104, error location module, and model repair module 201 can be applications running on computing devices, such as computing engines. These applications can also be virtualized and provided to users as virtualization services. Virtualization services can include virtual machine (VM) services, bare metal server (BMS) services, or container services. VM services can be services that use virtualization technology to create virtual machine (VM) resource pools on multiple physical hosts to provide VMs for users to use on demand. BMS services are services that use virtualization technology to create BMS resource pools on multiple physical hosts to provide BMS for users to use on demand. Container services are services that use virtualization technology to create container resource pools on multiple physical hosts to provide containers for users to use on demand. A VM is a simulated virtual computer, that is, a logical computer. A BMS is a scalable, high-performance computing service with computing performance indistinguishable from traditional physical machines and features secure physical isolation. Containers are a kernel virtualization technology that provides lightweight virtualization to isolate user space, processes, and resources. It should be understood that the VM service, BMS service, and container service mentioned above are merely specific examples. In practical applications, virtualization services can also include other lightweight or heavyweight virtualization services, which are not specifically limited here.

当通过硬件实现时,测试代码选取模块102、运行模块104和错误定位模块、模型修复模块201中可以包括至少一个计算设备,如服务器等。或者,测试代码选取模块102、运行模块104和错误定位模块、模型修复模块201也可以是利用专用集成电路(application-specific integrated circuit,ASIC)实现、或可编程逻辑器件(programmable logic device,PLD)实现的设备等。其中,上述PLD可以是复杂程序逻辑器件(complex programmable logical device,CPLD)、现场可编程门阵列(field-programmable gate array,FPGA)、通用阵列逻辑(generic array logic,GAL)或其任意组合实现。When implemented in hardware, the test code selection module 102, the execution module 104, the error location module, and the model repair module 201 may include at least one computing device, such as a server. Alternatively, the test code selection module 102, the execution module 104, the error location module, and the model repair module 201 may also be implemented using an application-specific integrated circuit (ASIC) or a programmable logic device (PLD). The PLD may be a complex programmable logical device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), or any combination thereof.

在一些可能的实现方式中,所述代码开发平台10还包括反馈模块108:In some possible implementations, the code development platform 10 further includes a feedback module 108:

所述运行模块104,还用于执行所述第一修复代码或者使用所述第一修复代码修复的所述测试代码;The running module 104 is further configured to execute the first repair code or the test code repaired using the first repair code;

所述反馈模块108,用于当执行不通过,向所述用户呈现所述第一修复代码,接收所述用户对所述第一修复代码的反馈,获得更新后的所述第一修复代码。The feedback module 108 is used to present the first repair code to the user when the execution fails, receive feedback from the user on the first repair code, and obtain the updated first repair code.

反馈模块108可以通过软件实现,或者通过硬件实现。当通过软件实现时,反馈模块108可以是运行在计算设备上的应用程序,如计算引擎等。上述应用程序还可以进行虚拟化,通过VM、container等以虚拟化服务形式提供给用户使用。当通过硬件实现时,反馈模块108中可以包括至少一个计算设备,如服务器等。The feedback module 108 can be implemented in software or hardware. When implemented in software, the feedback module 108 can be an application running on a computing device, such as a computing engine. This application can also be virtualized and provided to users as a virtualization service via VMs, containers, etc. When implemented in hardware, the feedback module 108 can include at least one computing device, such as a server.

在一些可能的实现方式中,所述代码开发平台10还包括:In some possible implementations, the code development platform 10 also includes:

模板匹配修复模块203,用于确定所述错误代码的错误类型,根据所述错误类型对应的修复模板对所述错误代码进行修复,获得第二修复代码;The template matching and repair module 203 is used to determine the error type of the error code, repair the error code according to the repair template corresponding to the error type, and obtain a second repair code;

所述模型修复模块201具体用于:The model repair module 201 is specifically used for:

当所述第二修复代码修复失败,根据所述错误代码的位置信息,提取上下文信息。If the second repair code fails to repair, the context information is extracted based on the location information of the error code.

在一些可能的实现方式中,所述错误代码的错误类型包括断言失败;In some possible implementations, the error type of the error code includes assertion failure;

所述模板匹配修复模块203具体用于:The template matching and repair module 203 is specifically used for:

确定所述错误代码中错误断言的断言类型;Determine the assertion type of the error assertion in the error code;

当所述断言类型为相等类型,从所述错误代码中提取所述错误断言的预期值,从测试报告中提取所述错误断言的实际值;When the assertion type is an equality type, extract the expected value of the error assertion from the error code and extract the actual value of the error assertion from the test report;

根据所述断言类型对应的断言修复模板,将所述错误断言的断言参数中的所述预期值替换为所述实际值,获得第二修复代码。Based on the assertion repair template corresponding to the assertion type, the expected value in the assertion parameter of the erroneous assertion is replaced with the actual value to obtain the second repair code.

模板匹配修复模块203可以通过软件实现,或者通过硬件实现。当通过软件实现时,模板匹配修复模块203可以是运行在计算设备上的应用程序,如计算引擎等。上述应用程序还可以进行虚拟化,通过VM、container等以虚拟化服务形式提供给用户使用。当通过硬件实现时,模板匹配修复模块203中可以包括至少一个计算设备,如服务器等。The template matching and repair module 203 can be implemented in software or hardware. When implemented in software, the template matching and repair module 203 can be an application running on a computing device, such as a computing engine. This application can also be virtualized and provided to users as a virtualization service via VMs, containers, etc. When implemented in hardware, the template matching and repair module 203 can include at least one computing device, such as a server.

在一些可能的实现方式中,所述模板匹配修复模块203还用于:In some possible implementations, the template matching and repair module 203 is further configured to:

当所述断言类型为布尔类型,根据所述错误断言中的断言参数以及所述错误断言使用的第一断言修复模板对应的第二断言修复模板,生成第二修复代码,所述第二断言修复模板的布尔逻辑与所述第一断言修复模板的布尔逻辑相反。When the assertion type is Boolean, a second repair code is generated based on the assertion parameters in the error assertion and the second assertion repair template corresponding to the first assertion repair template used by the error assertion. The Boolean logic of the second assertion repair template is the opposite of the Boolean logic of the first assertion repair template.

在一些可能的实现方式中,所述错误代码的错误类型包括异常,所述第二修复代码包括所述异常对应的异常处理代码块;In some possible implementations, the error type of the error code includes an exception, and the second repair code includes an exception handling code block corresponding to the exception;

所述模板匹配修复模块具体用于:The template matching and repair module is specifically used for:

从所述异常的堆栈追踪信息中确定异常类型;Determine the exception type from the stack trace information of the exception;

将所述异常类型填充到异常修复模板,获得所述异常处理代码块。Fill the exception type into the exception repair template to obtain the exception handling code block.

在一些可能的实现方式中,所述代码开发平台10还包括:In some possible implementations, the code development platform 10 also includes:

编译模块103,用于编译所述测试代码,获得所述测试代码的编译信息,所述编译信息包括编译器对所述测试代码进行编译输出的错误日志,所述错误日志记录有所述错误代码的错误类型;The compilation module 103 is used to compile the test code and obtain the compilation information of the test code. The compilation information includes the error log output by the compiler when compiling the test code. The error log records the error type of the error code.

当所述错误代码的错误类型包括缺失类引用,所述第二修复代码包括导入语句;When the error code includes a missing class reference, the second repair code includes an import statement;

所述模板匹配修复模块203具体用于:The template matching and repair module 203 is specifically used for:

确定缺失的类名;Determine the missing class name;

基于项目依赖库、开发工具库或者三方库,构建符号索引,所述符号索引包括可访问类的完全限定名;Based on project dependency libraries, development tool libraries, or third-party libraries, construct a symbol index, which includes the fully qualified names of accessible classes;

将所述缺失的类名和所述符号索引进行匹配,获得所述缺失的类名对应的完全限定名;The missing class name is matched with the symbol index to obtain the fully qualified name corresponding to the missing class name;

将所述完全限定名插入导包修复模板,获得所述导入语句。Insert the fully qualified name into the import package repair template to obtain the import statement.

其中,编译模块103可以通过软件实现,或者通过硬件实现。当通过软件实现时,编译模块103可以是运行在计算设备上的应用程序,如计算引擎等。上述应用程序还可以进行虚拟化,通过VM、container等以虚拟化服务形式提供给用户使用。当通过硬件实现时,编译模块103中可以包括至少一个计算设备,如服务器等。The compilation module 103 can be implemented in software or hardware. When implemented in software, the compilation module 103 can be an application running on a computing device, such as a computing engine. This application can also be virtualized and provided to users as a virtualization service via VMs, containers, etc. When implemented in hardware, the compilation module 103 can include at least one computing device, such as a server.

需要说明的是,图1中的编译模块103、运行模块104还可以耦合为一个模块,例如是耦合为编译与运行模块。图1仅仅是代码开发平台10的一种具体实现方式,在本申请实施例其他可能的实现方式中,也可以通过其他方式进行测试代码的编译、运行。It should be noted that the compilation module 103 and the runtime module 104 in Figure 1 can also be coupled into a single module, for example, coupled into a compilation and runtime module. Figure 1 is merely one specific implementation of the code development platform 10. In other possible implementations of this application, the compilation and execution of test code can also be performed in other ways.

在一些可能的实现方式中,所述模型修复模块201还用于:In some possible implementations, the model repair module 201 is further configured to:

当所述第一修复代码修复失败,针对所述测试代码重新执行代码修复,直至所述测试代码被修复成功或者重试次数达到目标值。If the first repair code fails to repair, the code repair is re-executed for the test code until the test code is successfully repaired or the number of retries reaches the target value.

本申请还提供一种计算设备1000。如图10所示,计算设备1000包括:总线1002、处理器1004、存储器1006和通信接口1008。处理器1004、存储器1006和通信接口1008之间通过总线1002通信。计算设备1000可以是服务器或终端设备。应理解,本申请不限定计算设备1000中的处理器、存储器的个数。This application also provides a computing device 1000. As shown in FIG10, the computing device 1000 includes: a bus 1002, a processor 1004, a memory 1006, and a communication interface 1008. The processor 1004, the memory 1006, and the communication interface 1008 communicate with each other via the bus 1002. The computing device 1000 can be a server or a terminal device. It should be understood that this application does not limit the number of processors and memories in the computing device 1000.

总线1002可以是外设部件互连标准(peripheral component interconnect,PCI)总线或扩展工业标准结构(extended industry standard architecture,EISA)总线等。总线可以分为地址总线、数据总线、控制总线等。为便于表示,图10中仅用一条线表示,但并不表示仅有一根总线或一种类型的总线。总线1002可包括在计算设备1000各个部件(例如,存储器1006、处理器1004、通信接口1008)之间传送信息的通路。Bus 1002 can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. Buses can be categorized as address buses, data buses, control buses, etc. For ease of illustration, only one line is used in Figure 10, but this does not imply that there is only one bus or one type of bus. Bus 1002 can include pathways for transmitting information between various components of computing device 1000 (e.g., memory 1006, processor 1004, communication interface 1008).

处理器1004可以包括中央处理器(central processing unit,CPU)、图形处理器(graphics processing unit,GPU)、微处理器(micro processor,MP)或者数字信号处理器(digital signal processor,DSP)等处理器中的任意一种或多种。The processor 1004 may include any one or more of the following processors: central processing unit (CPU), graphics processing unit (GPU), microprocessor (MP), or digital signal processor (DSP).

存储器1006可以包括易失性存储器(volatile memory),例如随机存取存储器(random access memory,RAM)。存储器1006还可以包括非易失性存储器(non-volatile memory),例如只读存储器(read-only memory,ROM),快闪存储器,机械硬盘(hard disk drive,HDD)或固态硬盘(solid state drive,SSD)。存储器1006中存储有可执行的程序代码,处理器1004执行该可执行的程序代码以实现前述代码生成方法。具体的,存储器1006上存有代码开发平台10用于执行代码生成方法的指令。The memory 1006 may include volatile memory, such as random access memory (RAM). The memory 1006 may also include non-volatile memory, such as read-only memory (ROM), flash memory, hard disk drive (HDD), or solid-state drive (SSD). The memory 1006 stores executable program code, which the processor 1004 executes to implement the aforementioned code generation method. Specifically, the memory 1006 stores instructions from the code development platform 10 for executing the code generation method.

通信接口1008使用例如但不限于网络接口卡、收发器一类的收发模块,来实现计算设备1000与其他设备或通信网络之间的通信。The communication interface 1008 uses transceiver modules such as, but not limited to, network interface cards and transceivers to enable communication between the computing device 1000 and other devices or communication networks.

本申请实施例还提供了一种计算设备集群。该计算设备集群包括至少一台计算设备。该计算设备可以是服务器,例如是中心服务器、边缘服务器,或者是本地数据中心中的本地服务器。在一些实施例中,计算设备也可以是台式机、笔记本电脑或者智能手机等终端设备。This application also provides a computing device cluster. The computing device cluster includes at least one computing device. The computing device can be a server, such as a central server, an edge server, or a local server in a local data center. In some embodiments, the computing device can also be a terminal device such as a desktop computer, a laptop computer, or a smartphone.

如图11所示,所述计算设备集群包括至少一个计算设备1000。计算设备集群中的一个或多个计算设备1000中的存储器1006中可以存有相同的代码开发平台10用于执行代码生成方法的指令。As shown in Figure 11, the computing device cluster includes at least one computing device 1000. The memory 1006 of one or more computing devices 1000 in the computing device cluster may store instructions from the same code development platform 10 for executing code generation methods.

在一些可能的实现方式中,该计算设备集群中的一个或多个计算设备1000也可以用于执行代码开发平台10用于执行代码生成方法的部分指令。换言之,一个或多个计算设备1000的组合可以共同执行代码开发平台10用于执行代码生成方法的指令。In some possible implementations, one or more computing devices 1000 in the computing device cluster can also be used to execute some of the instructions used by the code development platform 10 to execute the code generation method. In other words, a combination of one or more computing devices 1000 can jointly execute the instructions used by the code development platform 10 to execute the code generation method.

需要说明的是,计算设备集群中的不同的计算设备1000中的存储器1006可以存储不同的指令,用于执行代码开发平台10的部分功能。It should be noted that the memory 1006 in different computing devices 1000 in the computing device cluster can store different instructions for executing some functions of the code development platform 10.

图12示出了一种可能的实现方式。如图12所示,两个计算设备1000A和1000B通过通信接口1008实现连接。计算设备1000A中的存储器上存有用于执行测试代码选取模块102、运行模块104的功能的指令。计算设备1000B中的存储器上存有用于执行错误定位模块、模型修复模块201的功能的指令。进一步地,计算设备1000A中的存储器还存有用于执行编译模块103、修复策略选取模块106、反馈模块108的功能的指令,计算设备1000B的存储器中还存有用于执行模板匹配修复模块203的功能的指令。换言之,计算设备1000A和1000B的存储器1006共同存储了代码开发平台10用于执行代码生成方法的指令。Figure 12 illustrates one possible implementation. As shown in Figure 12, two computing devices 1000A and 1000B are connected via a communication interface 1008. The memory in computing device 1000A stores instructions for executing the functions of the test code selection module 102 and the execution module 104. The memory in computing device 1000B stores instructions for executing the functions of the error location module and the model repair module 201. Furthermore, the memory in computing device 1000A also stores instructions for executing the functions of the compilation module 103, the repair strategy selection module 106, and the feedback module 108, while the memory in computing device 1000B also stores instructions for executing the function of the template matching repair module 203. In other words, the memory 1006 of computing devices 1000A and 1000B jointly stores the instructions used by the code development platform 10 to execute the code generation method.

图12所示的计算设备集群之间的连接方式可以是考虑到本申请提供的代码生成方法需要较多资源运行语言模型,从而实现基于语言模型推理生成第一修复代码。因此,考虑将测试代码修复装置200中错误定位模块、模型修复模块201实现的功能交由独立的计算设备执行。例如,交互装置100中相关模块实现的功能由计算设备1000A执行,测试代码修复装置200中相关模块实现的功能由计算设备1000B执行。The connection method between the computing device clusters shown in Figure 12 can be considered because the code generation method provided in this application requires a lot of resources to run the language model, thereby realizing the generation of the first repair code based on language model reasoning. Therefore, it is considered to dedicate the functions implemented by the error location module and the model repair module 201 in the test code repair device 200 to independent computing devices. For example, the functions implemented by the relevant modules in the interaction device 100 are executed by computing device 1000A, and the functions implemented by the relevant modules in the test code repair device 200 are executed by computing device 1000B.

应理解,图12中示出的计算设备1000A的功能也可以由多个计算设备1000完成。同样,计算设备1000B的功能也可以由多个计算设备1000完成。It should be understood that the functions of computing device 1000A shown in Figure 12 can also be performed by multiple computing devices 1000. Similarly, the functions of computing device 1000B can also be performed by multiple computing devices 1000.

在一些可能的实现方式中,计算设备集群中的一个或多个计算设备可以通过网络连接。其中,所述网络可以是广域网或局域网等等。图13示出了一种可能的实现方式。如图13所示,两个计算设备1000C和1000D之间通过网络进行连接。具体地,通过各个计算设备中的通信接口与所述网络进行连接。在这一类可能的实现方式中,计算设备1000C中的存储器1006中存有执行交互装置100中相关模块的功能的指令,例如是存储执行测试代码选取模块102、运行模块104的功能的指令,进一步地,计算设备1000C中的存储器1006中还存储用于执行编译模块103、修复策略选取模块106、反馈模块108的功能的指令。同时,计算设备1000D中的存储器1006中存有执行测试代码修复装置200中相关模块的功能的指令,例如计算设备1000D的存储器中存储执行错误定位模块、模型修复模块201的功能的指令,进一步地,计算设备1000D的存储器中还存储执行模板匹配修复模块203的功能的指令。In some possible implementations, one or more computing devices in a computing device cluster can be connected via a network. This network can be a wide area network (WAN) or a local area network (LAN), etc. Figure 13 illustrates one possible implementation. As shown in Figure 13, two computing devices 1000C and 1000D are connected via a network. Specifically, they are connected to the network through communication interfaces in each computing device. In this type of possible implementation, the memory 1006 in computing device 1000C stores instructions for executing the functions of relevant modules in the interactive device 100, such as instructions for executing the functions of the test code selection module 102 and the execution module 104. Furthermore, the memory 1006 in computing device 1000C also stores instructions for executing the functions of the compilation module 103, the repair strategy selection module 106, and the feedback module 108. Meanwhile, the memory 1006 in the computing device 1000D stores instructions for executing the functions of relevant modules in the test code repair device 200. For example, the memory of the computing device 1000D stores instructions for executing the functions of the error location module and the model repair module 201. Furthermore, the memory of the computing device 1000D also stores instructions for executing the functions of the template matching repair module 203.

图13所示的计算设备集群之间的连接方式可以是考虑到本申请提供的代码生成方法需要大量资源进行推理以生成第一修复代码,因此考虑将测试代码修复装置200中相关模块实现的功能交由计算设备1000D执行。The connection method between the computing device clusters shown in Figure 13 can be considered as follows: taking into account that the code generation method provided in this application requires a lot of resources for reasoning to generate the first repair code, it is considered that the functions implemented by the relevant modules in the test code repair device 200 are handed over to the computing device 1000D for execution.

应理解,图13中示出的计算设备1000C的功能也可以由多个计算设备1000完成。同样,计算设备1000D的功能也可以由多个计算设备1000完成。It should be understood that the functions of computing device 1000C shown in Figure 13 can also be performed by multiple computing devices 1000. Similarly, the functions of computing device 1000D can also be performed by multiple computing devices 1000.

本申请实施例还提供了一种计算机可读存储介质。所述计算机可读存储介质可以是计算设备能够存储的任何可用介质或者是包含一个或多个可用介质的数据中心等数据存储设备。所述可用介质可以是磁性介质,(例如,软盘、硬盘、磁带)、光介质(例如,DVD)、或者半导体介质(例如固态硬盘)等。该计算机可读存储介质包括指令,所述指令指示计算设备执行上述应用于代码开发平台10用于执行代码生成方法。This application also provides a computer-readable storage medium. The computer-readable storage medium can be any available medium that a computing device can store, or a data storage device such as a data center containing one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid-state drive). The computer-readable storage medium includes instructions that instruct the computing device to execute the code generation method described above applied to the code development platform 10.

本申请实施例还提供了一种包含指令的计算机程序产品。所述计算机程序产品可以是包含指令的,能够运行在计算设备上或被储存在任何可用介质中的软件或程序产品。当所述计算机程序产品在至少一个计算设备上运行时,使得至少一个计算设备执行上述代码生成方法。This application also provides a computer program product containing instructions. The computer program product may be a software or program product containing instructions, capable of running on a computing device or stored on any usable medium. When the computer program product is run on at least one computing device, it causes the at least one computing device to execute the above-described code generation method.

最后应说明的是:以上实施例仅用以说明本发明的技术方案,而非对其限制;尽管参照前述实施例对本发明进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本发明各实施例技术方案的保护范围。Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the protection scope of the technical solutions of the embodiments of the present invention.

Claims (19)

一种测试代码修复方法,其特征在于,应用于代码开发平台,所述方法包括:A method for fixing test code, characterized in that it is applied to a code development platform, the method comprising: 获取源代码对应的测试代码,所述测试代码用于对所述源代码的功能和/或性能进行测试;Obtain the test code corresponding to the source code, and the test code is used to test the functionality and/or performance of the source code; 执行所述测试代码,获得所述测试代码的执行信息,所述执行信息包括执行所述测试代码时输出的异常的堆栈追踪信息;Execute the test code to obtain the execution information of the test code, the execution information including the stack trace information of the exceptions output when the test code is executed; 根据所述执行信息对所述测试代码进行错误定位,获得错误代码的位置信息;Based on the execution information, the test code is used to locate errors and obtain the location information of the error code. 根据所述错误代码的位置信息,提取上下文信息,所述上下文信息包括错误的测试用例、错误描述或所述错误内容中的至少一种;Based on the location information of the error code, extract the context information, which includes at least one of the error test case, error description, or error content. 将基于所述上下文信息构建的提示输入语言模型进行推理,获得第一修复代码,所述第一修复代码为所述语言模型对所述测试代码中的所述错误代码进行修复得到。The prompt input language model constructed based on the context information is used for reasoning to obtain a first repair code, which is obtained by the language model to repair the erroneous code in the test code. 根据权利要求1所述的方法,其特征在于,所述方法还包括:The method according to claim 1, characterized in that the method further comprises: 执行所述第一修复代码或者使用所述第一修复代码修复的所述测试代码;Execute the first fix code or the test code that is fixed using the first fix code; 当执行不通过,向所述用户呈现所述第一修复代码,接收所述用户对所述第一修复代码的反馈,获得更新后的所述第一修复代码。If the execution fails, the first fix code is presented to the user, feedback from the user on the first fix code is received, and the updated first fix code is obtained. 根据权利要求1或2所述的方法,其特征在于,所述方法还包括:The method according to claim 1 or 2, characterized in that the method further comprises: 确定所述错误代码的错误类型;Determine the error type of the error code; 根据所述错误类型对应的修复模板对所述错误代码进行修复,获得第二修复代码;The error code is repaired according to the repair template corresponding to the error type to obtain the second repair code; 所述根据所述错误代码的位置信息,提取上下文信息,包括:The step of extracting context information based on the location information of the error code includes: 当所述第二修复代码修复失败,根据所述错误代码的位置信息,提取上下文信息。If the second repair code fails to repair, the context information is extracted based on the location information of the error code. 根据权利要求3所述的方法,其特征在于,所述错误代码的错误类型包括断言失败;The method according to claim 3, wherein the error type of the error code includes assertion failure; 所述根据所述错误类型对应的修复模板对所述错误代码进行修复,获得第二修复代码,包括:The step of repairing the error code according to the repair template corresponding to the error type to obtain the second repair code includes: 确定所述错误代码中错误断言的断言类型;Determine the assertion type of the error assertion in the error code; 当所述断言类型为相等类型,从所述错误代码中提取所述错误断言的预期值,从测试报告中提取所述错误断言的实际值;When the assertion type is an equality type, extract the expected value of the error assertion from the error code and extract the actual value of the error assertion from the test report; 根据所述断言类型对应的断言修复模板,将所述错误断言的断言参数中的所述预期值替换为所述实际值,获得第二修复代码。Based on the assertion repair template corresponding to the assertion type, the expected value in the assertion parameter of the erroneous assertion is replaced with the actual value to obtain the second repair code. 根据权利要求4所述的方法,其特征在于,所述方法还包括:The method according to claim 4, characterized in that the method further comprises: 当所述断言类型为布尔类型,根据所述错误断言中的断言参数以及所述错误断言使用的第一断言修复模板对应的第二断言修复模板,生成第二修复代码,所述第二断言修复模板的布尔逻辑与所述第一断言修复模板的布尔逻辑相反。When the assertion type is Boolean, a second repair code is generated based on the assertion parameters in the error assertion and the second assertion repair template corresponding to the first assertion repair template used by the error assertion. The Boolean logic of the second assertion repair template is the opposite of the Boolean logic of the first assertion repair template. 根据权利要求3所述的方法,其特征在于,所述错误代码的错误类型包括异常,所述第二修复代码包括所述异常对应的异常处理代码块;According to the method of claim 3, the error type of the error code includes an exception, and the second repair code includes an exception handling code block corresponding to the exception; 所述根据所述错误类型对应的修复模板对所述错误代码进行修复,获得第二修复代码,包括:The step of repairing the error code according to the repair template corresponding to the error type to obtain the second repair code includes: 从所述异常的堆栈追踪信息中确定异常类型;Determine the exception type from the stack trace information of the exception; 将所述异常类型填充到异常修复模板,获得所述异常处理代码块。Fill the exception type into the exception repair template to obtain the exception handling code block. 根据权利要求3所述的方法,其特征在于,所述方法还包括:The method according to claim 3, characterized in that the method further comprises: 编译所述测试代码,获得所述测试代码的编译信息,所述编译信息包括编译器对所述测试代码进行编译输出的错误日志,所述错误日志记录有所述错误代码的错误类型;Compile the test code to obtain the compilation information of the test code. The compilation information includes the error log output by the compiler when compiling the test code. The error log records the error type of the error code. 当所述错误代码的错误类型包括缺失类引用,所述第二修复代码包括导入语句;When the error code includes a missing class reference, the second repair code includes an import statement; 所述根据所述错误类型对应的修复模板对所述错误代码进行修复,获得第二修复代码,包括:The step of repairing the error code according to the repair template corresponding to the error type to obtain the second repair code includes: 确定缺失的类名;Determine the missing class name; 基于项目依赖库、开发工具库或者三方库,构建符号索引,所述符号索引包括可访问类的完全限定名;Based on project dependency libraries, development tool libraries, or third-party libraries, construct a symbol index, which includes the fully qualified names of accessible classes; 将所述缺失的类名和所述符号索引进行匹配,获得所述缺失的类名对应的完全限定名;The missing class name is matched with the symbol index to obtain the fully qualified name corresponding to the missing class name; 将所述完全限定名插入导包修复模板,获得所述导入语句。Insert the fully qualified name into the import package repair template to obtain the import statement. 根据权利要求1至7任一项所述的方法,其特征在于,所述方法还包括:The method according to any one of claims 1 to 7, characterized in that the method further comprises: 当所述第一修复代码修复失败,针对所述测试代码重新执行代码修复,直至所述测试代码被修复成功或者重试次数达到目标值。If the first repair code fails to repair, the code repair is re-executed for the test code until the test code is successfully repaired or the number of retries reaches the target value. 一种代码开发平台,其特征在于,所述代码开发平台包括:A code development platform, characterized in that the code development platform comprises: 测试代码选取模块,用于获取源代码对应的测试代码,所述测试代码用于对所述源代码的功能和/或性能进行测试;The test code selection module is used to obtain the test code corresponding to the source code, and the test code is used to test the functionality and/or performance of the source code; 运行模块,用于执行所述测试代码,获得所述测试代码的执行信息,所述执行信息包括执行所述测试代码时输出的异常的堆栈追踪信息;The execution module is used to execute the test code and obtain the execution information of the test code, including the stack trace information of the exceptions output when the test code is executed; 错误定位模块,用于根据所述执行信息对所述测试代码进行错误定位,获得错误代码的位置信息;The error location module is used to locate errors in the test code based on the execution information and obtain the location information of the error code. 模型修复模块,用于根据所述错误代码的位置信息,提取上下文信息,所述上下文信息包括错误的测试用例、错误描述或所述错误内容中的至少一种,将基于所述上下文信息构建的提示输入语言模型进行推理,获得第一修复代码,所述第一修复代码为所述语言模型对所述测试代码中的所述错误代码进行修复得到。The model repair module is used to extract context information based on the location information of the error code. The context information includes at least one of the error test case, error description, or error content. The module then uses a prompt input language model built based on the context information to perform reasoning to obtain a first repair code. The first repair code is obtained by the language model repairing the error code in the test code. 根据权利要求9所述的代码开发平台,其特征在于,所述代码开发平台还包括反馈模块:The code development platform according to claim 9, characterized in that the code development platform further includes a feedback module: 所述运行模块,还用于执行所述第一修复代码或者使用所述第一修复代码修复的所述测试代码;The running module is also used to execute the first repair code or the test code repaired using the first repair code; 所述反馈模块,用于当执行不通过,向所述用户呈现所述第一修复代码,接收所述用户对所述第一修复代码的反馈,获得更新后的所述第一修复代码。The feedback module is used to present the first repair code to the user when the execution fails, receive feedback from the user on the first repair code, and obtain the updated first repair code. 根据权利要求8或9所述的代码开发平台,其特征在于,所述代码开发平台还包括:The code development platform according to claim 8 or 9, characterized in that the code development platform further includes: 模板匹配修复模块,用于确定所述错误代码的错误类型,根据所述错误类型对应的修复模板对所述错误代码进行修复,获得第二修复代码;The template matching and repair module is used to determine the error type of the error code, and repair the error code according to the repair template corresponding to the error type to obtain a second repair code; 所述模型修复模块具体用于:The model repair module is specifically used for: 当所述第二修复代码修复失败,根据所述错误代码的位置信息,提取上下文信息。If the second repair code fails to repair, the context information is extracted based on the location information of the error code. 根据权利要求11所述的代码开发平台,其特征在于,所述错误代码的错误类型包括断言失败;The code development platform according to claim 11 is characterized in that the error type of the error code includes assertion failure; 所述模板匹配修复模块具体用于:The template matching and repair module is specifically used for: 确定所述错误代码中错误断言的断言类型;Determine the assertion type of the error assertion in the error code; 当所述断言类型为相等类型,从所述错误代码中提取所述错误断言的预期值,从测试报告中提取所述错误断言的实际值;When the assertion type is an equality type, extract the expected value of the error assertion from the error code and extract the actual value of the error assertion from the test report; 根据所述断言类型对应的断言修复模板,将所述错误断言的断言参数中的所述预期值替换为所述实际值,获得第二修复代码。Based on the assertion repair template corresponding to the assertion type, the expected value in the assertion parameter of the erroneous assertion is replaced with the actual value to obtain the second repair code. 根据权利要求12所述的代码开发平台,其特征在于,所述模板匹配修复模块还用于:According to claim 12, the code development platform is characterized in that the template matching and repair module is further used for: 当所述断言类型为布尔类型,根据所述错误断言中的断言参数以及所述错误断言使用的第一断言修复模板对应的第二断言修复模板,生成第二修复代码,所述第二断言修复模板的布尔逻辑与所述第一断言修复模板的布尔逻辑相反。When the assertion type is Boolean, a second repair code is generated based on the assertion parameters in the error assertion and the second assertion repair template corresponding to the first assertion repair template used by the error assertion. The Boolean logic of the second assertion repair template is the opposite of the Boolean logic of the first assertion repair template. 根据权利要求11所述的代码开发平台,其特征在于,所述错误代码的错误类型包括异常,所述第二修复代码包括所述异常对应的异常处理代码块;According to the code development platform of claim 11, the error type of the error code includes an exception, and the second repair code includes an exception handling code block corresponding to the exception; 所述模板匹配修复模块具体用于:The template matching and repair module is specifically used for: 从所述异常的堆栈追踪信息中确定异常类型;Determine the exception type from the stack trace information of the exception; 将所述异常类型填充到异常修复模板,获得所述异常处理代码块。Fill the exception type into the exception repair template to obtain the exception handling code block. 根据权利要求11所述的代码开发平台,其特征在于,所述代码开发平台还包括:The code development platform according to claim 11, characterized in that the code development platform further includes: 编译模块,用于编译所述测试代码,获得所述测试代码的编译信息,所述编译信息包括编译器对所述测试代码进行编译输出的错误日志,所述错误日志记录有所述错误代码的错误类型;A compilation module is used to compile the test code and obtain compilation information of the test code. The compilation information includes error logs output by the compiler when compiling the test code, and the error logs record the error types of the error codes. 当所述错误代码的错误类型包括缺失类引用,所述第二修复代码包括导入语句;When the error code includes a missing class reference, the second repair code includes an import statement; 所述模板匹配修复模块具体用于:The template matching and repair module is specifically used for: 确定缺失的类名;Determine the missing class name; 基于项目依赖库、开发工具库或者三方库,构建符号索引,所述符号索引包括可访问类的完全限定名;Based on project dependency libraries, development tool libraries, or third-party libraries, construct a symbol index, which includes the fully qualified names of accessible classes; 将所述缺失的类名和所述符号索引进行匹配,获得所述缺失的类名对应的完全限定名;The missing class name is matched with the symbol index to obtain the fully qualified name corresponding to the missing class name; 将所述完全限定名插入导包修复模板,获得所述导入语句。Insert the fully qualified name into the import package repair template to obtain the import statement. 根据权利要求9至15任一项所述的代码开发平台,其特征在于,所述模型修复模块还用于:The code development platform according to any one of claims 9 to 15, wherein the model repair module is further configured to: 当所述第一修复代码修复失败,针对所述测试代码重新执行代码修复,直至所述测试代码被修复成功或者重试次数达到目标值。If the first repair code fails to repair, the code repair is re-executed for the test code until the test code is successfully repaired or the number of retries reaches the target value. 一种计算设备集群,其特征在于,所述计算设备集群包括至少一台计算设备,所述至少一台计算设备包括至少一个处理器和至少一个存储器,所述至少一个存储器中存储有计算机可读指令;所述至少一个处理器执行所述计算机可读指令,以使得所述计算设备集群执行如权利要求1至8中任一项所述的代码生成方法。A computing device cluster, characterized in that the computing device cluster includes at least one computing device, the at least one computing device includes at least one processor and at least one memory, the at least one memory stores computer-readable instructions; the at least one processor executes the computer-readable instructions to cause the computing device cluster to perform the code generation method as described in any one of claims 1 to 8. 一种计算机可读存储介质,其特征在于,包括计算机可读指令;所述计算机可读指令用于实现权利要求1至8任一项所述的代码生成方法。A computer-readable storage medium, characterized in that it includes computer-readable instructions; the computer-readable instructions are used to implement the code generation method according to any one of claims 1 to 8. 一种计算机程序产品,其特征在于,包括计算机可读指令;所述计算机可读指令用于实现权利要求1至8任一项所述的代码生成方法。A computer program product, characterized in that it includes computer-readable instructions; the computer-readable instructions are used to implement the code generation method according to any one of claims 1 to 8.
PCT/CN2024/137807 2024-05-29 2024-12-09 Test code repairing method and related device Pending WO2025246269A1 (en)

Applications Claiming Priority (4)

Application Number Priority Date Filing Date Title
CN202410683284.2 2024-05-29
CN202410683284 2024-05-29
CN202410961426.7 2024-07-17
CN202410961426.7A CN121070314A (en) 2024-05-29 2024-07-17 A test code repair method and related equipment

Publications (1)

Publication Number Publication Date
WO2025246269A1 true WO2025246269A1 (en) 2025-12-04

Family

ID=97851600

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2024/137807 Pending WO2025246269A1 (en) 2024-05-29 2024-12-09 Test code repairing method and related device

Country Status (2)

Country Link
CN (1) CN121070314A (en)
WO (1) WO2025246269A1 (en)

Also Published As

Publication number Publication date
CN121070314A (en) 2025-12-05

Similar Documents

Publication Publication Date Title
CN117009231B (en) Highly reliable unit test automatic generation method and device based on conversational large language model
US10552301B2 (en) Completing functional testing
Leotta et al. Pesto: Automated migration of DOM‐based Web tests towards the visual approach
US9898387B2 (en) Development tools for logging and analyzing software bugs
US10409700B2 (en) Flexible configuration and control of a testing system
Soltani et al. A guided genetic algorithm for automated crash reproduction
US7320114B1 (en) Method and system for verification of soft error handling with application to CMT processors
US10489274B2 (en) Using emulation to disassociate verification from stimulus in functional test
US20070011669A1 (en) Software migration
US9141351B2 (en) Indicators for resources with idempotent close methods in software programs
Pan et al. Aster: Natural and multi-language unit test generation with llms
CN108459961A (en) The method, client and server of examination are resurveyed after a kind of failure of testing case
CN113918465A (en) Compatibility testing method, apparatus, electronic device and readable storage medium
CN112035367B (en) Method and system for checking workflow correctness of big data platform
US11132286B1 (en) Dynamic reordering of test case execution
Gotovos et al. Test-driven development of concurrent programs using concuerror
US11327723B1 (en) Development environment integrated with failure detection system
CN113626307B (en) Data verification method and device based on K8S container platform
US10481969B2 (en) Configurable system wide tests
Jarmusch et al. Analysis of validating and verifying openacc compilers 3.0 and above
US20130298105A1 (en) Indicators for resources with close methods that do not complete erroneously in software programs
US20250245487A1 (en) Execution-based feedback-enhanced large language model for test generation
WO2025246269A1 (en) Test code repairing method and related device
US11321218B1 (en) Automated generation of source code models from machine code for code analysis
CN112256554A (en) Method and equipment for testing based on scene test case