Method, device and storage medium for obtaining function

CN116339742BActive Publication Date: 2026-08-07SHENZHEN HUAWEI CLOUD COMPUTING TECHNOLOGIES CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
SHENZHEN HUAWEI CLOUD COMPUTING TECHNOLOGIES CO LTD
Filing Date
2023-02-28
Publication Date
2026-08-07

AI Technical Summary

Technical Problem

但是相关技术采用的代码生成技术生成函数的精度不高,这样需要用户花费大量时间检查生成的函数

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116339742B_ABST
    Figure CN116339742B_ABST
Patent Text Reader

Abstract

The application discloses a method, device and storage medium for obtaining a function, and belongs to the computer field. The method comprises the following steps: obtaining description information, a function signature and a first test method of a target function to be generated, wherein the description information is used for describing the function implemented by the target function, the function signature is used for identifying the target function, and the first test method is used for testing the target function; generating a plurality of candidate functions based on the first test method, the description information and the function signature; testing each candidate function in the plurality of candidate functions based on the first test method, so as to obtain a test result of the each candidate function; and selecting the target function from the plurality of candidate functions based on the test result of the each candidate function. The application can improve the accuracy of function-level code generation and reduce the time for checking and selecting the generated function by a user.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computers, and in particular to a method, apparatus and storage medium for obtaining functions. Background Technology

[0002] Code generation technology has always been a hot topic in academic research in software engineering and artificial intelligence, and has attracted much attention from industry due to its enormous commercial value. In the past two years, thanks to the achievements of artificial intelligence research in natural language processing and programming language processing, code generation-related technologies have been gradually moved from academic research to practical applications.

[0003] In related technologies, code generation techniques can be used to generate business logic code, which often includes multiple functions. These techniques generate some or all of the functions in the business logic code, thus assisting users in writing the code and improving efficiency. However, the precision of the functions generated by these techniques is not high, requiring users to spend a significant amount of time checking the generated functions. Summary of the Invention

[0004] This application provides a method, apparatus, and storage medium for obtaining functions, so as to improve the accuracy of function-level code generation and reduce the time users spend checking and selecting generated functions. The technical solution is as follows:

[0005] Firstly, this application provides a method for obtaining a function. In this method, a description of the target function to be generated, a function signature, and a first testing method are obtained. The description describes the functionality implemented by the target function, the function signature identifies the target function, and the first testing method tests the target function. Based on the first testing method, the description, and the function signature, multiple candidate functions are generated. Each candidate function is tested using the first testing method to obtain a test result for each candidate function. Based on the test results of each candidate function, a target function is selected from the multiple candidate functions.

[0006] By acquiring the first test method, multiple candidate functions are generated based on the first test method, the description information of the target function, and the function signature. This enriches the information used to generate candidate functions, improves the accuracy of candidate function generation, and thus improves the accuracy of function-level code generation. Furthermore, it improves testing efficiency when testing these multiple candidate functions using the first test method. Moreover, because multiple candidate functions are automatically tested using the first test method, testing efficiency is significantly improved compared to manual testing, reducing the time users spend checking and selecting the generated functions.

[0007] In one possible implementation, in response to an input operation on the business code to be generated, the description information and function signature of the target function input into the business code are obtained. A first test file is displayed, which includes a second test method generated based on the function signature. In response to a modification operation on the first test file, the first test method is obtained, whereby the modification operation modifies and / or supplements the second test method included in the first test file to obtain the first test method.

[0008] Since the second test method is generated based on the function signature, and then the second test method is modified and / or supplemented to obtain the first test method, the amount of content that needs to be modified or supplemented can be reduced. This not only improves the efficiency of obtaining the first test method, but also reduces the time required to obtain the first test method.

[0009] In another possible implementation, in response to the input operation, a first prompt element is displayed, indicating whether to generate a test method. A command generated in response to the first prompt element is executed to retrieve configuration information, including file information for the test framework and the first test file. The test framework includes a test method generation template. Based on the test method generation template, the file information, and the function signature of the target function, the first test file is generated using the test framework.

[0010] The display of the first prompt element, used to suggest whether to generate test methods, allows users to choose whether to use the automatic generation method, providing timely reminders. Additionally, the test framework includes a test method generation template, ensuring the successful generation of the second test method.

[0011] In another possible implementation, the first testing method includes multiple test cases, each including input data and expected output data. A first candidate function is combined with the business code to be generated to obtain target code. The business code to be generated is the business code to which the target function belongs. The multiple candidate functions include the first candidate function. The target code processes the input data included in each test case to obtain the processing result corresponding to each test case. The processing result corresponding to each test case output by the target code is obtained. The expected output data included in each test case and the processing result corresponding to each test case are compared to obtain the test result of the first candidate function. This achieves automatic testing of the multiple candidate functions through the first testing method, reducing the time required for testing the candidate functions.

[0012] In another possible implementation, the target code is compiled. Upon successful compilation, the target code is fed the input data for each test case, allowing the target code to process this input data. This method tests the successfully compiled target code, reducing the amount of test data.

[0013] Secondly, this application provides an apparatus for obtaining a function, used to execute the method in the first aspect or any possible implementation of the first aspect. Specifically, the apparatus includes units for executing the method in the first aspect or any possible implementation of the first aspect.

[0014] Thirdly, this application provides a cluster for acquiring functions, the cluster including at least one computing device, each of the at least one computing device including at least one processor and at least one memory, the at least one memory storing computer-readable instructions; the at least one processor executes the computer-readable instructions to cause the cluster to implement the method in the first aspect or any possible implementation of the first aspect.

[0015] Fourthly, this application provides a computer program product comprising a computer program stored in a computer-readable storage medium, wherein the computer program is loaded by a processor to implement the method described in the first aspect or any possible implementation thereof.

[0016] Fifthly, this application provides a computer-readable storage medium for storing a computer program, which is loaded by a processor to execute the method described in the first aspect or any possible implementation thereof.

[0017] In a sixth aspect, this application provides a chip including a memory and a processor, wherein the memory is used to store computer instructions, and the processor is used to retrieve and execute the computer instructions from the memory to perform the method described in the first aspect or any possible implementation thereof. Attached Figure Description

[0018] Figure 1 This is a schematic diagram of a network architecture provided in an embodiment of this application;

[0019] Figure 2 This is a flowchart of a method for obtaining a function provided in an embodiment of this application;

[0020] Figure 3 This is a schematic diagram of a business code editing interface provided in an embodiment of this application;

[0021] Figure 4 This is a schematic diagram of a first configuration interface provided in an embodiment of this application;

[0022] Figure 5 This is a schematic diagram of a second configuration interface provided in an embodiment of this application;

[0023] Figure 6 This is a schematic diagram illustrating a simultaneous display of a business code editing interface and a first interface provided in an embodiment of this application;

[0024] Figure 7 This is a schematic diagram illustrating a simultaneous display of a business code editing interface, a first interface, and multiple second interfaces provided in an embodiment of this application.

[0025] Figure 8 This is a schematic diagram illustrating the display of syntax errors provided in an embodiment of this application;

[0026] Figure 9 This is a schematic diagram illustrating the number of test samples that have passed the test, provided in an embodiment of this application.

[0027] Figure 10 This is a schematic diagram of a device structure for obtaining a function provided in an embodiment of this application;

[0028] Figure 11 This is a schematic diagram of the structure of a computing device provided in an embodiment of this application;

[0029] Figure 12 This is a schematic diagram of the structure of a cluster for obtaining functions provided in an embodiment of this application;

[0030] Figure 13 This is a schematic diagram of the structure of another cluster for obtaining functions provided in an embodiment of this application. Detailed Implementation

[0031] The embodiments of this application will now be described in further detail with reference to the accompanying drawings.

[0032] Users can use terminal devices to develop business code. Typically, business code includes at least one function. To increase the efficiency of developing business code and reduce the workload of users writing program code, the terminal device can automatically obtain the functions included in the business code and write the obtained functions into the business code.

[0033] In some embodiments, the terminal device has a local code editor that provides users with the ability to edit business code. The terminal device displays a business code editing interface through this code editor, where users can input business code. Optionally, the code editor can be a lightweight editor (Visual Studio Code, VS Code) or an integrated development environment (IDE) or other program development tools.

[0034] In some embodiments, business code typically includes at least one function. The code editor of the terminal device is equipped with a code generation plugin that has the function of automatically generating functions. The terminal device automatically generates the functions included in the business code through this function of the code generation plugin, which can save the user's labor cost of editing business code.

[0035] The detailed implementation process of the functions involved in generating the business code will be discussed later. Figure 2 The method shown in 200 is described in detail here.

[0036] In some embodiments, the function of the generated function is a cloud service, and the terminal device can request the cloud computing device providing the cloud service to generate the functions included in the business code.

[0037] See Figure 1 This application provides a network architecture 100, which includes a cloud computing device 101 and a terminal device 102. The cloud computing device 101 provides cloud services for generating functions and communicates with the terminal device 102. The cloud computing device 101 is a computing device in a cluster.

[0038] When terminal device 102 needs to generate a function for business code, it can send a function generation request message to cloud computing device 101. The function generation request message includes the information required to generate the function.

[0039] The cloud computing device 101 receives the function generation request message, generates the function included in the business code based on the information required to generate the function included in the function generation request message, and sends a function generation response message to the terminal device 102, which includes the generated function.

[0040] Terminal device 102 receives the function generation response message and writes the function included in the function generation response message into the business code.

[0041] The detailed implementation process of the functions included in the business code generated by cloud computing device 101 will be discussed later. Figure 2The method shown in 200 is described in detail here.

[0042] See Figure 2 This application provides a method 200 for obtaining a function, wherein the method 200 is executed by a first device, which may be a terminal device or a device that may be a terminal device. Figure 1 The cloud computing device 101 in the network architecture 100 shown. The method 200 includes the following steps 201 to 205.

[0043] Step 201: The first device obtains the description information and function signature of the target function to be generated. The description information is used to describe the function implemented by the target function, and the function signature is used to identify the target function.

[0044] In some embodiments, the first device is a terminal device, and the first device displays a business code editing interface. Users can enter code statements, including those included in the business code to be generated, in the business code editing interface.

[0045] In some embodiments, the first device has an auto-completion function. When a user enters a code statement into the business code editing interface, the entire code statement is automatically completed based on the partial characters included in the user-entered code statement. For example, suppose a user needs to enter the code statement System.out.println(“a”) into the business code editing interface. When the user enters “sys” in the code statement into the business code editing interface, the first device automatically completes System.out.println(“”), and the user only needs to enter the character 'a' to be printed in the code statement to obtain the code statement System.out.println(“a”).

[0046] Typically, a business logic code consists of at least one function and other content besides that function. Users need to input the individual code statements to be generated in the business logic code editing interface; therefore, the business logic code editing interface includes the currently incomplete business logic code to be generated.

[0047] When a user enters the description and signature of the target function to be generated in the business code editing interface, the first device detects the input operation in the business code to be generated within the business code editing interface and retrieves the description and signature of the target function from the business code editing interface. Optionally, this input operation can be the user's input via a keyboard or virtual keyboard into the business code editing interface.

[0048] When a user enters the target function to be generated in the business code editing interface, the user will first enter the function declaration of the target function in the business code editing interface, and then enter the function signature and description information of the target function.

[0049] When the first device detects a function declaration entered by the user in the business code editing interface, it obtains the function signature and description information of the target function located after the function declaration entered by the user.

[0050] In some embodiments, the first device is a cloud computing device. The terminal device obtains the description information and function signature of the target function to be generated, as well as the business code to be generated included in the business code editing interface. A function generation request message is sent to the first device, which includes the business code to be generated and the description information and function signature of the target function to be generated. The first device receives the function generation request message, obtains the description information and function signature of the target function to be generated from the message, and also obtains the business code to be generated.

[0051] Step 202: The first device acquires the first test method, which is used to test the target function.

[0052] In step 202, the first test method can be obtained through the following operations from 2021 to 2024, which are shown below.

[0053] 2021: When the first device detects an input operation for inputting the function signature and description information of the target function, in response to the input operation, it displays a first prompt element. The first prompt element is used to prompt whether to generate a first test method. The first test method is used to test the target function.

[0054] In some embodiments, the first prompt element may be a prompt button. For example, see Figure 3 The first device responds to the input operation and displays the first interface.

[0055] Optionally, the first interface is a floating interface, hovering above the business code editing interface. The first interface includes a first prompt element, which allows the user to choose whether to generate a first test method. For example... Figure 3As shown, the first prompt element includes the prompt message "Automatically generate test method (create test?)" and two options for the user to choose between "yes" and "no". If the user selects the first option ("yes"), the first option generates a command (i.e., the command generated when the first prompt element is triggered). The first device responds to this command and performs the following 2022 operations. If the user selects the second option ("no"), the first device responds to the second option and, based on the function signature and description information of the target function, calls the code generation plugin in the code editor to generate the target function.

[0056] In some embodiments, the first prompt element is a prompt bar displayed by the code editor, used to ask the user whether to generate a test method corresponding to the target function.

[0057] In some embodiments, the user can configure the first device to automatically display a first prompt element in advance.

[0058] For example, see Figure 4 The first device can display a first configuration interface to the user, where the user can enable the function of automatically prompting the user to generate test methods. When the first device detects that the function of automatically prompting the user to generate test methods has been enabled, it displays a first prompt element in response to the input operation.

[0059] In some embodiments, the first device is a cloud computing device. The first device displays a first configuration interface on a terminal device, where the user can enable the function of automatically prompting the user to generate test methods. The terminal device sends a first instruction to the first device, which instructs the user to enable the function of automatically prompting the user to generate test methods in the first configuration interface. Upon receiving the first instruction, the first device, in response to the input operation, displays a first prompt element on the business code logic interface.

[0060] For example, see Figure 4 The first configuration interface includes an option to "Auto-CreateTest for New Method".

[0061] Users can also configure other settings in the first configuration interface. For example, they can configure "Completion Mode" by setting it to "Fast". Another example is "Function-level Completion" by setting it to "On (no)".

[0062] 2022: The first device responds to the command generated by the first prompt element and obtains configuration information, which includes file information of the test framework and the first test file, and the test framework includes a test method generation template.

[0063] In some embodiments, the configuration information may also include data simulation frameworks and / or test method generation strategies.

[0064] In some embodiments, the file information of the first test file includes the file name of the first test file (which may be the same as the name of the first test method), the storage path of the first test file, and / or the data packet containing the first test file, etc.

[0065] In 2022, the first device, in response to a command triggered by a first prompt element, displays a second configuration interface. This second configuration interface includes multiple test frameworks. The user can select a test framework and input file information for a first test file within the second configuration interface. The first device retrieves the selected test framework and the user-input file information for the first test file from the second configuration interface.

[0066] In some embodiments, the first device is a cloud computing device, and the terminal device sends a command generated by the triggering of a first prompt element to the first device. The first device receives the command and, in response, displays a second configuration interface on the terminal device, allowing the user to select a test framework and input file information for a first test file. The first device receives the second configuration interface returned by the terminal device and retrieves the test framework selected by the user and the file information of the first test file entered by the user from the second configuration interface.

[0067] In some embodiments, the testing framework includes one or more of the following: a Java unit testing framework (JUnit), a unit testing framework supporting Java or Groovy (Spock), or a next-generation testing framework (TestNext, TestNG). Java and Groovy are two programming languages.

[0068] For example, the first device displays as follows Figure 5 The second configuration interface shown includes input elements for "Test destination package", "Test class name", "Test source root" and "Test framework".

[0069] The user can enter the data package containing the first test file (e.g., ...) in the "Test Destination Package" input element of the second configuration interface. Figure 5 The data package shown is "com.github". In the "Test Method Name" input element, enter the file name of the first test file (e.g., ...). Figure 5 The file name shown is "MainTest". In the "Storage Path" input element, select the storage path for the first test file (e.g., ...). Figure 5 The storage path shown is "D: / dev / project / src / test / java", and the test framework is selected in the "Test Framework" input element (e.g., ...). Figure 5 The test framework shown is "JUnit".

[0070] exist Figure 5 In the second configuration interface shown, the "Test Framework" input element is a drop-down list that includes multiple test frameworks, which the user can select.

[0071] The first device reads the data packet containing the first test file "com.github", the file name of the first test file "MainTest", the storage path of the first test file "D: / dev / project / src / test / java", and the test framework "JUnit" from the second configuration interface.

[0072] For example, the second configuration interface also includes an input element for "Test Method Generation Strategy" and / or an input element for "Data Mock Framework," etc. Users can input their test method generation strategy (such as...) in the "Test Method Generation Strategy" input element included in the second configuration interface. Figure 5 The test method generation strategy shown is "Template: Basic". In the second configuration interface, enter the data simulation framework (e.g., ...) in the "Data Simulation Framework" input element. Figure 5 The data simulation framework shown is "Mockito".

[0073] The first device also reads the test method generation strategy "Template: Basic" and / or the data simulation framework "Mockito" from the second configuration interface.

[0074] 2023: The first device generates a template, file information of the first test file, and function signature of the target function based on the test method, and generates a first test file through the test framework. The first test file includes the second test method.

[0075] In 2023, the first device generates a second test method based on the function signature of the model and the objective function generated by the test method, and generates a first test file based on the file information of the first test file. The first test file includes the second test method.

[0076] In some embodiments, the first device generates a second test method based on the test method generation model, the function signature of the objective function, the test method generation strategy, and the data simulation framework.

[0077] In some embodiments, the test method generates a template that includes a function call statement and an assertion statement. The function call statement contains a blank space for the function signature to be called and the required input data. The assertion statement contains a blank space for the expected output data.

[0078] The following is an example of a test method template generation. The function call statement in the generated template is "<output_type> result =<class_name> .<method_name> ( <input> ...)”<output_type> This indicates the type of function call statement, and `method_name` represents the function signature that needs to be filled in. <input> This indicates the input data that needs to be entered.

[0079] The assertion statement in the template generated by this test method is "Assertion.assertEquals(<expected_output> ,result),"expected_output represents the expected output data that needs to be input.

[0080]

[0081] Suppose the function signature of the target function is "String getPlatform(String url)". Combine this function signature "String getPlatform(String url)" with the test method generation model described above to form the second test method shown below. In the second test method, the function call statement is of type String, resulting in the function call statement "String result = Demo.getPlatform(url: "string")". This function call statement invokes the target function "getPlatform" and inputs the data "string1" into it. The target function "getPlatform" then processes the input data "string1" and obtains the result "result".

[0082] The assertion statement is "Assertion.assertEquals(expected: "string2", output: result)". This assertion statement is used to compare whether the expected output data "string2" is the same as the processing result "result". If they are the same, it means that the target function "getPlatform" implements the required function.

[0083]

[0084] In some embodiments, the first device can display business code and the second test method on two separate screens, with the business code and the second test method displayed on two different screens respectively.

[0085] For example, see Figure 6 The first device can display the business code editing interface and the first interface on the same screen. The business code editing interface includes the business code, while the first interface includes the second test method in the first test file.

[0086] In some embodiments, the first device is a cloud computing device, and the first device displays the business code editing interface and the first interface on the same screen on the terminal device. The business code editing interface includes business code, and the first interface includes the second test method in the first test file.

[0087] The second test method in the first test file may have a problem. Users can modify the second test method. For example, users can modify the input data and expected output data in the second test method. That is, the first device may also perform the following 2024 operations.

[0088] 2024: In response to a modification operation on a first test file, a first test method is obtained, the modification operation being used to modify and / or supplement a second test method included in the first test file to obtain the first test method.

[0089] The modified first test method includes multiple test cases, each of which includes input data and expected output data.

[0090] In some embodiments, the first device is a cloud computing device, and the terminal device, in response to a modification operation on the first test file, obtains a first test method, sends the first test method to the first device, and the first device receives the first test method.

[0091] Step 203: The first device generates multiple candidate functions based on the first test method, the description information of the target function, and the function signature of the target function.

[0092] In step 203, based on the first testing method, the description information of the target function, and the function signature of the target function, multiple candidate functions are generated using an algorithm for generating functions.

[0093] In step 203, the information used to generate multiple candidate functions includes not only the description information and function signature of the target function, but also the first test method, thereby enriching the information used to generate multiple candidate functions and improving the accuracy of generating candidate functions.

[0094] In some embodiments, the first device also displays the plurality of candidate functions. Optionally, the first device may display the business code to be generated, the first test method, and the plurality of candidate functions on the same screen.

[0095] For example, see Figure 7 The first device can simultaneously display the business code editing interface, the first interface, and multiple second interfaces. For example, in... Figure 7 In the example shown, the business code editing interface is located on the left side of the first interface, and the multiple second interfaces are located on the right side of the first interface.

[0096] The business code editing interface includes business code, the first interface includes the first test method in the first test file, and any one of the plurality of second interfaces is used to display a candidate function, and each of the plurality of second interfaces displays a different candidate function.

[0097] In some embodiments, the first device is a cloud computing device, and the first device displays the business code editing interface, the first interface, and multiple second interfaces on the same screen on the terminal device.

[0098] Step 204: The first device tests each of the multiple candidate functions based on the first test method and obtains the test result of each candidate function.

[0099] In step 204, the first device obtains the test results of each candidate function through the following operations 2041 to 2044, the operations of 2041-2045 are as follows.

[0100] 2041: The first device checks whether the first candidate function has a syntax error by performing a compilability check on the first candidate function, which includes the first candidate function.

[0101] 2042: If the first candidate function is found to have no syntax errors, then combine the first candidate function with the business code to be generated to obtain the target code.

[0102] The business code to be generated is the code in the business code editing interface. For ease of explanation, any one of the multiple candidate functions will be referred to as the first candidate function. The first device can read the business code to be generated from the business code editing interface and combine it with the first candidate function to obtain the target code. Following the same process described above, each candidate function is combined with the business code to be generated to obtain the target code corresponding to each candidate function.

[0103] 2043: The first device compiles the target code.

[0104] Individual candidate functions cannot be compiled; they must be combined with the business logic code to be generated to form a complete target code before the target code can be compiled. The business logic code to be generated is already compiled and contains no compilation errors.

[0105] When the first device compiles the target code, it can detect whether there are compilation errors in the target code. If there are compilation errors in the target code, it means that there are compilation errors in the candidate functions included in the target code, or that there are errors in external calls or dependencies involved in the compilation and construction of the target code into binary, or that there are syntax errors in the target code after the business code is combined with the candidate functions. If there are no compilation errors in the target code, it means that there are no compilation errors in the candidate functions included in the target code.

[0106] As shown in 2043, compile each of the other target codes to determine whether there are compilation errors in the candidate functions corresponding to each of the other target codes. In this way, it is possible to determine whether there are compilation errors in each candidate function.

[0107] In some embodiments, for a first candidate function, if the first candidate function has syntax errors and / or compilation errors, the first device may display an error indication on a second interface including the first candidate function. If the first candidate function does not have syntax errors or compilation errors, the first device may display a correct indication on the second interface including the first candidate function.

[0108] For example, see Figure 8 You can use "!" in a circle to indicate that a compileability check has found syntax errors in the candidate function, you can use "!" in a triangle to indicate that a compilation error has been found in the candidate function, and you can use "√" to indicate that the candidate function has no syntax errors or compilation errors.

[0109] The first device can obtain the target code corresponding to each candidate function that has no syntax errors and compilation errors, and then perform the following operations on the target code corresponding to each candidate function that has no syntax errors and compilation errors. That is, if the first candidate function has no syntax errors and compilation errors, perform the following test operations 2043-2044 on the target code corresponding to the first candidate function.

[0110] If the first candidate function has no syntax errors and compiles without errors, the second interface used to display the first candidate function includes a test button. Users can trigger the test button to execute the following test operations (2043-2044) on the target code corresponding to the first candidate function.

[0111] For example, see Figure 8 For any candidate function without syntax errors or compilation errors, the second interface displaying the candidate function includes a test button "test". Users can click the test button "test" to trigger the execution of the following test operations 2043-2044 on the target code corresponding to the candidate function.

[0112] In some embodiments, the first device is a cloud computing device, and the terminal device displays a test button "test" on a second interface including the candidate function. When the user clicks the test button, the terminal device sends a test request to the first device, the test request including the function identifier of the candidate function. The first device receives the test request and, based on the function identifier of the candidate function included in the test request, performs the following test operations 2043-2044 on the target code corresponding to the candidate function.

[0113] In some embodiments, the first device may also display a "Test All" button, which the user can trigger to execute the following 2043-2044 tests on the target code corresponding to each candidate function that has no syntax errors or compilation errors.

[0114] For example, see Figure 8 The first device displays the "testall" button. Users can click the "testall" button to trigger the execution of test operations 2043-2044 on the target code corresponding to each candidate function that has no syntax errors or compilation errors.

[0115] In some embodiments, the first device is a cloud computing device. When the user clicks the "Show All Tests" button on the terminal device, the terminal device sends a test request to the first device. The first device receives the test request and, based on the test request, performs the following test operations (2043-2044) on the target code corresponding to each candidate function that has no syntax errors or compilation errors.

[0116] 2044: When the first device successfully compiles the target code, it inputs the input data included in each test case into the target code, so that the target code processes the input data included in each test case.

[0117] When the target code is successfully compiled, it means that the target code has no syntax errors or compilation errors; that is, the candidate functions included in the target code also have no syntax errors or compilation errors. Thus, for any test case in the first test method (for ease of explanation, this test case is referred to as the first test case), the first device inputs the input data included in the first test method into the target code through the first test method, causing the target code to process the input data included in the first test case and obtain the processing result corresponding to the first test case.

[0118] In this process, the first device runs a first test method, which uses function call statements to input the first test sample data into a candidate function within the target function, causing the target code to run. When the execution reaches a candidate function within the target code, the input data from the first test sample in the candidate function is processed to obtain a processing result, which is the processing result corresponding to the first test sample. This processing result is then returned to the first test method.

[0119] Following the above process, the first device takes the input data from each of the other test samples in the first test method and obtains the processing result corresponding to each of the other test samples.

[0120] 2045: The first device obtains the processing result corresponding to each test case of the target code output, compares the expected output data included in each test case with the processing result corresponding to each test case, and obtains the test result of the first candidate function.

[0121] For the processing result corresponding to the first test sample, the first device compares the expected output data included in the first test sample with the processing result corresponding to the first test sample. If the expected output data included in the first test sample and the processing result corresponding to the first test sample are the same, it means that the test of the first test sample has passed. If the expected output data included in the first test sample and the processing result corresponding to the first test sample are different, it means that the test of the first test sample has failed.

[0122] For each of the other test cases, the first device determines whether the test passes for each of the other test cases in the manner described above. The test result of the first candidate function includes the number of test cases that pass the test.

[0123] See Figure 9 The first device also displays the number of test cases that passed the test in a second interface that includes the first candidate function. For example, in Figure 9The second interface, which includes candidate function 1, shows "10 / 10" as the number of test cases that passed, indicating that out of 10 test cases, 10 passed. Figure 9 The second interface, which includes candidate function 2, shows "8 / 10" as the number of test cases that passed the test, indicating that there are a total of 10 test cases, and 8 of them passed the test.

[0124] Step 205: The first device selects the target function from the multiple candidate functions based on the test results of each candidate function, and fills the target function into the business code to be generated.

[0125] In some embodiments, the test results of the first candidate function include the number of test cases passed by the target code corresponding to the first candidate function. The first device can select the candidate function with the most passed test cases as the target function; or, the first device can select a candidate function whose number of passed test cases exceeds a threshold as the target function. The target function is then filled into the business code to be generated.

[0126] In some embodiments, the first device is a cloud computing device. After selecting the target function, the first device sends the target function to the terminal device. The terminal device receives the target function and fills it into the business code to be generated.

[0127] In some embodiments, the first device may select at least one candidate function that has passed the most test cases as the candidate objective function; or, the first device may select at least one candidate function that has passed more than a certain number of test cases as the candidate objective function.

[0128] In other words, the first device can select multiple candidate objective functions and display an "Accept" button on a second interface that includes any of the candidate objective functions. The user can then select a candidate objective function as the objective function using the "Accept" button. The first device then obtains the objective function selected by the user and fills it into the business code to be generated in the business code editing interface.

[0129] For example, see Figure 9 The first device displays an "accept" button on a second interface that includes any candidate objective function. The user can select a candidate objective function from the second interface by clicking the "accept" button. The first device then retrieves the objective function from the second interface and fills it into the business code to be generated in the business code editing interface.

[0130] In some embodiments, the first device is a cloud computing device. After selecting at least one candidate objective function, the first device displays an "Accept" button on a second interface on the terminal device that includes the candidate objective function for any given candidate objective function. The user can select the candidate objective function as the objective function using the "Accept" button. The terminal device obtains the objective function selected by the user and fills it into the business code to be generated included in the business code editing interface.

[0131] If none of the candidate objective functions meet the user's requirements, the user can modify the candidate objective functions. The first device then obtains the modified objective functions and fills them into the business code to be generated in the business code editing interface. Alternatively,

[0132] If none of the candidate objective functions meet the user's requirements, the user can trigger the first device to regenerate the function according to the steps 202-205 above.

[0133] In this embodiment, a first device acquires the description information, function signature, and first testing method of the target function to be generated. Based on the first testing method, the description information and function signature of the target function, multiple candidate functions are generated. Since the information required to generate the candidate functions is incorporated into the first testing method, the accuracy of the generated candidate functions can be improved, i.e., the accuracy of function-level code generation is improved. Each candidate function is tested using the first testing method, and a test result is obtained for each candidate function. Based on the test results of each candidate function, the target function is selected from the multiple candidate functions. Because the generated candidate functions have high accuracy, the probability of selecting a candidate function that implements the required function from the more accurate candidate functions is higher. This eliminates the need for the user to manually spend a lot of time reviewing, understanding, and modifying the generated candidate functions, saving manpower costs and reducing the time the user spends checking and selecting the generated functions.

[0134] See Figure 10 This application provides a device 1000 for obtaining functions, which can be deployed in... Figure 1 The network architecture 100 shown can be used on terminal devices or cloud computing devices, or the device 100 can be deployed on... Figure 2 On a first device of the method 200 shown. The device 1000 includes:

[0135] The acquisition unit 1001 is used to acquire the description information, function signature and first test method of the target function to be generated. The description information is used to describe the function implemented by the target function, the function signature is used to identify the target function, and the first test method is used to test the target function.

[0136] Processing unit 1002 is used to generate multiple candidate functions based on the first test method, the description information, and the function signature;

[0137] The processing unit 1002 is also used to test each of the plurality of candidate functions based on the first test method, and obtain the test result of each candidate function;

[0138] The processing unit 1002 is also configured to select a target function from the plurality of candidate functions based on the test results of each candidate function.

[0139] Optionally, for details on how unit 1001 obtains the description information of the target function, the function signature, and the detailed implementation process of the first test method, please refer to [link to documentation]. Figure 2 The details of steps 201 and 202 of method 200 shown will not be explained in detail here.

[0140] Optionally, for details on how processing unit 1002 generates multiple candidate functions, please refer to [link to relevant documentation]. Figure 2 The details of step 203 of method 200 shown will not be explained in detail here.

[0141] Optionally, for details on how processing unit 1002 obtains the test results for each candidate function, please refer to [link to relevant documentation]. Figure 2 The details of step 204 of method 200 shown will not be explained in detail here.

[0142] Optionally, for details of the process by which processing unit 1002 selects the target function from the plurality of candidate functions, see [link to relevant documentation]. Figure 2 The details of step 205 of method 200 shown will not be explained in detail here.

[0143] Optionally, the acquisition unit 1001 is used for:

[0144] In response to an input operation on the business code to be generated, obtain the description information and function signature of the target function input into the business code by the input operation;

[0145] The first test file is displayed, which includes a second test method generated based on the function signature.

[0146] In response to a modification operation on a first test file, a first test method is obtained, wherein the modification operation is used to modify and / or supplement a second test method included in the first test file to obtain the first test method.

[0147] Optionally, for the detailed implementation process of obtaining the description information and function signature of the target function input to the business code by the acquisition unit 1001, please refer to [link to relevant documentation]. Figure 2 The details of step 201 of method 200 shown will not be explained in detail here.

[0148] Optionally, for detailed implementation of the acquisition unit 1001 displaying the first test file, please refer to [link / reference]. Figure 2 The details of step 202 of method 200 shown will not be explained in detail here.

[0149] Optionally, for details on the implementation of the first test method obtained by unit 1001, please refer to [link / reference]. Figure 2 The details of step 202 of method 200 shown will not be explained in detail here.

[0150] Optionally, the device 1000 further includes a display unit 1003;

[0151] Display unit 1003 is configured to respond to the input operation by displaying a first prompt element, the first prompt element being used to prompt whether a test method should be generated;

[0152] The acquisition unit 1001 is also used for:

[0153] In response to the command generated by the first prompt element, obtain configuration information, which includes file information of the test framework and the first test file, and the test framework includes a test method generation template;

[0154] Based on this testing method, a template, the file information, and the function signature of the target function are generated, and the first test file is generated through the testing framework.

[0155] Optionally, for details on how display unit 1003 displays the first prompt element, please refer to [link / reference]. Figure 2 The details of step 202 of method 200 shown will not be explained in detail here.

[0156] Optionally, for details on the implementation process of obtaining configuration information by unit 1001, please refer to [link / reference]. Figure 2 The details of step 202 of method 200 shown will not be explained in detail here.

[0157] Optionally, for details on how unit 1001 generates the first test file using the test framework, please refer to [link to documentation]. Figure 2 The details of step 202 of method 200 shown will not be explained in detail here.

[0158] Optionally, the first testing method includes multiple test cases, each test case including input data and expected output data.

[0159] Processing unit 1002 is used for:

[0160] The first candidate function is combined with the business code to be generated to obtain the target code. The business code to be generated is the business code to which the target function belongs. The multiple candidate functions include the first candidate function. The target code is used to process the input data included in each test case to obtain the processing result corresponding to each test case.

[0161] Obtain the processing result corresponding to each test case output by the target code;

[0162] By comparing the expected output data included in each test case with the corresponding processing result for each test case, the test result of the first candidate function is obtained.

[0163] Optionally, the processing unit 1002 combines the first candidate function with the business code to be generated to obtain the target code. For a detailed implementation process, see [link to relevant documentation]. Figure 2 The details of step 2042 in method 200 shown will not be explained in detail here.

[0164] Optionally, for details on how processing unit 1002 obtains the processing result corresponding to each test case of the target code output, please refer to [link to relevant documentation]. Figure 2 The details of step 2044 in method 200 shown will not be explained in detail here.

[0165] Optionally, for details of how processing unit 1002 obtains the test results of the first candidate function, please refer to [link to relevant documentation]. Figure 2 The details of step 2045 of method 200 shown will not be explained in detail here.

[0166] Optionally, the processing unit 1002 is further configured to:

[0167] Compile the target code;

[0168] When the target code is successfully compiled, the input data included in each test case is input into the target code, so that the target code processes the input data included in each test case.

[0169] Optionally, for details of the compilation process of the target code by the processing unit 1002, please refer to [link to relevant documentation]. Figure 2 The details of step 2043 in method 200 shown will not be explained in detail here.

[0170] Optionally, for details of the implementation process of the processing unit 1002 inputting the input data for each test case into the target code, please refer to [link to relevant documentation]. Figure 2 The details of step 2044 in method 200 shown will not be explained in detail here.

[0171] The acquisition unit 1001, processing unit 1002, and display unit 1003 can all be implemented in software or in hardware. For example, the implementation of processing unit 1002 will be described below. Similarly, the implementation of acquisition unit 1001 and display unit 1003 can refer to the implementation of processing unit 1002.

[0172] As an example of a software functional unit, processing unit 1002 may include code running on a computing instance. The computing instance may include at least one of a physical host (computing device), a virtual machine, and a container. Further, the aforementioned computing instance may be one or more. For example, processing unit 1002 may include code running on multiple hosts / virtual machines / containers. It should be noted that the multiple hosts / virtual machines / containers used to run the code may be distributed in the same region or in different regions. Further, the multiple hosts / virtual machines / containers used to run the code may be distributed in the same availability zone (AZ) or in different AZs, each AZ including one or more geographically proximate data centers. Typically, a region may include multiple AZs.

[0173] Similarly, multiple hosts / virtual machines / containers used to run this code can be distributed within the same Virtual Private Cloud (VPC) or across multiple VPCs. Typically, a VPC is set up within a region. Communication between two VPCs within the same region, as well as between VPCs in different regions, requires a communication gateway to be set up within each VPC to enable interconnection between VPCs.

[0174] As an example of a hardware functional unit, the processing unit 1002 may include at least one computing device, such as a server. Alternatively, the processing unit 1002 may also be a device implemented using an application-specific integrated circuit (ASIC) or a programmable logic device (PLD). The PLD may be implemented using a complex programmable logical device (CPLD), a field-programmable gate array (FPGA), generic array logic (GAL), or any combination thereof.

[0175] The processing unit 1002 includes multiple computing devices that can be distributed in the same region or in different regions. Similarly, the processing unit 1002 can be distributed in the same Availability Zone (AZ) or in different AZs. Likewise, the processing unit 1002 can be distributed in the same Virtual Private Cloud (VPC) or in multiple VPCs. These multiple computing devices can be any combination of computing devices such as servers, ASICs, PLDs, CPLDs, FPGAs, and GALs.

[0176] It should be noted that, in other embodiments, the acquisition unit 1001 and the processing unit 1002 can be used to execute any step in the method provided in any of the above embodiments, and the display unit 1003 can be used to execute any display step in the method provided in any of the above embodiments. The steps implemented by the acquisition unit 1001, the processing unit 1002, and the display unit 1003 can be specified as needed. By implementing different steps in the method provided in any of the above embodiments through the acquisition unit 1001, the processing unit 1002, and the display unit 1003, all functions of the device 1000 for acquiring functions can be realized.

[0177] In this embodiment, since the acquisition unit acquires the first testing method, the processing unit generates multiple candidate functions based on the first testing method, the description information of the target function, and the function signature. This enriches the information used to generate the candidate functions and improves the accuracy of the generated candidate functions, i.e., improves the accuracy of function-level code generation. Furthermore, the processing unit improves testing efficiency when testing these multiple candidate functions using the first testing method. Moreover, since the processing unit automatically tests multiple candidate functions using the first testing method, compared to manual testing, testing efficiency is significantly improved, reducing the time required for users to check and select the generated functions.

[0178] See Figure 11 This application provides a computing device 1100. For example, the computing device 1100 may be... Figure 1 The cloud computing device 101 or terminal device 102 in the network architecture shown, or, is Figure 2 The first device of method 200 shown.

[0179] like Figure 11 As shown, the computing device 1100 includes a bus 1102, a processor 1104, a memory 1106, and a communication interface 1108. The processor 1104, the memory 1106, and the communication interface 1108 communicate with each other via the bus 1102. The computing device 1100 can be a server or a terminal device. It should be understood that this application does not limit the number of processors and memories in the computing device 1100.

[0180] Bus 1102 can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. Buses can be categorized as address buses, data buses, control buses, etc. For ease of representation, Figure 11 The bus 1104 may be represented by a single line, but this does not mean that there is only one bus or one type of bus. The bus 1104 may include a path for transmitting information between various components of the computing device 1100 (e.g., memory 1106, processor 1104, communication interface 1108).

[0181] The processor 1104 may include any one or more processors such as a central processing unit (CPU), a graphics processing unit (GPU), a microprocessor (MP), or a digital signal processor (DSP).

[0182] The memory 1106 may include volatile memory, such as random access memory (RAM). The processor 1104 may also include non-volatile memory, such as read-only memory (ROM), flash memory, hard disk drive (HDD), or solid state drive (SSD).

[0183] See Figure 11 The memory 1106 stores executable program code, and the processor 1104 executes the executable program code to implement the following respectively. Figure 10 The functions of the acquisition unit 1001, processing unit 1002, and display unit 1003 in the illustrated device 1000 are used to implement the method provided in any of the above embodiments. That is, the memory 1106 stores instructions for executing the method provided in any of the above embodiments. Alternatively,

[0184] The communication interface 1103 uses transceiver modules such as, but not limited to, network interface cards and transceivers to enable communication between the computing device 1100 and other devices or communication networks.

[0185] This application also provides a data processing cluster. The data processing cluster includes at least one computing device. The computing device can be a server, such as a central server, an edge server, or a local server in a local data center. In some embodiments, the computing device can also be a terminal device such as a desktop computer, a laptop computer, or a smartphone.

[0186] like Figure 12 As shown, the data processing cluster includes at least one computing device 1100. The memory 1106 of one or more computing devices 1100 in the data processing cluster may store the same instructions for performing the methods provided in any of the above embodiments.

[0187] In some possible implementations, the memory 1106 of one or more computing devices 1100 in the data processing cluster may also store partial instructions for executing the above-described communication methods. In other words, a combination of one or more computing devices 1100 can jointly execute instructions for performing the methods provided in any of the above embodiments.

[0188] In some possible implementations, one or more computing devices in the cluster processing the data can be connected via a network. This network can be a wide area network (WAN), a local area network (LAN), or similar. Figure 13 One possible implementation is shown. For example... Figure 13 As shown, the two computing devices 1100A and 1100B are connected via a network. Specifically, they are connected to the network through the communication interfaces in each computing device.

[0189] In this type of possible implementation, the memory 1106 in the computing device 1100A stores the execution of, for example Figure 10 The instructions for the acquisition unit 1001 and processing unit 1002 in the illustrated embodiment are shown. Meanwhile, the memory 1106 in the computing device 1100B stores instructions for performing operations such as... Figure 10 Instructions for the function of the display unit 1003 in the illustrated embodiment.

[0190] It should be understood that Figure 13 The functions of computing device 1100A shown can also be performed by multiple computing devices 1100. Similarly, the functions of computing device 1100B can also be performed by multiple computing devices 1100.

[0191] This application also provides another cluster for acquiring functions. The connection relationships between the computing devices in this cluster can be similarly referenced. Figure 13The connection method of the cluster of acquisition functions is different. In addition, the memory 1106 of one or more computing devices 1100 in the cluster of acquisition functions can store the same instructions for executing the methods provided in any of the above embodiments.

[0192] In some possible implementations, the memory 1106 of one or more computing devices 1100 in the cluster of the acquisition function may also store partial instructions for executing the methods provided in any of the above embodiments. In other words, a combination of one or more computing devices 1100 can jointly execute instructions for executing the methods provided in any of the above embodiments.

[0193] This application also provides a computer program product containing instructions. The computer program product may be a software or program product containing instructions, capable of running on a computing device or stored on any usable medium. When the computer program product is run on at least one computing device, it causes the at least one computing device to perform the methods provided in any of the above embodiments.

[0194] This application also provides a computer-readable storage medium. The computer-readable storage medium can be any available medium capable of being stored by a computing device, or a data storage device such as a data center containing one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid-state drive). The computer-readable storage medium includes instructions that instruct a computing device to perform the method provided in any of the above embodiments.

[0195] Those skilled in the art will understand that all or part of the steps of the above embodiments can be implemented by hardware or by a program instructing related hardware. The program can be stored in a computer-readable storage medium, such as a read-only memory, a disk, or an optical disk.

[0196] The above description is merely an optional embodiment of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the principles of this application should be included within the protection scope of this application.

Claims

1. A method for obtaining a function, characterized in that, The method includes: In response to an input operation on the business code to be generated, the description information and function signature of the target function input into the business code by the input operation are obtained. The description information is used to describe the function implemented by the target function, and the function signature is used to identify the target function. Display a first test file, which includes a second test method, the second test method being generated based on the function signature; In response to a modification operation on the first test file, a first test method is obtained. The modification operation is used to modify and / or supplement the second test method included in the first test file to obtain the first test method. The first test method is used to test the target function. Based on the first testing method, the description information, and the function signature, multiple candidate functions are generated using an algorithm for generating functions; Based on the first testing method, each of the plurality of candidate functions is tested to obtain the test result of each candidate function; The target function is selected from the plurality of candidate functions based on the test results of each candidate function.

2. The method as described in claim 1, characterized in that, The method further includes: In response to the input operation, a first prompt element is displayed, which prompts whether to generate a test method; In response to the command generated by the first prompt element being triggered, configuration information is obtained, the configuration information including file information of the test framework and the first test file, the test framework including a test method generation template; Based on the test method, the template, the file information, and the function signature of the target function are generated, and the first test file is generated through the test framework.

3. The method as described in claim 1 or 2, characterized in that, The first testing method includes multiple test cases, each test case including input data and expected output data. The step of testing each of the plurality of candidate functions based on the first testing method to obtain a test result for each candidate function includes: The first candidate function is combined with the business code to be generated to obtain the target code. The business code to be generated is the business code to which the target function belongs. The multiple candidate functions include the first candidate function. The target code is used to process the input data included in each test case to obtain the processing result corresponding to each test case. Obtain the processing result corresponding to each test case output by the target code; The test result of the first candidate function is obtained by comparing the expected output data included in each test sample with the processing result corresponding to each test sample.

4. The method as described in claim 3, characterized in that, The method further includes: Compile the target code; Upon successful compilation of the target code, the input data included in each test case is input into the target code, so that the target code processes the input data included in each test case.

5. An apparatus for obtaining a function, characterized in that, The device includes: The acquisition unit is configured to, in response to an input operation on the business code to be generated, acquire description information and function signature of the target function input into the business code by the input operation, wherein the description information describes the functionality implemented by the target function and the function signature identifies the target function; display a first test file, wherein the first test file includes a second test method, the second test method being generated based on the function signature; and, in response to a modification operation on the first test file, acquire a first test method, wherein the modification operation modifies and / or supplements the second test method included in the first test file to obtain the first test method, the first test method being used to test the target function. The processing unit is configured to generate multiple candidate functions based on the first testing method, the description information, and the function signature using an algorithm for generating functions; The processing unit is further configured to test each of the plurality of candidate functions based on the first testing method, and obtain the test result of each candidate function; The processing unit is further configured to select the target function from the plurality of candidate functions based on the test results of each candidate function.

6. The apparatus as claimed in claim 5, characterized in that, The device also includes a display unit; The display unit is configured to display a first prompt element in response to the input operation, the first prompt element being configured to prompt whether a test method should be generated; The acquisition unit is further configured to acquire configuration information in response to a command generated by the first prompt element being triggered. The configuration information includes file information of the test framework and the first test file. The test framework includes a test method generation template. The acquisition unit is further configured to generate a template, the file information, and the function signature of the target function based on the test method, and generate the first test file through the test framework.

7. The apparatus as described in claim 5 or 6, characterized in that, The first testing method includes multiple test cases, each test case including input data and expected output data. The processing unit is used for: The first candidate function is combined with the business code to be generated to obtain the target code. The business code to be generated is the business code to which the target function belongs. The multiple candidate functions include the first candidate function. The target code is used to process the input data included in each test case to obtain the processing result corresponding to each test case. Obtain the processing result corresponding to each test case output by the target code; The test result of the first candidate function is obtained by comparing the expected output data included in each test sample with the processing result corresponding to each test sample.

8. The apparatus as claimed in claim 7, characterized in that, The processing unit is further configured to: Compile the target code; Upon successful compilation of the target code, the input data included in each test case is input into the target code, so that the target code processes the input data included in each test case.

9. A data processing cluster, characterized in that, The cluster includes at least one computing device, each of the at least one computing device including at least one processor and at least one memory, the at least one memory storing computer-readable instructions; the at least one processor executes the computer-readable instructions to cause the cluster to perform the method as described in any one of claims 1-4.

10. A computer storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the method as described in any one of claims 1-4.

11. A computer program product comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the method as described in any one of claims 1-4.

Citation Information

Patent Citations

  • Testing method and device

    CN111984476A

  • Code editing method and device, server, user equipment and storage medium

    CN112817583A