Unit test code generation method based on large language model and related equipment
By automatically generating unit test code using a large language model and then automatically compiling and running it, the problems of low unit test code coverage and high maintenance costs are solved, achieving efficient unit test code generation and maintenance.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- TONGYI YUNQI (HANGZHOU) INFORMATION TECHNOLOGY CO LTD
- Filing Date
- 2024-12-19
- Publication Date
- 2026-06-23
Smart Images

Figure CN122261978A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of software development technology, and in particular to a method and related equipment for generating unit test code based on a large language model. Background Technology
[0002] Unit testing is a testing method that verifies whether the smallest testable unit of software (such as a function) works as expected. It features isolation, automation, fine-grainedness, and rapid feedback, improving code quality, supporting refactoring, serving as documentation, and facilitating rapid debugging. During software development, unit testing ensures the quality of the source code developed by developers. In practice, developers often write unit test code manually. However, manually written unit test code often has low test coverage; it requires a significant investment of time and effort; and as the source code is continuously updated, the unit test code also needs frequent modification and maintenance, resulting in high maintenance costs. Summary of the Invention
[0003] This application provides a method and related equipment for generating unit test code based on a large language model, which can improve the test coverage of unit test code, reduce the time and effort required to write unit test code, and reduce the maintenance cost of unit test code.
[0004] This application provides a method for generating unit test code based on a large language model, comprising: obtaining the code file under test in the current software project and obtaining multiple target project dependency information required to generate unit test code, wherein the multiple target project dependency information includes at least the identifier of the target simulation framework and the identifier of the target testing framework; analyzing the code file under test and the multiple target project dependency information by calling the large language model through a unit test agent to obtain analysis results, the analysis results including a set of functions under test and an execution plan, and generating unit test code corresponding to each test function in different test scenarios according to the execution plan based on the target simulation framework and the target testing framework; wherein the set of functions under test includes multiple functions under test extracted from the code file under test; the execution plan is used to instruct the sequential generation of unit test code corresponding to each function under test based on the target simulation framework and the target testing framework; compiling the unit test code corresponding to each test function in different test scenarios by calling the compiler through the unit test agent, and calling the build tool to run the compiled unit test code to obtain the unit test code of each test function running successfully in different test scenarios.
[0005] This application provides an electronic device, including: a memory and a processor; the memory for storing a computer program; and the processor coupled to the memory for executing the computer program to perform steps in a unit test code generation method based on a large language model.
[0006] This application provides a computer-readable storage medium storing a computer program, which, when executed by a processor, enables the processor to implement the steps in a unit test code generation method based on a large language model.
[0007] This application provides a computer program product, including a computer program / instructions, which, when executed by a processor, enable the processor to implement the steps in a unit test code generation method based on a large language model.
[0008] In this embodiment, a unit test agent calls a large language model to generate unit test code for multiple test functions in multiple different test scenarios. The unit test agent then calls a compiler to automatically compile the unit test code generated by the large language model, and finally calls a build tool to automatically run the compiled unit test code. This achieves automatic generation, compilation, and execution of unit test code, enabling batch generation of unit test code covering various diverse test scenarios. This improves test coverage, increases the success rate of obtaining successfully executed unit test code, enhances the accuracy and usability of unit test code, significantly reduces the time and maintenance costs for developers in unit test scenarios, and improves the development efficiency and code quality of unit test code. Attached Figure Description
[0009] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings:
[0010] Figure 1 A schematic diagram illustrating an application scenario provided in an embodiment of this application;
[0011] Figure 2 A flowchart illustrating a unit test code generation method based on a large language model is provided in this application embodiment;
[0012] Figures 3 to 8 Each of the embodiments of this application provides an interface diagram;
[0013] Figure 9 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0014] To make the objectives, technical solutions, and advantages of this application clearer, the technical solutions of this application will be clearly and completely described below in conjunction with specific embodiments and corresponding drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0015] In the embodiments of this application, "at least one" refers to one or more, and "more than one" refers to two or more. "And / or" describes the access relationship between associated objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone, where A and B can be singular or plural. In the textual description of this application, the character " / " generally indicates that the preceding and following associated objects have an "or" relationship. Furthermore, in the embodiments of this application, "first," "second," "third," etc., are only used to distinguish the content of different objects and have no other special meaning.
[0016] The following is an explanation of some terms used in this application:
[0017] AI Agent: A software or hardware entity that has the ability to autonomously perceive its environment, make decisions, and execute actions, with the aim of completing specific tasks or achieving goals in the simulated or real world.
[0018] Compiler (compiling program): A software program that translates a source program (high-level language) into a target program.
[0019] Build tool: A type of automated software that assists in the execution of code.
[0020] Large Language Models (LLMs): LLMs are typically based on deep learning architectures, especially the Transformer architecture. They learn the complex structures and rich contextual information of language through pre-training on massive amounts of text data. LLMs can handle various natural language tasks, such as text classification, question answering, and dialogue, and are an important pathway to artificial intelligence. The Transformer module is a neural network structure based on a self-attention mechanism, which significantly improves model performance through parallel processing and self-attention.
[0021] A software project typically refers to a collection of related code files, library files, and resource files that together constitute a part of a complete software application or system. A software project usually includes: a source code directory, a library file directory, a resource file directory, and a test code directory. The source code directory stores all source code files. The library file directory stores third-party libraries that the project depends on. The resource file directory stores non-code resources such as configuration files and images. The test code directory stores test code files.
[0022] A mocking framework is a tool used to simulate the behavior of external dependencies or complex objects during testing. It allows developers to create "mock objects" that can replace real objects or services, thereby isolating the code under test and ensuring the independence and reliability of the tests.
[0023] A testing framework is a set of tools and libraries for writing, executing, and managing test code. It provides developers with a structured environment that makes writing, running, and maintaining tests simpler and more efficient. Testing frameworks typically include features such as automated test execution, test result reporting, and test coverage analysis, helping development teams ensure code quality, stability, and maintainability.
[0024] Unit testing is a testing method that verifies whether the smallest testable unit of software (such as a function) works as expected. It features isolation, automation, fine-grainedness, and rapid feedback, improving code quality, supporting refactoring, serving as documentation, and facilitating rapid debugging. During software development, unit testing ensures the quality of the source code developed by developers. In practice, developers often write unit test code manually. However, manually written unit test code often has low test coverage; it requires a significant investment of time and effort; and as the source code is continuously updated, the unit test code also needs frequent modification and maintenance, resulting in high maintenance costs.
[0025] Figure 1 This is a schematic diagram illustrating an application scenario provided by an embodiment of this application. See also... Figure 1Developers open code editors on various terminal devices such as desktop computers, laptops, or tablets, and work on code using input devices such as keyboards and mice. During code development, developers often utilize intelligent programming assistance tools installed on their devices to aid their work. In intelligent coding scenarios, intelligent programming assistance tools based on large language models can provide capabilities such as real-time line-level / function-level code continuation, natural language code generation, unit test generation, code optimization, comment generation, code explanation, and exception handling, helping developers code efficiently and fluently.
[0026] In practical applications, unit test agents can be deployed in intelligent programming aids. A unit test agent can be understood as an agent with unit testing capabilities. It can invoke a large language model to perform tasks such as code generation and optimization, call a compiler to compile code, and invoke build tools to run code. Of course, unit test agents can also perform many more tasks.
[0027] Specifically, by using a unit test agent to invoke a large language model, developers can improve efficiency in unit testing scenarios. This eliminates the need for developers to manually write unit test code; the large language model automatically generates unit test code covering diverse scenarios. The unit test agent then calls the compiler to automate the compilation of the unit test code, invokes build tools to automate code execution, and uses the large language model for code optimization. It also provides interactive interfaces for execution plan confirmation, automatic code adoption, and code review, enabling developers to leverage AI (Artificial Intelligence) capabilities to efficiently and smoothly generate unit test code, improving development efficiency and code quality. This is applicable to software engineering of all sizes, and has significant application value, especially in the development of large-scale, complex systems.
[0028] It should be noted that, Figure 1 The application scenario shown is merely an exemplary scenario, and the embodiments of this application do not limit the application scenarios. The embodiments of this application do not... Figure 1 The included equipment is not limited, nor is it restricted. Figure 1 The positional relationships between the devices are defined.
[0029] The technical solutions of this application and how they solve the aforementioned technical problems are described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The technical solutions provided by each embodiment of this application are described in detail below with reference to the accompanying drawings.
[0030] Figure 2 A flowchart illustrating a unit test code generation method based on a large language model is provided as an embodiment of this application. See also... Figure 2 The method may include the following steps:
[0031] 201. Obtain the code file under test in the current software project and obtain the dependency information of multiple target projects required to generate unit test code. The dependency information of multiple target projects includes at least the identifier of the target simulation framework and the identifier of the target test framework.
[0032] Specifically, the current software project refers to any existing software project, and the code file under test can be any code file within the current software project that requires unit testing. The code file under test includes, but is not limited to, source code files and code snippet files. Source code files are complete code files containing the core logic and functionality of the software project. Source code files are typically written by developers and include the project's technical logic, algorithm implementation, class definitions, function definitions, etc. Code snippet files are files containing a small number of code snippets. A code snippet file is not necessarily a complete, compileable program, but rather a code snippet focused on a specific function or problem. A code snippet file can include a few lines of code, a few functions, or a portion of a class.
[0033] In practical applications, there can be one or more code files under test. Understandably, generating corresponding unit test code in batches for multiple code files under test improves unit testing efficiency by processing test requirements for multiple files in batches.
[0034] In practical applications, users can select the code file to be tested from the current software project as needed. The current software project may also contain code change information, which records the changed code. Users can select the changed code file as the code file to be tested. This ensures that unit tests can still be performed on the changed code file after code changes, thereby improving code quality and project stability.
[0035] Based on the above, the implementation method for obtaining the code file under test in the current software project is as follows: The system receives unit test code generation requirement information input by the user for the current software project. This requirement information indicates the identifier of the code file under test or indicates the generation of corresponding unit test code for code changes. If the requirement information indicates the identifier of the code file under test, the system searches for the code file under test in the current software project. If the requirement information indicates the generation of corresponding unit test code for code changes, the system searches for the code changes in the current software project and uses the modified code file involved in the code changes as the code file under test.
[0036] In practical applications, an interactive interface can be provided to users, allowing them to input unit test code for the current software project to generate requirement information. This interface could be, for example, an AI dialogue interface where users interact with a large language model. See also... Figure 3 The AI dialogue interface can display an information input area, but it is not limited to this. The information input area is primarily used to receive user input; it typically appears as an input box where users can enter various information such as plain text, images, and links. The information input area can include a prompt input area and a context introduction area. The prompt input area can be understood as an input box specifically for entering prompts; users can enter various input content such as natural language text (also called natural language text), images, and links in this area without restriction. For example, the unit test code generation requirement information entered in the prompt input area might be "Use JUnit5 testing to generate unit test code corresponding to OrderServicelmpl.java". JUnit5 testing is a testing framework, and OrderServicelmpl.java is the code file being tested.
[0037] The context introduction area can be understood as an input box specifically for entering contextual information. Users can enter the contextual information needed for dialogue interaction with the large language model in the context introduction area. The context introduction area allows users to select one or more files at a time as the context for dialogue interaction, reducing the number of user operations and improving the user experience. In practical applications, there are no restrictions on how the file selection operation is triggered in the context introduction area. For example, users can click, double-click, or long-press the context introduction area to trigger the file selection operation; or, see [link to relevant documentation]. Figure 3 An add control is displayed in the context introduction area to guide the user to use the add control to initiate a file selection operation.
[0038] In practical applications, upon receiving a file selection operation triggered in the context introduction area, the system can retrieve available files based on pre-specified folder paths, storage paths, etc., and display the file identifiers of the available files for the user to select. However, it is not limited to this. In practical applications, the types of available files include, but are not limited to, code files, image files, or code change content from the current software engineering project.
[0039] In practical applications, upon receiving a file selection operation triggered in the context introduction area, a context selection panel can pop up in the interactive interface. This panel displays multiple optional file identifiers for the user to choose from, such as codebase, file, codeChanges, image, OrderServicelmpl.java, OrderService.java, and FileUtil.java. The context selection panel can take various forms, including but not limited to: an interface, a window, or a card. It can also include an input box where the user enters a file identifier. The system then retrieves the file identifier and displays the corresponding file identifier label in the context introduction area. This file identifier label, or tag-style file identifier, enriches the file selection methods.
[0040] In practical applications, the unit test code generation requirement information input by the user for the current software project describes the request information of this dialogue interaction. The unit test code generation requirement information can indicate the identifier of the code file being tested, or it can indicate that the unit test is related to the code changes (codeChanges), that is, to perform unit tests on the changed code file. The changed code file can refer to the file obtained by modifying the source code file. The changed code file includes, but is not limited to, new code added to the source code file, code deleted from the source code file, or modified code in the source code file.
[0041] In some optional embodiments, to ensure that the large language model better understands user needs and improves the reliability of the generated unit test code, the unit test code generation requirement information may further include: an identifier of the context information of the code file under test. For example, see... Figure 3 In the pop-up context selection panel, the user selects the context information for the code file being tested, using the codebase file and the OrderServicelmpl.java file as context information. After clicking the send button in the prompt input area, the system receives the unit test code generation requirements information entered in the prompt input area and the context information entered in the context introduction area.
[0042] In this embodiment, in addition to obtaining the code file under test in the current software project, it is also necessary to obtain multiple target project dependency information required to generate unit test code. Among them, the multiple target project dependency information includes at least the identifier of the target simulation framework and the identifier of the target test framework.
[0043] In practical applications, a current software project may depend on a software runtime environment, various versions of programming languages, multiple mocking frameworks, or multiple testing frameworks, etc. The target mocking framework can be any of the multiple mocking frameworks, and the target testing framework can be any of the multiple testing frameworks. In practical applications, there are no restrictions on the methods used to obtain the multiple target project dependency information required to generate unit test code.
[0044] Optionally, to support users in flexibly selecting project dependency information, the implementation method for obtaining multiple target project dependency information required to generate unit test code is as follows: obtain a list of project dependency information for the current software project and display the list on the project dependency information confirmation interface. The project dependency information list includes multiple project dependency information options, each of which is used to select one type of project dependency information; in response to the user's selection operation triggered for the project dependency information option, select one project dependency information from the multiple optional project dependency information corresponding to the project dependency information option; in response to the user's confirmation operation for the selected multiple project dependency information triggered on the project dependency information confirmation interface, use the selected multiple project dependency information as multiple target project dependency information required to generate unit test code.
[0045] by Figure 4 For example, the AI dialogue interaction interface displays a project dependency information confirmation interface. This interface shows a list of project dependencies, including options for environment setup tools, programming language versions, mocking frameworks, and testing frameworks. The environment setup tool option displays that the current software project's environment setup tool is Maven. Maven is a powerful project management and build tool, primarily used for building Java projects, managing dependencies, and generating documentation. The programming language version option allows users to select the desired programming language version. Each option is associated with one or more programming language versions for the user to choose from; for example, the user selects Java 9.2.2. The mocking framework option allows users to select the desired mocking framework. Each option is associated with one or more mocking frameworks for the user to choose from; for example, the user selects the mocking framework Mockito 5.7.0. The testing framework option allows users to select the desired testing framework. Each option is associated with one or more testing frameworks for the user to choose from; for example, the user selects the testing framework JUnit 5. When the user clicks... Figure 4 The confirmation button in the settings will confirm the selected project dependency information as the required project dependency information.
[0046] 202. The unit test agent calls the large language model to analyze the code file under test and the dependency information of multiple target projects, and obtains the analysis results. The analysis results include the set of functions under test and the execution plan, as well as the unit test code corresponding to each test function under different test scenarios generated according to the execution plan based on the target simulation framework and the target test framework. Among them, the set of functions under test includes multiple functions under test extracted from the code file under test; the execution plan is used to instruct the sequential generation of the unit test code corresponding to each function under test based on the target simulation framework and the target test framework.
[0047] In practical applications, the unit testing agent inputs the code file under test and dependency information of multiple target projects into a large language model. The large language model performs intent understanding and requirement analysis, extracts multiple test functions from the code file under test, which can be any function in the code file under test, and the multiple test functions form a set of test functions. The large language model can also plan an execution plan, which can instruct the generation of unit test code corresponding to each test function in sequence based on the target simulation framework and the target testing framework, but is not limited to this.
[0048] Further optionally, to improve the quality of unit test code generation by the large language model, if the unit test code generation requirement information also includes: the identifier of the context information of the code file under test; then, based on the identifier of the context information of the code file under test, the context information of the code file under test is retrieved in the current software project; correspondingly, the implementation method of calling the large language model through the unit test agent to analyze the code file under test and the dependency information of multiple target projects to obtain the analysis results is as follows: the large language model is called through the unit test agent to analyze the code file under test, the context information, and the dependency information of multiple target projects to obtain the analysis results.
[0049] In practical applications, large language models can directly generate corresponding unit test code for the functions under test in the set of functions under test. Optionally, to better meet user needs and improve the flexibility of unit test code generation, it also supports users managing the set of functions under test on demand. In practice, a confirmation interface for the functions under test can also be displayed to users to allow them to manage the set of functions under test as needed.
[0050] Based on the above, before generating the unit test code corresponding to each test function in different test scenarios according to the execution plan based on the target simulation framework and the target test framework, the above method may further include: displaying a confirmation interface for the function under test, which includes multiple test code file options, each test code file option being associated with multiple test functions in the corresponding test code file; responding to the user's operation on any test code file option, displaying multiple test functions in the test code file corresponding to the test code file option; and responding to the user's confirmation operation on the test function confirmation interface, executing the step of generating the unit test code corresponding to each test function in different test scenarios according to the execution plan based on the target simulation framework and the target test framework. In practical applications, before responding to the user's confirmation operation on the test function confirmation interface, one or more test functions from the multiple test functions included in the test code file can also be deleted from the test function set in response to a user-triggered deletion operation. Optionally, to allow users to intuitively know how many test code files and how many test functions there are, summary data of the test code files and summary data of the test functions can be displayed on the test function confirmation interface.
[0051] by Figure 5 For example, the AI dialogue interaction interface displays a confirmation interface for the functions under test. This interface shows three code files under test, containing a total of 20 functions under test. The confirmation interface displays options for multiple code files under test, such as OrderServicelmpl.java, OrderService.java, and FileUtil.java. When the user clicks the OrderService.java option, it displays multiple functions under test within that file. These functions are insertOrder(), updateOrder(), deleteOrder(), makePayment(), or getRelatedOrders(), each implementing a different function. In practical applications, operation controls can be provided within the code file options to expand and collapse the cards containing the multiple functions under test within those files. For example, Figure 5 In the code file under test, when the > control is displayed, clicking the > control expands a card containing multiple functions under test within the code file. After expanding the card containing multiple functions under test, the > control changes to a ∧ control. Clicking the ∧ control again collapses the card, thus exiting the display of multiple functions under test within the code file. In practical applications, users can delete functions under test as needed, such as... Figure 5In the test, when a function under test is deleted, a deletion instruction message can be displayed. After the user has selected all the functions under test, the user can click the confirmation control in the function confirmation interface to confirm the set of functions under test.
[0052] In this embodiment, the large language model is invoked to generate unit test code for each test function under different test scenarios based on the target simulation framework and the target test framework according to the execution plan. The test scenarios can be flexibly defined as needed. In practical applications, the large language model can generate unit test code covering a wide variety of test scenarios, thereby improving test coverage.
[0053] 203. The unit test agent calls the compiler to compile the unit test code for each test function under different test scenarios, and calls the build tool to run the compiled unit test code to obtain the unit test code for each test function that runs successfully under different test scenarios.
[0054] In practical applications, after the large language model generates unit test code for each test function under different test scenarios, the unit test agent can call the compiler to automatically compile the unit test code for each test function under different test scenarios. The unit test agent can also call the build tool to automatically run the compiled unit test code, resulting in successfully executed unit test code for each test function under different test scenarios. In essence, unit test code is code used to perform unit tests on the corresponding function under test.
[0055] In practical applications, unit test code may fail to compile or run. Unit test code that compiles successfully but fails to run can be addressed by having a unit test agent call the large language model to optimize the code based on relevant error messages. The unit test agent then compiles and runs the optimized code until successfully running unit test code is obtained. Essentially, the unit test agent compiles and runs the optimized code, calls the compiler to automate the compilation, and calls the build tools to automate the execution of the compiled and optimized code. This provides a solution for automatically compiling, running, and repairing (i.e., optimizing) unit test code, improving the success rate of automatically generating successfully running unit test code. Relevant error messages help the large language model pinpoint the reasons for compilation or runtime failures, thus better guiding the model in code repair.
[0056] In practical applications, multiple rounds of compilation, execution, and repair can be performed to improve the success rate of automatically generating and running unit test code, enhance the accuracy and usability of unit test code, significantly reduce the time developers spend in unit testing scenarios, and improve development efficiency.
[0057] The technical solution provided in this application's embodiments generates unit test code for multiple test functions in various test scenarios by calling a large language model in batches through a unit test agent. The unit test agent then calls a compiler to automatically compile the unit test code generated by the large language model, and finally calls a build tool to automatically run the compiled unit test code. This achieves automatic generation, compilation, and execution of unit test code, enabling batch generation of unit test code covering diverse test scenarios. This improves test coverage, increases the success rate of obtaining successfully running unit test code, enhances the accuracy and usability of unit test code, significantly reduces the time and maintenance costs for developers in unit testing scenarios, and improves the development efficiency and code quality of unit test code.
[0058] Understandably, the system allows users to select multiple code files and modify code content to generate unit test code in batches, significantly improving the efficiency of unit test code generation when multiple functions have changed. It also allows users to intervene in project dependency information and the selection of functions under test, ensuring that the large language model accurately understands user requirements.
[0059] In some optional embodiments, users are also allowed to view the unit test code generation progress interface, which allows them to understand the generation status of unit test code in real time, enhancing the transparency of the development process and improving development efficiency and user experience.
[0060] Based on the above, the method further includes: displaying a unit test code generation progress interface, which includes the following information:
[0061] First progress information indicates the number of functions under test in multiple test code files where unit test code has been generated.
[0062] The second progress information is used to indicate the status summary information of all unit test codes under multiple test code files. Different statuses of unit test codes correspond to different styles of icons. The number of unit test codes in the corresponding status is displayed around each icon to indicate the status summary information of the unit test codes in the corresponding status. The status summary information of unit test codes in different statuses includes at least two of the following: the number of unit test codes that ran successfully, the number of unit test codes that failed to run, or the number of unit test codes that failed to compile.
[0063] The third progress information for each code file under test indicates the number of functions under test in which unit test code has been generated in at least one function under test corresponding to that code file under test.
[0064] Optionally, to meet more diverse user needs, the unit test code generation progress interface also includes: card operation controls for each code file under test; when the card corresponding to the code file under test is in a collapsed state, the card operation controls are used to trigger the display of the card corresponding to the code file under test; when the card corresponding to the code file under test is in an expanded state, the card operation controls are used to trigger the collapse of the card corresponding to the code file under test.
[0065] The card corresponding to the code file under test displays the fourth progress information for each function under test within the code file under test. The fourth progress information for each function under test is used to indicate the status of the unit test code under the function under test. The status of the unit test code under the function under test includes at least two of the following: generating, running, fixing, or generated. If the status of the unit test code under the function under test is generated, the status summary information of the unit test code under the function under test in different states is displayed.
[0066] For example, see Figure 6 The AI-powered interactive interface displays the progress of unit test code generation. The first progress message, "10 / 20 functions under test completed," indicates that unit test code has been generated for 10 out of 20 functions under test. The icon represents the unit test code that ran successfully. The icon represents unit test code that failed to run. The icon represents the unit test code that failed to compile; by overlaying the icon and the number, the number of unit test codes that ran successfully (15), the number of unit test codes that failed to run (3), or the number of unit test codes that failed to compile (1) can be displayed.
[0067] See Figure 6 In the OrderServicelmpl.java test file, all 9 tested functions have completed the execution or compilation of their corresponding unit test code; in the OrderService.java test file, only 1 of the 5 tested functions has completed the execution or compilation of its corresponding unit test code; and in the FileUtil.java test file, none of the 6 tested functions have completed the execution or compilation of their corresponding unit test code.
[0068] See Figure 6This displays card-based operation controls for each code file under test. Clicking the > card control in OrderService.java displays cards representing the five functions under test within OrderService.java, and the > card control transforms into a ∨ card control. Clicking the ∨ card control collapses the cards in OrderService.java, and the ∨ card control transforms back into the > card control. In essence, the cards corresponding to the > card control are collapsed, while the cards corresponding to the ∨ card control are expanded.
[0069] See Figure 6 After expanding the cards containing the five tested functions in OrderService.java, the status of the tested functions is as follows: insertOrder() is completed, updateOrder() is compiling, deleteOrder() is running, and makePayment() is fixing or getRelatedOrders() is generating. The status of insertOrder() being completed indicates that all unit test code for insertOrder() has been executed or compiled. Specifically, 4 unit test codes for insertOrder() ran successfully, 1 failed to run, and 0 failed to compile. The unit test code for updateOrder() has not yet been compiled and is currently in the compiling stage; the unit test code for deleteOrder() has not yet been executed and is currently running; the unit test code for makePayment() has been executed or compiled but is currently in the fixing stage; and getRelatedOrders() has not yet generated all unit test code and is currently generating.
[0070] In some optional embodiments, users are also allowed to view the unit test code viewing interface, which allows them to understand the details of the unit test code in real time, enhancing the transparency of the development process and improving development efficiency and user experience.
[0071] Based on the above, the method further includes: displaying a unit test code viewing interface, which includes a list of test code files, each containing file identifiers for multiple test code files; expanding the test code file cards in response to a user's action to expand the cards; wherein the test code file cards display a first entry control and a first statistical result for a first unit test code list, the first unit test code list including successfully executed or failed unit test codes, the first statistical result indicating the number of unit test codes in the first unit test code list, and the unit test codes in the first unit test code list having been added to the test code files; displaying the first unit test code list in response to a user's action to trigger the first entry control, the first unit test code list including multiple unit test codes and their corresponding scenario description information; and adding the test code files containing the added unit test codes to the current software project in response to a user's acceptance action in the unit test code viewing interface. The scenario description information of the unit test codes describes relevant information about the test scenarios of the unit test codes.
[0072] Further optionally, in order to meet the diverse needs of users and improve the reliability and accuracy of unit test code generation, before responding to the user's accept operation triggered in the unit test code viewing interface, the above method further includes: in response to the user's deselection operation of unit test code in the first unit test code list, deleting the selected unit test code from the test code file; or, in response to the user's manual repair operation of unit test code that failed to run in the first unit test code list, repairing the unit test code that failed to run.
[0073] Optionally, to meet diverse user needs and improve the reliability and accuracy of unit test code generation, the test code file card displays a second entry control for a second unit test code list and a second statistical result. The second unit test code list includes unit test codes that failed to compile, and the second statistical result indicates the number of unit test codes in the second unit test code list. The unit test codes in the second unit test code list have not yet been added to the test code file. In response to the user triggering the second entry control, the second unit test code list is displayed, which includes multiple unit test codes and their corresponding scenario descriptions. In response to the user's manual repair operation on the unit test codes that failed to compile in the second unit test code list, the unit test codes that failed to compile are repaired. And in response to the operation of adding the repaired unit test codes that failed to compile to the test code file, the repaired unit test codes are added to the test code file.
[0074] Optionally, to meet diverse user needs, the unit test code viewing interface also displays the number of test code files and the total number of unit test codes from all tested code files.
[0075] Specifically, a new test code file is created for each code file under test. This test code file stores the unit test code selected from the unit test code of the corresponding function in the code file under test. In practice, successfully executed or unexecuted unit test code can be automatically added to the test code file. Unexecuted unit test code refers to unit test code that compiles successfully but fails to run. Whether or not to add unexecuted unit test code to the test code file can be decided manually.
[0076] For example, see Figure 7 The unit test code viewing interface displays "Involves 3 test code files, with a total of 50 unit test codes." This means the 3 test code files are: OrderServicelmplTest.java (corresponding to OrderServicelmpl.java), OrderServiceTest.java (corresponding to OrderService.java), and FileUtilTest.java (corresponding to FileUtil.java). These 3 test files generate 50 unit test codes. Of these 50, 32 have been applied to their respective test code files; the remaining 18 require manual confirmation to determine if they need to be added. See also... Figure 7 Test code files that are fully selected include all unit test code corresponding to the test file; test code files that are partially selected include some unit test code corresponding to the test file; and test code files that are not selected have not yet had any unit test code added.
[0077] See Figure 7The OrderServiceTest.java test code file's file identifier is surrounded by a > card operation control (not shown). The OrderServiceTest.java test code file's card is initially collapsed. Clicking the > card operation control corresponding to OrderServiceTest.java displays the corresponding card, which transforms into a ∨ card operation control. The card displays the first entry control and first statistical result "20 unit test codes have been applied" for the first unit test code list, and the second entry control and second statistical result "5 unit test codes need confirmation" for the second unit test code list. The > control around the text "20 unit test codes have been applied" is the first entry control; the > control around the text "5 unit test codes need confirmation" is the second entry control. The first unit test code list corresponding to "20 unit test codes have been applied" is fully selected, indicating that the 20 unit test codes have been applied to the corresponding test code file; the second unit test code list corresponding to "5 unit test codes need confirmation" is unselected, indicating that the 5 unit test codes require manual confirmation and have not yet been added to the corresponding test code file.
[0078] When a user triggers the display of the first or second list of unit test code, for the selected unit test code, the user can trigger a deselection operation to change the selected unit test code to an unselected unit test code; conversely, for the unselected unit test code, the user can trigger a selection operation to change the unselected unit test code to a selected unit test code.
[0079] like Figure 7 The diagram shows the scenario descriptions for the selected `insertOrderTest()` unit test code and its successful execution status. It also shows the scenario descriptions for the selected `updateOrderTest()` unit test code and its failed execution status; the scenario descriptions for the unselected `deleteOrderTest()` unit test code and its compilation failure status; the scenario descriptions for the unselected `makePaymentTest()` unit test code and its compilation failure status; and the scenario descriptions for the unselected `getRelatedOrdersTest()` unit test code and its compilation failure status.
[0080] In practical applications, users can view the code content of any unit test and manually fix its contents. For example, they can manually fix unit test code that has failed to compile or run.
[0081] In practical applications, see Figure 7 After the user confirms the selected unit test code, they can click the accept control on the unit test code viewing interface to confirm the selected unit test code and add the test code file containing the selected unit test code to the current software project, thus meeting the user's code review requirements and adopting the required unit test code as needed.
[0082] See Figure 8 Users can also view the code changes in any test file. For test files with code changes, code difference comparison technology is used to compare the code changes and display them on the relevant interactive interface, so that users can easily view, revise, and make adoption decisions regarding code changes.
[0083] It should be noted that the execution subject of each step of the method provided in the above embodiments can be the same device, or the method can be executed by different devices. For example, the execution subject of steps 201 to 203 can be device A; or the execution subject of steps 201 and 202 can be device A, and the execution subject of step 203 can be device B; and so on.
[0084] Furthermore, in some of the processes described in the above embodiments and accompanying drawings, multiple operations appear in a specific order. However, it should be clearly understood that these operations may not be executed in the order they appear herein, or they may be executed in parallel. The operation numbers, such as 401, 402, etc., are merely used to distinguish different operations and do not represent any execution order. Additionally, these processes may include more or fewer operations, and these operations may be executed sequentially or in parallel. It should be noted that the descriptions such as "first" and "second" in this document are used to distinguish different messages, devices, modules, etc., and do not represent a sequential order, nor do they limit "first" and "second" to different types.
[0085] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use and processing of the relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and corresponding operation portals are provided for users to choose to authorize or refuse.
[0086] Figure 9 This is a schematic diagram of the structure of an electronic device provided for an exemplary embodiment of this application. For example... Figure 9 As shown, the electronic device includes: a memory 91 and a processor 92;
[0087] Memory 91 is used to store computer programs and can be configured to store various other data to support operation on the computing platform. Examples of this data include instructions for any application or method operating on the computing platform, contact data, phone book data, messages, pictures, videos, etc.
[0088] The memory 91 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random-access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk.
[0089] Processor 92, coupled to memory 91, executes a computer program in memory 91 to: obtain the code file under test in the current software project and obtain multiple target project dependency information required to generate unit test code, wherein the multiple target project dependency information includes at least the identifier of the target simulation framework and the identifier of the target test framework; analyze the code file under test and the multiple target project dependency information by calling a large language model through a unit test agent to obtain analysis results, including a set of functions under test and an execution plan, and generating unit test code corresponding to each test function under different test scenarios according to the execution plan based on the target simulation framework and the target test framework; wherein the set of functions under test includes multiple functions under test extracted from the code file under test; the execution plan is used to instruct the sequential generation of unit test code corresponding to each function under test based on the target simulation framework and the target test framework; compile the unit test code corresponding to each test function under different test scenarios by calling a compiler through a unit test agent, and call a build tool to run the compiled unit test code to obtain the unit test code of each test function running successfully under different test scenarios.
[0090] Optionally, the processor 92 is also used to: if there are unit test codes that fail to compile or fail to run, then use the unit test agent to call the large language model to repair the unit test codes that fail to compile or fail to run by combining the relevant error information of the unit test codes that fail to compile or fail to run; use the unit test agent to compile and run the repaired unit test codes until successfully running unit test codes are obtained.
[0091] Optionally, when processor 92 obtains the code file under test in the current software project, it is used to: receive unit test code generation requirement information input by the user for the current software project, the unit test code generation requirement information being used to indicate the identifier of the code file under test or to indicate the generation of corresponding unit test code for code changes; if the unit test code generation requirement information indicates the identifier of the code file under test, then the code file under test is retrieved in the current software project; if the unit test code generation requirement information indicates the generation of corresponding unit test code for code changes, then the code changes are retrieved in the current software project, and the modified code file involved in the code changes is taken as the code file under test.
[0092] Optionally, the unit test code generation requirement information also includes: an identifier of the context information of the code file under test; the processor 92 is also used to: retrieve the context information of the code file under test in the current software project based on the identifier of the context information of the code file under test; correspondingly, when the processor 92 calls the large language model through the unit test agent to analyze the code file under test and the dependency information of multiple target projects and obtains the analysis results, it is specifically used to: call the large language model through the unit test agent to analyze the code file under test, the context information and the dependency information of multiple target projects and obtain the analysis results.
[0093] Optionally, the number of code files to be tested can be multiple.
[0094] Optionally, when processor 92 obtains multiple target project dependency information required to generate unit test code, it specifically performs the following: obtains a list of project dependency information for the current software project and displays the list on a project dependency information confirmation interface. The project dependency information list includes multiple project dependency information options, each of which is used to select one type of project dependency information. In response to a user's selection operation triggered for a project dependency information option, it selects one project dependency information from the multiple optional project dependency information corresponding to the project dependency information option. In response to a user's confirmation operation on the project dependency information confirmation interface for the selected multiple project dependency information, it uses the selected multiple project dependency information as multiple target project dependency information required to generate unit test code.
[0095] Optionally, before generating the unit test code corresponding to each test function in different test scenarios based on the target simulation framework and the target test framework according to the execution plan, the processor 92 is further configured to: display a confirmation interface for the function under test, the confirmation interface for the function under test including multiple options for code files under test, each option for code files under test being associated with multiple functions under test in the corresponding code file under test; in response to the user's operation on any option for code files under test, display multiple functions under test in the code file under test corresponding to the option for code files under test; in response to a deletion operation triggered by the user, delete one or more functions under test from the set of functions under test included in the code file under test; in response to the user's confirmation operation on the confirmation interface for the function under test, execute the step of generating the unit test code corresponding to each test function in different test scenarios according to the execution plan based on the target simulation framework and the target test framework.
[0096] Optionally, the processor 92 is further configured to: display a unit test code generation progress interface, which includes the following information: first progress information, indicating the number of tested functions in multiple tested code files for which unit test code has been generated; second progress information, indicating the status summary information of all unit test codes in multiple tested code files, with different styles of icons corresponding to different statuses of unit test codes, and the number of unit test codes in the corresponding status displayed around each icon to indicate the status summary information of the unit test codes in the corresponding status, the status summary information of unit test codes in different statuses including at least two of the following: the number of unit test codes that ran successfully, the number of unit test codes that failed to run, or the number of unit test codes that failed to compile; and third progress information for each tested code file, indicating the number of tested functions in at least one tested function corresponding to the tested code file for which unit test code has been generated.
[0097] Optionally, the unit test code generation progress interface also includes: card operation controls corresponding to each code file under test; when the card corresponding to the code file under test is in a collapsed state, the card operation controls are used to trigger the display of the card corresponding to the code file under test; when the card corresponding to the code file under test is in an expanded state, the card operation controls are used to trigger the collapse of the card corresponding to the code file under test; the card corresponding to the code file under test displays the fourth progress information corresponding to each function under test in the code file under test, and the fourth progress information corresponding to the function under test is used to indicate the status of the unit test code under the function under test; the status of the unit test code under the function under test includes at least two of the following: generating, running, fixing, or generated; wherein, if the status of the unit test code under the function under test is generated, the status summary information of the unit test code under the function under test in different states is displayed.
[0098] Optionally, the processor 92 is further configured to: display a unit test code viewing interface, the unit test code viewing interface including a list of test code files, the test code file list including file identifiers of multiple test code files; expand the test code file cards in response to a user triggering an operation to expand the test code file cards; wherein, the test code file cards display a first entry control and a first statistical result for a first unit test code list, the first unit test code list including successfully run unit test code or failed run unit test code, the first statistical result indicating the number of unit test codes in the first unit test code list, and the unit test codes in the first unit test code list have been added to the test code file; display the first unit test code list in response to a user triggering an operation for the first entry control, the first unit test code list including multiple unit test codes and their corresponding scenario description information; and add the test code file with added unit test code to the current software project in response to an acceptance operation triggered by the user in the unit test code viewing interface.
[0099] Optionally, prior to the user's accept operation triggered in the unit test code viewing interface, the processor 92 is further configured to: delete the selected unit test code from the test code file in response to the user's deselection operation of the unit test code in the first unit test code list; or, in response to the user's manual repair operation of the unit test code that failed to run in the first unit test code list, repair the unit test code that failed to run.
[0100] Optionally, the card display in the test code file includes a second entry control and a second statistical result for the second unit test code list. The second unit test code list includes unit test codes that failed to compile, and the second statistical result indicates the number of unit test codes in the second unit test code list. The unit test codes in the second unit test code list have not yet been added to the test code file.
[0101] Processor 92 is also configured to: in response to a user triggering the second entry control, display a second unit test code list, the second unit test code list including multiple unit test codes and their corresponding scenario description information; in response to a user's manual repair operation on the unit test codes that failed to compile in the second unit test code list, repair the unit test codes that failed to compile; and in response to an operation to add the repaired unit test codes that failed to compile to the test code file, add the repaired unit test codes that failed to compile to the test code file.
[0102] Optionally, the unit test code viewing interface also displays the number of test code files and the total number of unit test codes from all the tested code files.
[0103] Optional, such as Figure 9 As shown, the electronic device also includes other components such as a communication component 93, a display 94, a power supply component 95, and an audio component 96. Figure 9 The diagram only shows some components and does not mean that the electronic device includes only these components. Figure 9 The components shown. Additionally... Figure 9 The components within the dashed box are optional, not mandatory, and their specific requirements depend on the product form of the electronic device. The electronic device in this embodiment can be a desktop computer, laptop computer, smartphone, or IoT (Internet of Things) device, or a server-side device such as a conventional server, cloud server, or server array. If the electronic device in this embodiment is a desktop computer, laptop computer, or smartphone, it may include... Figure 9 The components within the dashed box; if the electronic device in this embodiment is implemented as a conventional server, cloud server, or server array, etc., it may be omitted. Figure 9 The component within the dashed box.
[0104] For a detailed description of the implementation process of each action by the processor, please refer to the relevant descriptions in the foregoing method embodiments or device embodiments, which will not be repeated here.
[0105] Accordingly, embodiments of this application also provide a computer-readable storage medium storing a computer program, which, when executed, can perform the steps that can be executed by an electronic device in the above method embodiments.
[0106] Accordingly, this application also provides a computer program product, including a computer program / instructions, which, when executed by a processor, enables the processor to perform the steps that can be executed by an electronic device in the above method embodiments.
[0107] The aforementioned communication components are configured to facilitate wired or wireless communication between the device containing the communication components and other devices. The device containing the communication components can access wireless networks based on communication standards, such as WiFi (Wireless Fidelity), 2G (2nd Generation), 3G (3rd Generation), 4G (4th Generation) / LTE (long Term Evolution), 5G (5th Generation), or combinations thereof. In one exemplary embodiment, the communication components receive broadcast signals or broadcast-related information from an external broadcast management system via a broadcast channel. In one exemplary embodiment, the communication components also include a Near Field Communication (NFC) module to facilitate short-range communication. For example, the NFC module may be based on Radio Frequency Identification (RFID), Infrared Data Association (IrDA), Ultra Wide Band (UWB), Bluetooth, and other technologies. The aforementioned display includes a screen, which may include a Liquid Crystal Display (LCD) and a Touch Panel (TP). If the screen includes a Touch Panel, the screen can be implemented as a touchscreen to receive input signals from a user. The Touch Panel includes one or more touch sensors to sense touches, swipes, and gestures on the Touch Panel. The touch sensors can sense not only the boundaries of touch or swipe actions but also the duration and pressure associated with the touch or swipe operation. The aforementioned power supply component provides power to various components of the device in which the power supply component resides. The power supply component may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to the device in which the power supply component resides. The aforementioned audio component can be configured to output and / or input audio signals. For example, the audio component includes a microphone (MIC) configured to receive external audio signals when the device in which the audio component resides is in an operating mode, such as a call mode, recording mode, or voice recognition mode. The received audio signals may be further stored in memory or transmitted via a communication component. In some embodiments, the audio component also includes a speaker for outputting audio signals.
[0108] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-readable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0109] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0110] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0111] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0112] In a typical configuration, a computing device includes one or more processors (Central Processing Unit, CPU), input / output interfaces, network interfaces, and memory.
[0113] Memory may include non-persistent storage in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0114] Computer-readable media, including both permanent and non-permanent, removable and non-removable media, can store information using any method or technology. Information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase-change RAM (PRAM), static random-access memory (SRAM), dynamic random-access memory (DRAM), other types of random-access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile disc (DVD) or other optical storage, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transfer medium that can be used to store information accessible by a computing device. As defined in this article, computer-readable media do not include transient media, such as modulated data signals and carrier waves.
[0115] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0116] The above are merely embodiments of this application and are not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.
Claims
1. A method for generating unit test code based on a large language model, characterized in that, include: Obtain the code file under test in the current software project and obtain multiple target project dependency information required to generate unit test code, wherein the multiple target project dependency information includes at least the identifier of the target simulation framework and the identifier of the target test framework; The unit testing agent invokes a large language model to analyze the code file under test and the dependency information of the multiple target projects, obtaining analysis results. These results include a set of functions under test and an execution plan, as well as unit test code generated for each function in different test scenarios based on the target simulation framework and the target testing framework, according to the execution plan. The set of functions under test includes multiple functions extracted from the code file under test. The execution plan instructs the sequential generation of unit test code for each function under test based on the target simulation framework and the target testing framework. The unit test agent calls the compiler to compile the unit test code for each test function under different test scenarios, and calls the build tool to run the compiled unit test code, thus obtaining the unit test code for each test function that runs successfully under different test scenarios.
2. The method according to claim 1, characterized in that, Also includes: If there are unit test codes that fail to compile or run, the unit test agent calls the large language model to optimize the unit test codes by combining the relevant error information of the unit test codes that fail to compile or run. The optimized unit test code is compiled and run by the unit test agent until the successfully running unit test code is obtained.
3. The method according to claim 1, characterized in that, Obtaining the code files under test in the current software project includes: The system receives unit test code generation requirement information for the current software project input by the user. The unit test code generation requirement information is used to indicate the identifier of the code file under test or to indicate the generation of corresponding unit test code for code changes. If the unit test code generation requirement information indicates the identifier of the code file under test, then the code file under test is retrieved in the current software project; If the unit test code generation requirement information indicates that the corresponding unit test code is generated for the code change content, then the code change content is retrieved in the current software project, and the changed code file involved in the code change content is taken as the code file under test.
4. The method according to claim 1, characterized in that, The unit test code generation requirement information also includes: an identifier of the context information of the code file under test; the method further includes: retrieving the context information of the code file under test in the current software project based on the identifier of the context information of the code file under test. Accordingly, the unit test agent invokes a large language model to analyze the tested code file and the dependency information of the multiple target projects, obtaining the analysis results, including: The unit test agent invokes a large language model to analyze the tested code file, the context information, and the dependency information of the multiple target projects, and obtains the analysis results.
5. The method according to claim 1, characterized in that, The number of code files being tested is multiple.
6. The method according to claim 1, characterized in that, Obtain the dependency information of multiple target projects required to generate unit test code, including: Obtain the project dependency information list of the current software project and display the project dependency information list on the project dependency information confirmation interface. The project dependency information list includes multiple project dependency information options, and each project dependency information option is used to select a type of project dependency information. In response to a user's selection operation triggered by the project dependency information option, select one project dependency information from multiple optional project dependency information corresponding to the project dependency information option; In response to the user's confirmation operation on the project dependency information confirmation interface for the selected multiple project dependency information, the selected multiple project dependency information is used as multiple target project dependency information required to generate unit test code.
7. The method according to claim 1, characterized in that, Before generating the unit test code for each test function under different test scenarios according to the execution plan based on the target simulation framework and the target test framework, the process also includes: The interface for confirming the function under test is displayed. The interface for confirming the function under test includes multiple code file options under test. Each code file option under test is associated with multiple functions under test in the corresponding code file under test. In response to the user's operation on any test code file option, multiple test functions in the test code file corresponding to the test code file option are displayed; In response to the deletion operation triggered by the user, one or more of the multiple functions under test included in the code file under test are deleted from the set of functions under test; In response to the user's confirmation operation on the confirmation interface of the function under test, the step of generating unit test code for each test function under different test scenarios according to the execution plan based on the target simulation framework and the target test framework is executed.
8. The method according to claim 1, characterized in that, Also includes: The interface displays the progress of unit test code generation, which includes the following information: First progress information, which is used to indicate the number of tested functions in all tested functions under multiple tested code files that have generated unit test code; The second progress information is used to indicate the status summary information of all unit test codes under multiple test code files. Different statuses of unit test codes correspond to different styles of icons. The number of unit test codes in the corresponding status is displayed around each icon to indicate the status summary information of the unit test codes in the corresponding status. The status summary information of unit test codes in different statuses includes at least two of the following: the number of unit test codes that run successfully, the number of unit test codes that fail to run, or the number of unit test codes that fail to compile. The third progress information for each code file under test indicates the number of tested functions for which unit test code has been generated in at least one tested function corresponding to the code file under test.
9. The method according to claim 7, characterized in that, The unit test code generation progress interface also includes: a card operation control corresponding to each code file under test; when the card corresponding to the code file under test is in a collapsed state, the card operation control is used to trigger the display of the card corresponding to the code file under test; when the card corresponding to the code file under test is in an expanded state, the card operation control is used to trigger the collapse of the card corresponding to the code file under test. The card corresponding to the code file under test displays the fourth progress information for each function under test in the code file under test. The fourth progress information for each function under test is used to indicate the status of the unit test code under the function under test. The status of the unit test code under the function under test includes at least two of the following: generating, running, repairing, or generated. If the status of the unit test code under the function under test is generated, then the status summary information of the unit test code under the function under test in different states is displayed.
10. The method according to claim 1, characterized in that, Also includes: The unit test code viewing interface is displayed. The unit test code viewing interface includes a list of test code files, and the list of test code files includes file identifiers of multiple test code files. In response to a user triggering an operation to expand the card of the test code file, the card of the test code file is expanded; wherein, the card of the test code file displays a first entry control for a first unit test code list and a first statistical result, the first unit test code list includes unit test code that runs successfully or unit test code that fails to run, the first statistical result indicates the number of unit test codes in the first unit test code list, and the unit test codes in the first unit test code list have been added to the test code file; In response to the user's operation of triggering the first entry control, the first unit test code list is displayed, which includes multiple unit test codes and their corresponding scenario description information; In response to the user's acceptance operation triggered in the unit test code viewing interface, the test code file containing the unit test code is added to the current software project.
11. The method according to claim 10, characterized in that, Prior to the accept operation triggered by the user in the unit test code viewing interface, the method further includes: In response to the user's deselection operation of unit test codes in the first unit test code list, the selected unit test codes are deleted from the test code file; or, In response to the user's manual repair operation on the unit test code that failed to run in the first unit test code list, the unit test code that failed to run is repaired.
12. The method according to claim 10, characterized in that, The test code file displays a card with a second entry control and a second statistical result for a second unit test code list. The second unit test code list includes unit test codes that failed to compile. The second statistical result indicates the number of unit test codes in the second unit test code list. The unit test codes in the second unit test code list have not yet been added to the test code file. In response to the user's operation of triggering the second entry control, the second unit test code list is displayed, which includes multiple unit test codes and their corresponding scenario description information; In response to the user's manual repair operation on the unit test code that failed to compile in the second unit test code list, the unit test code that failed to compile is repaired; In response to the operation of adding the fixed compilation failure unit test code to the test code file, the fixed compilation failure unit test code is added to the test code file.
13. The method according to claim 10, characterized in that, The unit test code viewing interface also displays the number of test code files and the total number of unit test codes from all the tested code files.
14. An electronic device, characterized in that, include: Memory and processor; The memory is used to store computer programs; The processor is coupled to the memory for executing the computer program to perform the steps of the method according to any one of claims 1-13.
15. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it causes the processor to perform the steps of the method according to any one of claims 1-13.
16. A computer program product, characterized in that, Includes a computer program / instruction that, when executed by a processor, causes the processor to perform the steps of the method according to any one of claims 1-13.