Unit test generation method based on large language model
By slicing the code under test to generate test cases in parallel, and using large language model inference to generate high-coverage test suites, the problems of low coverage and high time cost in existing technologies are solved, and efficient unit test generation is achieved.
Patent Information
- Application Number
- CN202511016460.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-23
- Publication Date
- 2025-11-07
AI Technical Summary
Existing unit test generation methods based on large language models have low coverage and high time costs when generating complex methods, making it difficult to generate high-quality test suites within a limited time.
By slicing the code under test, multiple test cases are generated in parallel. A large language model is used for reasoning, and parallel test methods are constructed to generate prompt words, generate multiple code slice information, and splice them into a complete test suite.
It effectively improves code coverage for tests, reduces the average time cost of generating unit tests, and enables the generation of high-quality test suites within a limited time.
Smart Images

Figure CN120909930A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application belongs to the technical field of test generation, and particularly relates to a unit test generation method based on a large language model. BACKGROUND
[0002] Test generation is an important task in the field of software engineering, aiming to automatically generate test code for production code that has been written using test generation tools, which can ensure the quality of software systems, help developers discover defects and errors as early as possible in the development process, reduce the overall cost of products, and thus improve the productivity of developers, playing a key role in software maintenance.
[0003] Current test generation methods can be divided into two categories. One is the traditional search-based test generation method, which searches the test space of the method under test through a series of fixed rules. For example, the EvoSuite tool is based on genetic algorithms, which constantly optimize and iterate the current test cases to generate a test suite with the highest possible coverage rate. The other is the large language model-based test generation method, such as Deepseek-Coder, CodeLlama, and StarCoder, which are trained on a large amount of code corpus and have strong code reasoning ability. Through certain prompt words, the large language model can efficiently generate test cases that are more readable and understandable than traditional methods, while also achieving a relatively high code coverage rate. However, these large language model-based test generation methods still have certain limitations when generating tests for complex methods, such as low coverage rate and inability to reach corner branches. Because the complexity of the method under test is high, the large language model may not be able to understand every specific function of the method under test, making it difficult to generate one-to-one test cases for each branch or function of the method under test.
[0004] Although there have been research works that use various post-processing methods to improve the ability of large language models to generate test cases for complex methods, the post-processing methods used have very high time costs, making the final time cost unacceptable to developers. The present application aims to generate multiple test cases in parallel for each segment of the code under test without additional time-consuming post-processing, thereby reducing the time cost of test generation and improving the code coverage rate of the test, so as to generate a high-quality test suite within a limited time. SUMMARY
[0005] The present application aims to address the defects of existing unit test generation methods, such as low code coverage rate and high time cost of generation, and provides a unit test generation method based on a large language model.
[0006] The application aims to realize the following technical solutions: a unit test generation method based on a large language model, comprising the following steps:
[0007] (1) Deploy a language server corresponding to the language of the code under test, use language server technology to statically analyze the code under test, obtain abstract syntax trees, call relationship graphs, dependency relationship graphs and other information of the method under test, and finally extract context information closely related to the method under test according to the obtained abstract syntax trees, call relationship graphs, dependency relationship graphs and other information;
[0008] (2) According to the context information closely related to the method under test obtained in step (1), construct a code slice prompt word of the code under test;
[0009] (3) Use a general large language model to infer the code slice prompt word constructed in step (2), complete the code slicing task, and obtain multiple code slice information of the method under test according to the inference result of the general large language model;
[0010] (4) For the multiple code slice information obtained in step (3), for each piece of code slice information, construct a test method generation prompt word;
[0011] (5) Use a general large language model to infer the test method generation prompt word constructed in step (4), complete the test generation task, and obtain the test method generated for each piece of code slice information according to the inference result of the general large language model; each piece of code slice information can be executed in parallel, and finally multiple different test methods for each piece of code slice information are obtained;
[0012] (6) All test methods generated in step (5) are spliced into a complete test suite.
[0013] Further, the context information closely related to the method under test includes member variables of the class under test, other method signatures of the class under test, constructors of classes dependent on the class under test, and specific implementations of methods dependent on the method under test.
[0014] Further, the code slice prompt word of the code under test includes the following features:
[0015] The system generates content: in the prompt words, there are "The basic information of your workarounds are:1. The Programming Langauge: Java 2. The Language Style: Java{{java_version}}3. The Tools for Unit Tests:{{java_test_tool}}", this part of the prompt words is used to specify the corresponding programming language, specify the corresponding language version and specify the corresponding unit test tool;
[0016] The code under test related content: in the prompt words, there is a chapter "###Basic Information of the Method under Test and Its Dependencies", which includes the specific implementation of the code under test, the related context of the code under test, the dependent methods and dependent classes of the code under test;
[0017] Code slice information generation requirements: in the prompt words, there is a chapter "###Instructions on Decomposing the Method under Test into Slices", which includes the specific steps of the large language model for slicing the method under test: summarize the method under test; list the environment settings for running the method under test; generate code slices for the code under test, each piece of code slice information is logically independent; reconstruct the generated content into a formatted structure;
[0018] Code slice format generation requirements: in the prompt words, there is a chapter "###Format of the Output", which clearly specifies the Json structure of the generated slice information, including all key-value pairs: the key "summarization" corresponds to the summary string of the method under test; the key "invoked_outside_vars" corresponds to the global variables, method parameters and class member methods required by the method under test; the key "invoked_outside_methods" corresponds to the external methods required by the method under test; the key "steps" corresponds to all code slice information, the key "code" corresponds to the specific code segment of the slice, and the key "desp" corresponds to the function description of the slice.
[0019] Further, the test method generates prompt words including the following features:
[0020] System-generated content: In the prompt, there is "The basic information of your workarounds are:1. The Programming Langauge: Java 2. The Language Style: Java{{java_version}} 3. The Tools for Unit Tests:{{java_test_tool}}", this part of the prompt is used to specify the corresponding programming language, specify the corresponding language version and specify the corresponding unit test tool;
[0021] Code-under-test-related content: In the prompt, there is a section "###Basic Information of the Method under Test and Its Dependencies", which includes the specific implementation of the code-under-test, the relevant context of the code-under-test, the dependent methods and classes of the code-under-test;
[0022] Code slice information content: In the prompt, there is "Based on the information provided above, generate unit tests for code```java{{slice_code}}```The description of this code is{{slice_desc}}", which includes the specific code snippet and function description of the code slice;
[0023] Generate test method requirements: In the prompt word, there is a chapter "####Requirements and Attention for the Unit Test to Generate:" which includes specific requirements for generating tests. In this chapter, there is a requirement "Ensure that the unit tests are executable: they should run without any compilation errors, runtime errors, or timeouts." to generate error-free executable unit tests; there is a requirement "Aim for comprehensive coverage: the unit tests should encompass a significant portion of the codebase, including instructions and branches within the method under test." to generate high-coverage unit tests; there is a requirement "Avoid altering the method under test." to prohibit modifying the contents of the method under test; there is a requirement "Only generate the test method: Do not generate the full test class code or any imports. Provide only the inside implementation of the test method, including the `@Test` annotation." to generate unit tests at the method level; there is a requirement "Name the test method as `{{test_method_name}}`." to specify the name of the generated unit test method; there is a requirement "Ensure that the unit test methods do test the method under test:" to specify the specific method under test; there is a requirement "Utilize appropriate tools and adhere to the language style guidelines:" to specify the language version and test tools of the generated unit test.
[0024] Generate test format requirements: In the prompt word, there is a chapter "###Output Format:" which includes the specific format of generating tests. According to different test tools, the specific format of the test is also different.
[0025] Further, in the test format requirement generated, when testing is performed using JUnit 5, the corresponding format is "" <generate>The whole unit test method is:```java@Test...```< / generate> ".
[0026] To achieve the above object, the application further provides an electronic device, comprising a memory and a processor, the memory being coupled with the processor; wherein the memory is used for storing program data, and the processor is used for executing the program data to realize the above-mentioned unit test generation method based on a large language model.
[0027] To achieve the above object, the application further provides a computer readable storage medium, which stores a computer program, and the program is executed by a processor to realize the above-mentioned unit test generation method based on a large language model.
[0028] The application has the following advantages and beneficial effects: the application slices the code to be tested without performing an additional time-consuming post-processing process, and generates multiple test cases in parallel for each segment of the sliced code, thereby effectively improving the code coverage of the test compared with directly using a large language model to infer the corresponding unit test; compared with a test generation method using a high time cost post-processing technology, the average time for generating a single unit test is effectively reduced; and finally, a test suite with high code coverage can be generated within a limited time. BRIEF DESCRIPTION OF DRAWINGS
[0029] Figure 1 is a schematic diagram of the system prompt word of the application;
[0030] Figure 2 is a schematic diagram of the code slicing prompt word of the application;
[0031] Figure 3 is a schematic diagram of the test generation prompt word of the application.
[0032] Figure 4 is a schematic diagram of the test generation prompt word of the application. DETAILED DESCRIPTION
[0033] The application will be further described below with reference to the accompanying drawings.
[0034] The present application evaluates the effectiveness of the proposed method based on a high-quality open source project dataset collected from the Github open source community. The present application selects three high-quality Java open source projects with more than 300 stars from the Github open source community, extracts 50 complex method construction datasets from the three open source projects for evaluation. The present application generates JUnit5 unit tests in the evaluation, uses the coverage tool Jacoco of Java to evaluate the code coverage of the test cases, and uses one of the current most popular large language models, Deepseek-Coder-instruct-6.7b, to complete the code slicing task and test generation task.
[0035] As shown in Figure 1 , the present application provides a unit test generation method based on a large language model, which comprises the following steps:
[0036] (1) Deploy the language server corresponding to the language of the code under test, use language server technology to statically parse the code under test, and obtain the abstract syntax tree, call relationship graph, dependency relationship graph and other information of the method under test; according to the obtained abstract syntax tree, call relationship graph, dependency relationship graph and other information, finally extract the context information closely related to the method under test; the language server is a program that implements the language service protocol, which provides programming language related function support for the development environment, such as automatic completion, code jump, syntax check, reference lookup, etc. By using the language server protocol, different editors and IDEs can not need to rewrite the support logic of these functions, but only need to interact with the language server to complete the parsing of the code. The purpose of this step is to collect the context information related to the method under test, such as the member variable this.maxCount in the class under test that may be called in the method under test. Such information is crucial for understanding the method under test.
[0037] (2) According to the context information closely related to the method under test obtained in step (1), construct the code slicing prompt word of the code under test; the context information closely related to the method under test includes the member variables of the class under test, the method signatures of other methods of the class under test, the constructors of the classes depended by the class under test, and the specific implementation of the methods depended by the method under test; the code slicing prompt word of the code under test is composed of the system prompt word shown in Figure 2 and the code slicing prompt word shown in Figure 3 .
[0038] (3) using a general large language model to infer the measured code slice prompt word constructed in step (2), completing the code slice task, and obtaining multiple code slice information of the measured method according to the inference result of the general large language model. The code slice information includes code slice segments, code slice descriptions, code slice numbers and positions. This step does not depend on the unique characteristics of some large language models, and theoretically any general large language model with certain code knowledge can complete this task. This step can divide the complex measured method into multiple simple code segments, for example, a complex if-else conditional statement can be split into multiple simple if conditional statements.
[0039] (4) for the multiple code slice information obtained in step (3), for each piece of code slice information, construct a test method generation prompt word; the test method generation prompt word is composed of the system prompt word shown in Figure 2 and the test generation prompt word shown in Figure 4 .
[0040] (5) using a general large language model to infer the test method generation prompt word constructed in step (4), completing the test generation task, and obtaining the test method generated for each piece of code slice information according to the inference result of the general large language model; this step can be executed in parallel for each piece of code slice information, and finally multiple different test methods for each piece of code slice information can be obtained. This step does not depend on the unique characteristics of some large language models, and theoretically any general large language model with certain code knowledge can complete this task. This step will generate multiple unit tests in the JUnit 5 format starting with @Test.
[0041] (6) all test methods generated in step (5) are spliced into a complete test suite; this step is a text splicing of test methods, and each independent test method is written into the same test suite. Finally, the test suite is written back to the measured project, the test suite is run, and the final test success rate, compilation success rate and coverage rate are obtained.
[0042] Further, the measured code slice prompt word includes the following features:
[0043] The system generates content: in the prompt words, there are "The basic information of your workarounds are:1. The Programming Langauge: Java 2. The Language Style: Java{{java_version}}3. The Tools for Unit Tests:{{java_test_tool}}", this part of the prompt words can specify the corresponding programming language, specify the corresponding language version and specify the corresponding unit test tool;
[0044] The code to be tested is related: in the prompt words, there is a chapter "###Basic Information of the Method under Test and Its Dependencies", which includes the specific implementation of the code to be tested, the related context of the code to be tested, the dependent methods and dependent classes of the code to be tested;
[0045] Code slice generation information requirements: in the prompt words, there is a chapter "###Instructions on Decomposing the Method under Test into Slices", which includes the specific steps of the large language model for slicing the method to be tested: 1. Summarize the method to be tested; 2. List the environment settings for running the method to be tested; 3. Generate code slices for the code to be tested, each code slice information is logically independent; 4. Reconstruct the generated content into a formatted structure.
[0046] Code slice generation format requirements: in the prompt words, there is a chapter "###Format of the Output", which clearly states the Json structure of the generated slice information, including all key-value pairs: the key "summarization" corresponds to the summary string of the method to be tested; The key "invoked_outside_vars" corresponds to the global variables, method parameters and class member methods required by the method to be tested; The key "invoked_outside_methods" corresponds to the external methods required by the method to be tested; The key "steps" corresponds to all code slice information, which in turn has the key "code" corresponding to the specific code segment of the slice, and the key "desp" corresponding to the function description of the slice.
[0047] Further, the test method generates prompt words including the following features:
[0048] System-generated content: In the prompt, there is "The basic information of your workarounds are:1. The Programming Langauge: Java 2. The Language Style: Java{{java_version}} 3. The Tools for Unit Tests:{{java_test_tool}}", this part of the prompt can specify the corresponding programming language, specify the corresponding language version and specify the corresponding unit test tool;
[0049] Code-under-test-related content: In the prompt, there is a section "###Basic Information of the Method under Test and Its Dependencies", which includes the specific implementation of the code-under-test, the relevant context of the code-under-test, the dependent methods and classes of the code-under-test;
[0050] Code slice information content: In the prompt, there is "Based on the information provided above, generate unit tests for code```java{{slice_code}}```The description of this code is{{slice_desc}}", which includes the specific code snippet and function description of the code slice;
[0051] Generate test method requirements: There is a section "####Requirements and Attention for the Unit Test to Generate:" in the prompt words, which includes specific requirements for generating tests. In this section, there is a requirement "Ensure that the unit tests are executable: they should run without any compilation errors, runtime errors, or timeouts." to generate error-free executable unit tests; there is a requirement "Aim for comprehensive coverage: the unit tests should encompass a significant portion of the codebase, including instructions and branches within the method under test." to generate high-coverage unit tests; there is a requirement "Avoid altering the method under test." to prohibit modifying the contents of the method under test; there is a requirement "Only generate the test method: Do not generate the full test class code or any imports. Provide only the inside implementation of the test method, including the `@Test` annotation." to generate unit tests at the method level; there is a requirement "Name the test method as `{{test_method_name}}`." to specify the name of the generated unit test method; there is a requirement "Ensure that the unit test methods do test the method under test:" to specify the specific method under test; there is a requirement "Utilize appropriate tools and adhere to the language style guidelines:" to specify the language version and test tools of the generated unit test;
[0052] The generation test format requirement is that there is a chapter "###Output Format:" in the prompt word, which includes the specific format of the generated test. According to different test tools, the corresponding test specific format will also be different. When using JUnit 5 for testing, the corresponding format is " <generate>The whole unit test method is:```java@Test...```< / generate> ".
[0053] Embodiment 1
[0054] The present application uses five evaluation indicators commonly used in the field of class test generation when evaluating the effectiveness of unit test generation:
[0055] Test success rate: the proportion of test cases that can be successfully compiled and run through in the generated test cases;
[0056] Compilation success rate: the proportion of test cases that can be successfully compiled in the generated test cases;
[0057] Line coverage: the proportion of code lines covered by the generated test cases;
[0058] Branch coverage: the proportion of branches covered by the generated test cases;
[0059] Generation time consumption: the time cost of generating test cases, which does not include the time cost of running the test suite.
[0060] The method proposed in the present application is compared with the traditional test generation tool EvoSuite, the large language model itself, and a method based on large language models and post-processing techniques in the field of test generation HITS. Table 1 is the experimental evaluation results of the method proposed in the present application on the data of each open source project.
[0061] Table 1: Evaluation results of the method proposed in the present application on the data of each open source project
[0062]
[0063] The experimental results show that the method proposed in the present application can generate test cases with high code coverage in a short time, that is, high-quality test cases can be generated in a short time. Table 2 is the comparative evaluation results of the method proposed in the present application and the traditional test generation tool EvoSuite and the large language model itself.
[0064] Table 2: Comparative evaluation results of the method proposed in the present application and EvoSuite and the large language model itself
[0065]
[0066]
[0067] The EvoSuite generates content are all regression tests, and the EvoSuite generates content are output after running verification, and the generation time of the EvoSuite is configurable content, and the EvoSuite keeps retrying search until the generation time reaches the upper limit before reaching 100% coverage, so the test success rate, the compilation success rate and the average generation consumption time of the EvoSuite are meaningless. The evaluation results show that the method proposed in the application is significantly better than the traditional test generation method EvoSuite and the model itself in the code coverage, and is significantly higher than the model itself in the test success rate and the compilation success rate. In particular, although the generation time of the method proposed in the application is higher than that of the single call of the model itself, the coverage of the method proposed in the application is far more than that of the model itself, which is more meaningful to the developer, and further embodies the effectiveness of the method proposed in the application. Table 3 is the time cost experimental evaluation results of the method proposed in the application and the test generation method HITS using post-processing technology.
[0068] Table 3: Time cost evaluation results of the method proposed in the application and the test generation method HITS
[0069] Large language model HITS The invention Average generation consumption time / s 7.64 52.41 13.29
[0070] The evaluation results show that the method proposed in the application only needs to consume about one fourth of the time of HITS to complete generation, and for the developer, the method proposed in the application is undoubtedly a more efficient test generation method. In particular, due to various post-processing technologies, HITS needs to consume an average of 52.41s to generate corresponding tests for a single method under test, and in the actual development process, it may even be slower than the speed of the developer writing unit tests, while the method proposed in the application only needs an average of 13.29s to complete generation, and is more usable and efficient.
[0071] Corresponding to the foregoing embodiment of the unit test generation method based on the large language model, an electronic device is also provided, including one or more processors, a memory for storing one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors implement the unit test generation method based on the large language model as described above.
[0072] Corresponding to the foregoing embodiment of the unit test generation method based on the large language model, a computer readable storage medium is also provided, which stores a program, and when the program is executed by a processor, the unit test generation method based on the large language model in the foregoing embodiment is implemented.
[0073] The computer readable storage medium can be an internal storage unit of any of the aforementioned data processing capable devices, such as a hard disk or a memory. The computer readable storage medium can also be any of the aforementioned data processing capable devices, such as a plug-in hard disk, a Smart Media Card (SMC), an SD card, a Flash Card, etc. Further, the computer readable storage medium can also include both an internal storage unit of any of the aforementioned data processing capable devices and an external storage device. The computer readable storage medium is used to store the computer program as well as other programs and data required by the aforementioned data processing capable devices, and can also be used to temporarily store data that has been output or will be output.
[0074] Other embodiments of the application will be apparent to those skilled in the art from consideration of the specification and practice of the application disclosed herein. It is intended that the specification and examples be considered as exemplary only, with a true scope of the application being indicated by the following claims.
[0075] It is to be understood that the application is not limited to the precise details of design and operation described above and illustrated in the drawings. Various modifications and changes can be made without departing from the scope of the application.
Claims
1. A method for generating unit tests based on a large language model, characterized in that, The method comprises the following steps: (1) deploying a language server corresponding to the language of the code under test, using language server technology to statically analyze the code under test, obtaining abstract syntax tree, call relationship graph, dependency relationship graph and other information of the method under test, and finally extracting the context information closely related to the method under test according to the obtained abstract syntax tree, call relationship graph, dependency relationship graph and other information; (2) according to the context information closely related to the method under test obtained in step (1), constructing a code slice prompt word of the code under test; (3) using a general large language model to infer the code slice prompt word constructed in step (2), completing the code slicing task, and obtaining multiple code slice information of the method under test according to the inference result of the general large language model; (4) for the multiple code slice information obtained in step (3), for each piece of code slice information, constructing a test method generation prompt word; (5) using a general large language model to infer the test method generation prompt word constructed in step (4), completing the test generation task, and obtaining the test method generated for each piece of code slice information according to the inference result of the general large language model; Each piece of code slice information can be executed in parallel, and finally multiple different test methods for each piece of code slice information are obtained; (6) all test methods generated in step (5) are spliced into a complete test suite.
2. The large language model-based unit test generation method according to claim 1, characterized in that, The context information closely related to the method under test includes member variables of the class under test, other method signatures of the class under test, constructors of classes dependent on the class under test, and specific implementations of methods dependent on the method under test. 3.The method of claim 1, wherein, The code slice prompt word of the code under test comprises the following features: Specify system-generated content: In the prompt word, "The basic information of your workarounds are:
1. The Programming Langauge: Java 2. The Language Style: Java{{java_version}} 3. The Tools for Unit Tests:{{java_test_tool}}", this part of the prompt word is used to specify the corresponding programming language, specify the corresponding language version and specify the corresponding unit test tool; Code under test related content: In the prompt word, there is a chapter "###Basic Information of the Method under Test and Its Dependencies", which includes the specific implementation of the code under test, the related context of the code under test, the dependent methods and dependent classes of the code under test; Code slice information requirements: In the prompt word, there is a chapter "###Instructions on Decomposing the Method under Test into Slices", which includes the specific steps of the large language model for slicing the method under test: summarizing the method under test; List the environment settings of running the tested method; generate code slices for the tested code, each piece of code slice information is logically independent; reconstruct the generated content into a formatted structure; Code slice format requirements: there is a chapter "###Format of the Output" in the prompt word, which clearly shows the Json structure of the generated slice information, including all key-value pairs: the key "summarization" corresponds to the summary string of the tested method; the key "invoked_outside_vars" corresponds to the global variables, method parameters and class member methods required by the tested method; the key "invoked_outside_methods" corresponds to the external methods required by the tested method; the key "steps" corresponds to all code slice information, the key "code" corresponds to the specific code segment of the slice, and the key "desp" corresponds to the function description of the slice.
4. The large language model-based unit test generation method according to claim 1, characterized in that, The test method generates a prompt word Including the following features: System-generated content is specified: in the prompt word, there is "The basic information of your workarounds are:1.The Programming Langauge: Java 2.The Language Style: Java{{java_version}}3.The Tools for Unit Tests:{{java_test_tool}}", this part of the prompt word is used to specify the corresponding programming language, specify the corresponding language version and specify the corresponding unit test tool; Tested code related content: in the prompt word, there is a chapter "###Basic Information of the Method under Test and Its Dependencies", which includes the specific implementation of the tested code, the related context of the tested code, the dependent methods and dependent classes of the tested code; Code slice information content: in the prompt word, there is "Based on the information provided above, generate unit tests for code```java{{slice_code}}```The description of this code is{{slice_desc}}", which includes the specific code segment and function description of the code slice; Generate test method requirements: In the prompt word, there is a chapter "####Requirements and Attention for the Unit Test to Generate:" which includes specific requirements for generating tests. In this chapter, there is a requirement "Ensure that the unit tests are executable: they should run without any compilation errors, runtime errors, or timeouts." to generate error-free executable unit tests; there is a requirement "Aim for comprehensive coverage: the unit tests should encompass a significant portion of the codebase, including instructions and branches within the method under test." to generate high-coverage unit tests; there is a requirement "Avoid altering the method under test." to prohibit modifying the contents of the method under test; there is a requirement "Only generate the test method: Do not generate the full test class code or any imports. Provide only the inside implementation of the test method, including the `@Test` annotation." to generate unit tests at the method level; there is a requirement "Name the test method as `{{test_method_name}}`." to specify the name of the generated unit test method; there is a requirement "Ensure that the unit test methods do test the method under test:" to specify the specific method under test; there is a requirement "Utilize appropriate tools and adhere to the language style guidelines:" to specify the language version and test tools of the generated unit tests. Generate test format requirements: In the prompt word, there is a chapter "###Output Format:" which includes the specific format of generating tests. According to different test tools, the specific format of the test is also different.
5. The large language model-based unit test generation method according to claim 4, characterized in that, In the generation test format requirement, when testing is performed using JUnit 5, the corresponding format is <generate>The whole unittest method is:```java@Test...```< / generate> .
6. An electronic device comprising a memory and a processor, characterized in that The memory is coupled with the processor; wherein the memory is used to store program data, and the processor is used to execute the program data to realize the unit test generation method based on the large language model in any one of claims 1-5.
7. A computer-readable storage medium having stored thereon a computer program, characterized in that, The program is executed by the processor to realize the unit test generation method based on the large language model in any one of claims 1-5.