Training method, device and equipment for generating large model of unit test code

By retraining the large model and utilizing code style and function simulation prompts, the problem of unstable unit test code generation was solved, achieving efficient and stable unit test code generation and reducing manual costs.

CN120872301APending Publication Date: 2025-10-31BEIJING ZITIAO NETWORK TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410508619.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-04-25
Publication Date
2025-10-31

AI Technical Summary

Technical Problem

Existing unit test code acquisition solutions suffer from high manual workload and unstable code quality, making them unsuitable for various testing scenarios and resulting in low compilation pass rates and reduced testing efficiency.

Method used

By constructing training samples and sample labels, the pre-trained large model is retrained, and the stability and coverage of the generated unit test code are improved by using code style indicators that indicate whether to generate or disable generation and function prompts that simulate program unit calls.

Benefits of technology

It improves the usability and stability of the generated unit test code, reduces debugging costs, enables earlier detection and fixing of software vulnerabilities, and improves testing efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120872301A_ABST
    Figure CN120872301A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a training method, device and equipment for generating a large model of a unit test code. A specific embodiment of the method comprises the steps of obtaining a first unit code corresponding to a first program unit and a first test code for the first program unit; constructing a first cue indicating generation of a test code for the first program unit according to the first unit code and a first cue portion indicating a code style expected to be generated or prohibited from being generated; and taking the first prompt as a training sample, taking the first test code as a training label corresponding to the training sample, and training the pre-trained target large model again through the training sample and the training label. Through the method, the quality and the stability of the generated unit test code can be greatly improved, and the labor cost consumed by debugging the unit test code is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the fields of software testing and large model technology, and more particularly to a training method, apparatus, and device for generating unit test code for a large model. Background Technology

[0002] Unit testing is the testing of individual software modules or program units within a software application or system. Unit testing ensures that a program unit functions as expected and allows for the early detection of errors and defects in the code, improving code reliability. However, existing methods for obtaining unit test code either involve significant manual effort or suffer from inconsistent quality of the obtained unit test code. Summary of the Invention

[0003] This disclosure describes a training method, apparatus, device, and medium for generating unit test code for a large model.

[0004] Based on the first aspect, a method for training a large model to generate unit test code is provided, including:

[0005] Obtain the first unit code corresponding to the first program unit, and the first test code for the first program unit; based on the first unit code and the first prompt part indicating the code style to be generated or prohibited, construct a first prompt message indicating the generation of test code for the first program unit;

[0006] Using the first prompt as a training sample and the first test code as the training label corresponding to the training sample, the pre-trained target large model is retrained using the training sample and the training label.

[0007] According to the second aspect, a training apparatus for generating large models of unit test code is provided, comprising:

[0008] The acquisition unit is configured to acquire the first unit code corresponding to the first program unit and the first test code for the first program unit; based on the first unit code and a first prompt part indicating the desired or prohibited code style, construct a first prompt message indicating the generation of test code for the first program unit;

[0009] The training unit is configured to use the first prompt as a training sample and the first test code as the training label corresponding to the training sample, and to retrain the pre-trained target large model using the training sample and the training label.

[0010] According to a third aspect, a computer-readable storage medium is provided, on which a computer program is stored, which, when executed in a computer, causes the computer to perform the method of the first aspect.

[0011] According to a fourth aspect, an electronic device is provided, including a memory and a processor, wherein the memory stores executable code, and the processor executes the executable code to implement the method of the first aspect.

[0012] This disclosure provides a method, apparatus, device, and medium for training a large model to generate unit test code. First, a first unit code corresponding to a first program unit and first test code for the first program unit are obtained. Based on the first unit code and a first prompt indicating the desired or prohibited code style, a first prompt indicating the generation of test code for the first program unit is constructed. Then, using the first prompt as a training sample and the first test code as the corresponding training label, the pre-trained target large model is retrained using the training sample and the training label. This method significantly improves the usability and stability of the generated unit test code and reduces the manual cost of debugging unit test code. Attached Figure Description

[0013] Figure 1 A schematic diagram is shown of a training method for generating unit test code for a large model according to an embodiment of the present disclosure;

[0014] Figure 2 A flowchart illustrating a training method for generating unit test code for a large model according to an embodiment of the present disclosure is shown.

[0015] Figure 3 A schematic diagram of a first prompt according to an embodiment of the present disclosure is shown;

[0016] Figure 4 A schematic diagram of unit test code according to an embodiment of the present disclosure is shown;

[0017] Figure 5 A schematic diagram illustrating the generation of unit test code from a finely tuned target large model according to an embodiment of the present disclosure is shown;

[0018] Figure 6 A schematic diagram of the input prompts for the finely tuned target large model according to an embodiment of the present disclosure is shown;

[0019] Figure 7 A schematic block diagram of a training apparatus for generating unit test code for a large model according to an embodiment of the present disclosure is shown;

[0020] Figure 8A schematic diagram of the structure of an electronic device suitable for implementing the embodiments of the present disclosure is provided;

[0021] Figure 9 A schematic diagram of the structure of a storage medium suitable for implementing embodiments of the present disclosure is provided. Detailed Implementation

[0022] The technical solutions provided in this specification will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the relevant invention and not intended to limit the invention. Furthermore, it should be noted that, for ease of description, only the parts relevant to the invention are shown in the accompanying drawings. It should be noted that, unless otherwise specified, the embodiments and features described herein can be combined with each other.

[0023] In the description of the implementations disclosed herein, the term "comprising" and similar terms should be understood as open inclusion, i.e., "including but not limited to". The term "based on" should be understood as "at least partially based on". The term "one / an implementation" or "the implementation" should be understood as "at least one / an implementation". The term "some implementations" should be understood as "at least some implementations". Other explicit and implicit definitions may also be included below.

[0024] As mentioned earlier, unit testing is the testing of individual software modules or program units within a software application or system. Unit testing ensures that the functionality of a program unit meets expectations. Furthermore, it allows for the early detection of errors and defects in the code during software development, improving code reliability. Currently, the code used for unit testing, or simply unit test code, can be obtained through writing by developers or testers; however, this method is labor-intensive. Therefore, some software users or vendors wish to obtain unit test code automatically, such as by generating unit test code from pre-defined test case templates or by training neural network models. However, generating unit test code from pre-defined test case templates is difficult to adapt to various testing scenarios, leading to insufficient testing of the execution logic of the unit under test in some situations. The conventional method of generating unit test code by training neural network models also suffers from inconsistent test code quality in actual production scenarios, resulting in low compilation pass rates, reduced unit testing efficiency, and increased labor costs for testers to fix the unit test code.

[0025] To address the aforementioned technical problems, this disclosure provides a method for training a large model that generates unit test code. Figure 1 A schematic diagram is shown of a training method for generating unit test code for a large model according to an embodiment of this disclosure. For example... Figure 1 As shown, in some embodiments, for example, the code of the target program unit (or simply unit code) and the test code for the target program unit can be obtained. Training samples are constructed based on the unit code and prompts indicating the desired or prohibited code style. Sample labels corresponding to the training samples are determined based on the use case code. Using the training samples and sample labels, the pre-trained target model is retrained, or fine-tuned. In some embodiments, training samples can also be constructed based on the unit code, prompts indicating the desired or prohibited code style, and prompts indicating how to simulate the target function in the program unit in the unit test code.

[0026] The advantages of this method are as follows: First, by adding prompts to the training samples indicating the desired or prohibited code style, the large model can be better guided to generate unit test code with a high compilation pass rate, thereby improving the stability and usability of the generated unit test code. Second, by adding prompts to the training samples indicating functions that simulate program unit calls in the unit test code, the coverage of each execution branch in the unit under test by the unit test code can be effectively improved, thus enhancing the effectiveness of unit testing. This facilitates the earlier discovery of vulnerabilities or problems in the software through test code, allowing for the fix of vulnerabilities or problems at a lower cost. Third, in some embodiments, after fine-tuning the target large model, several code characters at the beginning of the unit test code can be added to the prompts input to the target large model, thereby instructing the target large model to generate unit test code more accurately based on these code characters, further improving the usability and stability of the generated unit test code.

[0027] The following describes the detailed process of this method.

[0028] Figure 2 A flowchart illustrating a training method for generating unit test code for a large model according to an embodiment of this disclosure is shown. Figure 2 As shown, the method includes at least the following steps:

[0029] Step S201: Obtain the first unit code corresponding to the first program unit and the first test code for the first program unit; based on the first unit code and the first prompt part indicating the code style to be generated or prohibited, construct a first prompt message indicating the generation of test code for the first program unit;

[0030] Step S203: Using the first prompt as a training sample and the first test code as the training label corresponding to the training sample, the pre-trained target large model is retrained using the training sample and the training label.

[0031] First, in step S201, the first unit code corresponding to the first program unit and the first test code for the first program unit are obtained. A program unit (Unit) refers to a basic component in a computer program. In different specific embodiments, it can be one or more of a function, procedure, module, or class. Unit testing is software testing performed on a program unit, which can be used to verify whether the actual function or performance of the program unit meets expectations. The test code for the program unit is the code used to execute the unit tests for the program unit. In one embodiment, the test code for the program unit may include code for one or more test cases for the program unit. In this step, the code of the first program unit itself (i.e., the first unit code) and the test code for the first program unit (i.e., the first test code) can be obtained. In different embodiments, the first program unit may belong to different specific programs or applications. In different embodiments, the first unit code and the first test code may be code based on different specific programming languages, which is not limited in this specification.

[0032] After obtaining the first unit code, a first prompt can be constructed based on the first unit code and a first prompt section indicating the expected or prohibited code style to be generated. Specifically, the first prompt section is used in subsequent steps to indicate to the larger model the expected or prohibited code style of the generated code. Figure 3 A schematic diagram of a first prompt according to an embodiment of this disclosure is shown. Figure 3 In the example shown, the first prompt may include the code for the program unit (e.g., the function Fun_1) and an indication of the prohibited code style (e.g., table-driven style). In other examples, the first prompt may also include an indication of the desired code style to be prohibited. This approach better guides the large model in subsequent steps to generate unit test code with the desired or avoided code styles, thereby improving the stability of the generated unit test code.

[0033] In different embodiments, the expected or prohibited target code style suggested in the first hint section may differ. For example, table-driven code typically has high syntactic complexity, and syntax errors in the generated code can cause the entire unit test code to fail to compile. To improve the usability of the generated unit test code, in one specific embodiment, the expected target code style may be, for example, table-driven.

[0034] In addition to the first prompt section, the first prompt may also include a second prompt section. The second prompt section is used to prompt the large model in subsequent steps to simulate the first target function called by the first program unit in its generated test code. Therefore, in one embodiment, the first program unit may call the first target function, and the first test code may include a code segment simulating the target function. Furthermore, a first prompt indicating the generation of test code for the first program unit can be constructed based on the first unit code, the first prompt section indicating the desired or prohibited code style, and the second prompt section indicating the simulation of the first target function called by the first program unit in the generated test code. In different embodiments, the first target function indicated in the second prompt section may also be one or more functions. Figure 3 In the example shown, the first prompt includes instructions to simulate multiple functions called by the first program unit in the unit test code, such as instructions to simulate Call Fun_1, Call Fun_2 and Call Fun_3 functions called in the Fun_1 function (the first program unit).

[0035] In different embodiments, the type of function called by the simulated program unit in the second prompt section can also be different. In one embodiment, the first target function may include, for example, one or more of the following: environment parameter reading parameters, configuration parameter reading functions, and functions contained in other program units. The environment parameter reading parameters can be used to obtain the values ​​of status parameters of the runtime environment during program unit execution, and the configuration parameter reading functions can be used to obtain the values ​​of, for example, business configuration parameters during program unit execution. Because in actual production environments, the actual return values ​​of functions such as environment parameter reading parameters, configuration parameter reading functions, and functions contained in other program units are often limited by the runtime environment itself, it is difficult to fully cover the execution branches in the program unit under test based on them. By using the simulated return values ​​of these functions, the limitations of the actual return values ​​of functions called in the actual runtime environment on the execution branches in the program unit under test can be avoided, effectively improving the coverage of the unit test code for each execution branch in the program unit under test.

[0036] In different specific embodiments, the specific way in which the code segment in the first test code simulates the first target function can be different. For example, in one specific embodiment, the code segment can simulate the first target function by the following steps: setting a simulated value corresponding to the first target function; and determining the return value of the first target function based on the simulated value in response to a call to the first target function during the execution of the first program unit. Figure 4 A schematic diagram of unit test code according to an embodiment of this disclosure is shown. Figure 4 As shown, for example, in the unit test code, the mock value corresponding to the function CallFun_1 can be set to false using a mock function (MockFun) in one or more test cases. Then, when the CallFun_1 function is called during the execution of program unit Fun_1, this mock value false is directly used as the return value of CallFun_1. Furthermore, as... Figure 4 As shown, functions such as Call Fun_2 and Call Fun_3 can also be simulated in a similar way in unit test code, which will not be elaborated here. This method allows for a simple and efficient simulation of the target function in the test code.

[0037] Then, in step S203, the first prompt obtained in step S201 is used as a training sample, and the first test code obtained in step S201 is used as the training label for the training sample. The pre-trained target model is then retrained using the training samples and training labels.

[0038] The target large model is a large model used to generate test code for a program unit, based at least on the program unit's own code and hints regarding the generated code style. The specific structure or type of the target large model may differ in different specific embodiments, and this specification does not impose any limitations on this. Retraining (or fine-tuning) the large model refers to making targeted adjustments and optimizations to the pre-trained large model to adapt it to a specific task or dataset. Specifically, for example, supervised learning can be performed on the pre-trained large model using training samples and sample labels, such as using the backpropagation algorithm to update the large model's parameters.

[0039] After the target large model is retrained (fine-tuned), test code for other program units can be generated based on the fine-tuned target large model and the code of other program units. Therefore, in one embodiment, the second unit code corresponding to the second program unit can be obtained; based on the second unit code and a first prompt indicating the desired or prohibited code style, a second prompt indicating the generation of test code for the second program unit can be constructed; the second prompt is input into the retrained target large model to obtain the second test code for the second program unit. In this way, based on the fine-tuned target large model and the code of different program units, unit test code with or without a specific code style can be obtained for different program units. Thus, by indicating the generated code style, the compilation pass rate of the generated unit test code is improved, thereby improving the stability of the unit test code.

[0040] In one embodiment, a second prompt indicating the generation of test code for the second program unit can also be constructed based on the second unit code, a third prompt indicating the desired or prohibited code style to be generated, and a third prompt indicating the second target function to be simulated in the generated test code. Figure 5 A schematic diagram illustrating the generation of unit test code from a finely tuned target large model according to an embodiment of this disclosure is shown. Figure 5 As shown, for example, unit code from other program units can be obtained. Based on this unit code, along with hints indicating the desired or prohibited code style and function simulation, a prompt for the target large model can be constructed. This prompt is then input into the fine-tuned target large model to obtain unit test code from other program units. Through this method, the coverage of the generated unit test code for each execution branch in the tested program unit can be effectively improved, thus enhancing the effectiveness of unit testing.

[0041] In one embodiment, the second prompt may further include a fourth prompt portion, which includes multiple code characters that appear first in the second test code. In a specific embodiment, the number of multiple code characters may be randomly determined or predetermined. Figure 6 As shown, for example, multiple code characters at the beginning of the unit test code can be added to the prompt message of the large model after fine-tuning, such as adding "fun Test_Fun_1(...){". In different embodiments, the number of multiple characters can vary; in one specific embodiment, the number of multiple code characters can be randomly determined or predetermined. Prompting the large model to the beginning of the generated unit test code in this way can further improve the accuracy and usability of the generated unit test code.

[0042] Figure 7 A schematic block diagram of a training apparatus for generating unit test code for a large model according to an embodiment of the present disclosure is shown. This apparatus is used to perform, for example... Figure 2 The method shown. (As illustrated) Figure 7 As shown, the device 700 includes:

[0043] The acquisition unit 701 is configured to acquire the first unit code corresponding to the first program unit and the first test code for the first program unit; based on the first unit code and a first prompt part indicating the desired or prohibited code style, construct a first prompt message indicating the generation of test code for the first program unit;

[0044] Training unit 702 is configured to use the first prompt as a training sample and the first test code as the training label corresponding to the training sample, and to retrain the pre-trained target large model using the training sample and the training label.

[0045] This disclosure also provides an electronic device, including a memory and a processor. The memory stores executable code, and when the processor executes the executable code, it implements, for example... Figure 2 The method shown.

[0046] The following can also be referenced Figure 8 It shows a structural schematic diagram of an electronic device 800 suitable for implementing embodiments of the present application. Figure 8 The electronic device 800 shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of this application.

[0047] like Figure 8As shown, the electronic device 800 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 801. The aforementioned processing device 801 may be a general-purpose processor, a digital signal processor (DSP), a microprocessor, or a microcontroller, and may further include an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can perform various appropriate actions and processes based on a program stored in read-only memory (ROM) 802 or a program loaded from storage device 808 into random access memory (RAM) 803. RAM 803 also stores various programs and data required for the operation of the electronic device 800. The processing device 801, ROM 802, and RAM 803 are interconnected via a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.

[0048] Typically, the following devices can be connected to I / O interface 805: input devices 806 including, for example, touchscreens, touchpads, keyboards, mice, etc.; output devices 807 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 808 including, for example, magnetic tapes, hard disks, etc.; and communication devices 809. Communication device 809 allows electronic device 800 to communicate wirelessly or wiredly with other devices to exchange data. Although Figure 8 An electronic device 800 with various devices is shown; however, it should be understood that it is not required to implement or possess all of the devices shown. More or fewer devices may be implemented or possessed alternatively. Figure 8 Each box shown can represent a device or multiple devices as needed.

[0049] Specifically, according to embodiments of this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device 809, or installed from a storage device 808, or installed from a ROM 802. When the computer program is executed by the processing device 801, it performs the functions defined in the training method for generating unit test code for a large model provided in embodiments of this application.

[0050] This disclosure also provides a computer-readable storage medium storing a computer program thereon. When the computer program is executed in a computer, it causes the computer to perform the functions provided in the embodiments of this application. Figure 2 This illustrates a training method for a large model that generates unit test code. Figure 9 This is a schematic diagram illustrating a storage medium for implementing an embodiment of this application. For example, such as... Figure 9 As shown, the storage medium 900 can be a non-transitory computer-readable storage medium used to store non-transitory computer-executable instructions 901. When the non-transitory computer-executable instructions 901 are executed by a processor, a training method for generating a large model of unit test code provided in the embodiments of this application can be implemented. For example, when the non-transitory computer-executable instructions 901 are executed by a processor, one or more steps in the training method for generating a large model of unit test code provided in the embodiments of this application can be performed. For example, the storage medium 900 can be applied in the above-mentioned electronic device. For example, the storage medium 900 can include the memory in the electronic device. The description of the storage medium 900 can be found in the description of the memory in the embodiments of the electronic device, and will not be repeated here. The specific functions and technical effects of the storage medium 900 can be found in the description of the training method for generating a large model of unit test code provided in the embodiments of this application, and will not be repeated here.

[0051] It should be noted that the computer-readable medium in the embodiments of this disclosure may be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium may be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a memory card of a smartphone, a storage component of a tablet computer, a portable computer disk, a hard disk of a personal computer, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In the embodiments of this disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In the embodiments of this disclosure, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, wherein computer-readable program code is carried. The transmitted data signal can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. The computer-readable signal medium can also be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wires, optical fibers, RF (radio frequency), etc., or any suitable combination thereof.

[0052] The aforementioned computer-readable medium may be included in the aforementioned electronic device; or it may exist independently and not assembled into the electronic device. The aforementioned computer-readable medium carries one or more programs, which, when executed by the server, cause the electronic device to implement the training method for generating a large model of unit test code provided in the embodiments of this application.

[0053] Computer program code for performing the operations of embodiments of this disclosure can be written in one or more programming languages ​​or a combination thereof. Programming languages ​​include object-oriented programming languages—such as Java, Smallport, and C++—and conventional procedural programming languages—such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0054] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present disclosure. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, may be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions. The units described in the embodiments of the present disclosure may be implemented in software or hardware. The names of the units do not necessarily constitute a limitation on the unit itself. The functions described above herein may be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: Field Programmable Gate Arrays (FPGAs), Application-Specific Integrated Circuits (ASICs), Application Standard Products (ASSPs), Systems-on-Chip (SOCs), Complex Programmable Logic Devices (CPLDs), and so on.

[0055] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the embodiments for storage media and computing devices are basically similar to the method embodiments, so they are described more simply; relevant parts can be referred to the descriptions of the method embodiments.

[0056] The above description is merely a preferred embodiment of this disclosure and an explanation of the technical principles employed. Those skilled in the art should understand that the scope of this disclosure is not limited to technical solutions formed by specific combinations of the above-described technical features, but should also cover other technical solutions formed by arbitrary combinations of the above-described technical features or their equivalents without departing from the above-described concept. For example, technical solutions formed by substituting the above-described features with (but not limited to) technical features with similar functions disclosed in this disclosure. Furthermore, although the operations are described in a specific order, this should not be construed as requiring these operations to be performed in the specific order shown or in sequential order. In certain environments, multitasking and parallel processing may be advantageous. Similarly, although several specific implementation details are included in the above discussion, these should not be construed as limiting the scope of this disclosure. Certain features described in the context of a single embodiment may also be implemented in combination in a single embodiment. Conversely, various features described in the context of a single embodiment may also be implemented individually or in any suitable sub-combination in multiple embodiments.

[0057] The above detailed embodiments further illustrate the purpose, technical solution, and beneficial effects of the embodiments of the present invention. Although the subject matter has been described using language specific to structural features and / or methodological logic, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. Rather, the specific features and actions described above are merely illustrative forms of implementing the claims. It should be understood that the above are merely specific embodiments of the present invention and are not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made on the basis of the technical solutions of the present invention should be included within the scope of protection of the present invention.

Claims

1. A method for training a large model to generate unit test code, comprising: Obtain the first unit code corresponding to the first program unit, and the first test code for the first program unit; Based on the first unit code and the first prompt section indicating the desired or prohibited code style, construct a first prompt message indicating the generation of test code for the first program unit; Using the first prompt as a training sample and the first test code as the training label corresponding to the training sample, the pre-trained target large model is retrained using the training sample and the training label.

2. The method according to claim 1, wherein, The first program unit calls the target function, and the first test code includes a code segment that simulates the target function; Based on the first unit code and the first prompt section indicating the desired or prohibited code style, construct a first prompt message indicating the generation of test code for the first program unit, including: Based on the first unit code, a first prompt indicating the desired or prohibited code style, and a second prompt indicating the simulation of the first target function called by the first program unit in the generated test code, a first prompt is constructed to indicate the generation of test code for the first program unit.

3. The method according to claim 2, wherein, The code segment simulates the first objective function through the following steps: Set the simulated value corresponding to the first objective function; In response to a call to a first objective function during the execution of the first program unit, the return value of the first objective function is determined based on the simulated value.

4. The method according to claim 2, wherein, The first objective function includes one or more of the following: environment parameter reading function, configuration parameter reading function, and functions contained in other program units.

5. The method according to claim 1, wherein, The target code style is table-driven.

6. The method according to claim 1, further comprising: Obtain the code for the second program unit corresponding to the second program unit; Based on the second unit code and the first prompt section indicating the desired or prohibited code style, construct a second prompt that indicates the generation of test code for the second program unit; Input the second prompt into the retrained target large model to obtain the second test code for the second program unit.

7. The method according to claim 6, wherein, Based on the second unit code and the first prompt section indicating the desired or prohibited code style, construct a second prompt indicating the generation of test code for the second program unit, including: Based on the second unit code, the third prompt section indicating the desired or prohibited code style, and the third prompt section indicating the second target function to be called in the generated test code, construct a second prompt message to indicate the generation of test code for the second program unit.

8. The method according to claim 6, wherein, The second prompt also includes a fourth prompt section, which includes multiple code characters that appear first in the second test code.

9. A training apparatus for generating large models of unit test code, comprising: The acquisition unit is configured to acquire the first unit code corresponding to the first program unit, and the first test code for the first program unit; Based on the first unit code and the first prompt section indicating the desired or prohibited code style, construct a first prompt message indicating the generation of test code for the first program unit; The training unit is configured to use the first prompt as a training sample and the first test code as the training label corresponding to the training sample, and to retrain the pre-trained target large model using the training sample and the training label.

10. A computer-readable storage medium having a computer program stored thereon, which, when executed in a computer, causes the computer to perform the method of any one of claims 1-8.

11. An electronic device comprising a memory and a processor, wherein the memory stores executable code, and the processor, when executing the executable code, implements the method of any one of claims 1-8.