A functional function testing method, device, storage medium and program product

By traversing the function call relationship diagram, and using the pre-trained model to automatically generate the test code of functional functions, the problem of untimely testing in the existing technology is solved, and the effect of quickly generating test code and improving testing efficiency is achieved.

CN119248658BActive Publication Date: 2025-04-29INSPUR SUZHOU INTELLIGENT TECH CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202411767937.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-12-04
Publication Date
2025-04-29
Estimated Expiration
2044-12-04

AI Technical Summary

Technical Problem

When performing functional function testing, the existing technology cannot quickly generate relevant test codes, resulting in untimely testing, unable to quickly feedback the test results, and the time resources for developing test codes are scarce.

Method used

By traversing the function call relationship diagram, the test code of the function function is automatically generated, and the pre-trained model is used to determine the affected functional functions based on the code modification fragment, and the corresponding test code is generated.

Benefits of technology

It realizes that after the functional function development is completed, test code is generated quickly, test time is shortened, code testing efficiency is improved, and test results are promptly feedback.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119248658B_ABST
    Figure CN119248658B_ABST
Patent Text Reader

Abstract

The present invention discloses a function test method, device, storage medium and program product, which relates to the field of software development technology, including: obtaining the code modification fragment corresponding to the code modification of the program to be tested; determining the function affected by the code modification fragment from the preset function call relationship graph to obtain the corresponding function to be tested; the preset function call relationship graph is determined based on the relationship between the preset function functions in the program to be tested; generating the test code corresponding to the function to be tested based on the target pre-trained model, and using the test code to test the function to be tested. The test code of the function function can be automatically generated by traversing the function call relationship graph, which helps to improve the efficiency of code testing.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of software development, and in particular to a functional function testing method, equipment, storage medium and program product. Background Art

[0002] Unit testing is mainly used to perform simple tests on the functions in the program, which can ensure that every line of code in the most basic function has been tested, thereby improving the quality of the program. However, compared with the development of program functions, the time resources for developing test programs are relatively scarce. In actual development situations, it often happens that all program functions have been developed, but the unit test program for testing each function of the program has not yet been developed, resulting in insufficient timeliness in testing and inability to quickly feedback test results.

[0003] At present, unit testing mostly adopts the method of manually writing test code for each function, but it consumes a lot of man-hours and cannot quickly and instantly write corresponding test code for each function. Even after completing the development of all function functions, the program developer still has no time to develop test code, and has no way of knowing whether there are program problems (bugs) in the existing function functions. At this time, if a program problem (bug) is found, it will take more time to modify the original function to meet the correct function behavior, and the immediacy of the test cannot be achieved. And even if there is test code for all function functions, if the program developer only modifies part of the function function code, it is impossible to quickly find the relevant test code, and can only test all the test codes, including the function functions that have not been changed, which will increase the invalid testing time.

[0004] It can be seen that how to improve the efficiency of code testing is a problem that technical personnel in this field need to solve. Summary of the invention

[0005] The purpose of the embodiments of the present invention is to provide a functional function testing method, device, storage medium and program product, which can automatically generate test code for the functional function by traversing the function call relationship graph, which helps to solve the problem of not being able to quickly find relevant test code for function testing and improve the efficiency of code testing.

[0006] In order to solve the above technical problems, in a first aspect, the present invention provides a functional function testing method, comprising:

[0007] Get the code modification snippet corresponding to the code modification of the program to be tested;

[0008] Determine the function affected by the code modification fragment from a preset function call relationship graph to obtain a corresponding function to be tested; the preset function call relationship graph is determined based on the relationship between the preset function functions in the program to be tested;

[0009] Generate test code corresponding to the function to be tested based on the target pre-trained model, and use the test code to test the function to be tested.

[0010] In some embodiments, before determining the functional function affected by the code modification snippet from the preset function call relationship graph, the method further includes:

[0011] Determine the influence relationship between the preset function functions based on the function input parameters and function return values ​​respectively corresponding to the preset function functions in the program to be tested;

[0012] The preset function call relationship graph corresponding to the program to be tested is generated according to the influence relationship and the calling relationship between each of the preset functional functions.

[0013] In some embodiments, determining the functional function affected by the code modification snippet from a preset function call relationship graph includes:

[0014] Determine, according to the position of the code modification fragment in the preset function call relationship graph, a target node where the target function corresponding to the code modification fragment is located;

[0015] Based on the target node and according to the impact relationship and the call relationship, the preset function call relationship graph is traversed to determine the functional function in the preset function call relationship graph that is affected by the code modification fragment.

[0016] In some embodiments, the functional function testing method further comprises:

[0017] If a sub-function of the target function function or a function input parameter of a sub-function of the target function function is affected by the code modification fragment, a first node mark and a second node mark are configured for the target node; the first node mark indicates that the target node is a node that triggers a downward traversal operation, and the second node mark indicates that the target node is a node to be tested;

[0018] If the function return value of the target function is affected by the code modification fragment, a third node mark is configured for the target node; the third node mark indicates that the target node is a node that triggers an upward traversal operation;

[0019] Accordingly, traversing the preset function call relationship graph based on the target node and according to the influence relationship and the call relationship includes:

[0020] Based on the first node tag and the third node tag of the target node and according to the influence relationship and the call relationship, the preset function call relationship graph is traversed.

[0021] In some embodiments, the process of traversing the preset function call relationship graph based on the target node and according to the impact relationship and the call relationship further includes:

[0022] Taking the node traversed based on the target node as a new target node, and continuing to traverse the preset function call relationship graph based on the new target node and according to the influence relationship and the call relationship, until no new node is traversed based on the current target node;

[0023] The function function corresponding to the traversed target node carrying the second node mark is used as the function to be tested.

[0024] In some embodiments, the generating the test code corresponding to the function to be tested based on the target pre-trained model includes:

[0025] Determine whether the function input parameters of the function to be tested include the function return value of the preset external resource function to obtain a corresponding determination result;

[0026] Based on the target pre-trained model and according to the judgment result, a test code corresponding to the function to be tested is generated.

[0027] In some embodiments, the generating the test code corresponding to the function to be tested based on the target pre-trained model and according to the judgment result includes:

[0028] If the function input parameters of the function to be tested do not include the function return value of the preset external resource function, directly generating the test code corresponding to the function to be tested based on the target pre-trained model;

[0029] If the function input parameters of the function to be tested include the function return value of the preset external resource function, a simulation function corresponding to the function to be tested is generated, and a test code corresponding to the function to be tested is generated according to the simulation function based on the target pre-trained model.

[0030] In some embodiments, generating a simulation function corresponding to the function to be tested includes:

[0031] Get the preset simulation function to generate prompt words;

[0032] The preset pre-trained model is used to generate prompt words according to the preset simulation function, and the simulation function corresponding to the function to be tested is generated.

[0033] In some embodiments, the generating the test code corresponding to the function to be tested according to the simulation function based on the target pre-trained model includes:

[0034] Based on the simulation function, a preset vector database is queried to obtain a corresponding query result; the query result includes a log file of the target function corresponding to the simulation function in the preset vector database and the preset external resource function;

[0035] The target pre-trained model is used to generate test code corresponding to the function to be tested according to the simulation function and the query result.

[0036] In some embodiments, the generating the test code corresponding to the function to be tested by using the target pre-trained model and according to the simulated function and the query result includes:

[0037] Get the preset test code generation prompt word;

[0038] The simulation function, the preset test code generation prompt word and the query result are input into the target pre-training model, so as to generate the test code corresponding to the function to be tested by using the target pre-training model.

[0039] In some embodiments, the functional function testing method further comprises:

[0040] Generate a test log for the function to be tested;

[0041] The test log and the test code are saved to a preset vector library so as to generate a new test code based on the preset vector library.

[0042] In some embodiments, the functional function testing method further comprises:

[0043] The target pre-trained model is continuously trained based on the preset vector database so as to generate new test codes based on the trained target pre-trained model.

[0044] In a second aspect, the present invention discloses an electronic device, comprising:

[0045] Memory for storing computer programs;

[0046] A processor is used to execute the computer program to implement the steps of the aforementioned functional function testing method.

[0047] In a third aspect, the present invention discloses a computer-readable storage medium having a computer program stored thereon, and the computer program implements the steps of the aforementioned functional function testing method when executed by a processor.

[0048] In a fourth aspect, the present invention discloses a computer program product, comprising a computer program / instruction, which implements the steps of the aforementioned functional function testing method when executed by a processor.

[0049] It can be seen from the above technical scheme that the present invention can first obtain the code modification fragment corresponding to the code modification being performed on the program to be tested, and then determine the function function affected by the code modification fragment from a preset function call relationship diagram determined based on the relationship between the preset function functions in the program to be tested, so as to obtain the corresponding function to be tested, thereby generating the test code corresponding to the function to be tested based on the target pre-trained model, and using the test code to test the function to be tested.

[0050] The beneficial effect of the present invention is that after each functional function is developed, a corresponding function call relationship graph can be generated. After traversing the function call relationship graph according to the code modification fragment, the functional function affected by the code modification fragment is automatically determined, so that the corresponding test code can be generated by using the pre-trained model. The test of the functional function can be completed in a shorter time, and the test results can be fed back to the program developer, which helps the program developer to know the test results of each functional function in the early stage of program problems, and can improve the efficiency of code testing. BRIEF DESCRIPTION OF THE DRAWINGS

[0051] In order to more clearly illustrate the embodiments of the present invention, the following briefly introduces the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0052] Figure 1 A flow chart of a functional function testing method provided by an embodiment of the present invention;

[0053] Figure 2 A schematic diagram of a function call graph provided by an embodiment of the present invention;

[0054] Figure 3 A node visit flow chart provided by an embodiment of the present invention;

[0055] Figure 4 A flow chart of a specific functional function testing method provided by an embodiment of the present invention;

[0056] Figure 5 A test code generation flow chart provided by an embodiment of the present invention;

[0057] Figure 6 A structural diagram of an electronic device provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0058] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0059] The terms "including" and "having" in the specification of the present invention and the above-mentioned drawings, as well as any variations thereof, are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device including a series of steps or units is not limited to the listed steps or units, but may include steps or units that are not listed.

[0060] In order to enable those skilled in the art to better understand the scheme of the present invention, the present invention is further described in detail below in conjunction with the accompanying drawings and specific implementation methods.

[0061] In actual development situations, the method of manually writing test codes for each function (Function) is often adopted. It often happens that all program functions are developed, but the unit test program for testing each function of the program has not been developed yet, resulting in the test not being timely enough and the test results cannot be fed back quickly. The present invention can use a pre-training model (PTM, Pre-Training Model) to generate a corresponding function call relationship diagram after each function is developed, and automatically determine the function function affected by the code modification fragment according to the code modification fragment to generate the corresponding test code, so that the test of the function function can be completed in a shorter time, thereby improving the efficiency of code testing.

[0062] Next, the functional function testing method provided by the embodiment of the present invention is introduced in detail. Figure 1 A functional function testing method provided in an embodiment of the present invention includes:

[0063] Step S11: Obtain the code modification fragment corresponding to the code modification being performed on the program to be tested.

[0064] In this embodiment, it is first necessary to decide when to start generating the test code for the program to be tested. Specifically, after the program developer has completed developing the program, a function call graph (Function CallGraph) can be generated based on the function code to be tested. And when generating the function call graph of the function, the influence relationship between each preset function function can be determined based on the function input parameters and function return values ​​corresponding to each preset function function in the program to be tested. Then, based on the influence relationship and the calling relationship between each preset function function, a preset function call relationship graph corresponding to the program to be tested is generated. In a specific embodiment, a specific function call graph such as Figure 2 As shown in the figure, the function call graph can be divided into nodes and edges. Each node represents a function. A directed edge represents the calling relationship of the function, specifically, the position relationship where the function is called. And when determining the calling relationship of the function in the function call graph, such as Figure 2 As shown, there are main function main(), data processing function processData(), result saving function saveResults(), data analysis function analyzeData(), data loading function loadData(), initialization function initialize(), file writing function writeToFile(), average value calculation function calculateAverage(), maximum value search function findMaximum(), cleanup function cleanup(), database data reading function readFromDatabase(), file opening function openFile() and file closing function closeFile(). Among them, the initialization function, data processing function and cleanup function are called in the main function. It can be said that the main function calls the initialization function, data processing function and cleanup function, or the main function is the parent function of these three functions, and the initialization function, data processing function and cleanup function are the child functions of the main function; and the relationship between the data analysis function and the average value calculation function is a recursive calling relationship of mutual calling.

[0065] It is also understandable that in actual applications, the relationship between functions also includes other mutually influencing relationships. For example, the child functions within the parent function can also be divided into related functions and unrelated functions, mainly the relationship between the input parameters and the return value between the functions. If the return value of the function Func1() is one of the input parameters of the function Func2(), it means that the two functions Func1 and Func2 have an influencing relationship; if the return value of Func1() has no interactive relationship with the input parameters of the Func3() function, then the two functions are said to have no relationship. The interactive relationship means that the return value of Func1() will not affect the input parameters of Func3() through the operation with any variables in the parent function. In other words, any change in Func1() will not affect the input value of Func3() (including input parameters and common variables used), nor will it affect the return value of Func3(). This can indicate that Func1 and Func3 have no influence relationship; and Func1 and Func3 have no influence relationship, which means that the change of Func1 will affect the function of Func2 but not the function of Func3. If the code change of Func2 does not involve the change of the input parameters, it will not affect the function of Func1 upwards.

[0066] After generating and analyzing the function call graph, in addition to finding out the relationship between functions (nodes) (calling relationship, impact relationship), it is also necessary to define the scope of impact of the newly added or modified code. That is, through the calling relationship and impact relationship, traverse (Traverse) the functions (nodes) on the function call graph and mark which node functions (nodes) must generate new test code and retest. The way of visiting in this embodiment is to first obtain the modified fragment (git commit) of this code, that is, it is necessary to first obtain the code modification fragment corresponding to the code modification of the program to be tested. It can be understood that this code fragment may be a large section of function code, or it may be three or four lines of code modification, and the functions (nodes) that need to be retested are marked by visiting the function call graph.

[0067] Step S12, determining the functional functions affected by the code modification fragment from a preset function call relationship graph to obtain a corresponding function to be tested; the preset function call relationship graph is determined based on the relationship between the preset functional functions in the program to be tested.

[0068] In this embodiment, after determining the preset function call relationship graph based on the relationship between each preset function function in the program to be tested, the function function affected by the code modification fragment can be determined from the preset function call relationship graph to obtain the corresponding function to be tested. When determining the function function affected by the code modification fragment from the preset function call relationship graph, the target node where the target function function corresponding to the code modification fragment is located can be determined based on the position of the code modification fragment in the preset function call relationship graph, and then based on the target node and based on the influence relationship and the call relationship, the preset function call relationship graph is traversed to determine the function function affected by the code modification fragment in the preset function call relationship graph.

[0069] And when traversing the function call graph based on the code modification fragment, it can be based on Figure 3 The visit rules and marking rules shown implement the traversal of the call graph:

[0070] a. The function location where the code snippet is located is used as the function (node) to be tested, referred to as the node to be tested;

[0071] b. Check whether the code snippet directly modifies the sub-function of the function. If so, mark the sub-function as the node to be visited (function to be visited) and the node to be tested (function to be tested);

[0072] c. Check whether the code snippet affects the input parameters of the sub-functions in the function. If so, mark the affected sub-functions as nodes to be visited (functions to be visited) and nodes to be tested;

[0073] d. If the code snippet affects the final return value of the function, then the function is set as the node to be visited upward (function to be visited);

[0074] e. After visiting these code snippets, visit the nodes to be visited (functions to be visited) one by one, and mark the nodes to be tested, the functions (nodes) to be visited upwards, and the functions (nodes) to be visited downwards one by one according to the rules of c and d;

[0075] f. After all the upward visited nodes (functions to be visited) are visited, the downward visited nodes (functions to be visited) are visited, and the downward visited nodes (functions to be visited) and the nodes to be tested are marked according to the rules of c;

[0076] g. After all the upward and downward visited nodes are visited, the node to be tested is finally determined to be the function (node) affected by the modification of the code snippet. Based on the determined node to be tested, the code generation tool can be used to generate the test code and the test environment.

[0077] That is to say, when traversing the function call graph, if the sub-function of the target function function or the function input parameter of the sub-function of the target function function is affected by the code modification fragment, the first node mark and the second node mark are configured for the target node; wherein the first node mark indicates that the target node is a node that triggers the downward traversal operation, and the second node mark indicates that the target node is a node to be tested; if the function return value of the target function function is affected by the code modification fragment, the third node mark is configured for the target node; wherein the third node mark indicates that the target node is a node that triggers the upward traversal operation; so as to traverse the preset function call relationship graph based on the first node mark and the third node mark of the target node and according to the influence relationship and the call relationship. And in the process of traversing the preset function call relationship graph based on the target node, the node traversed based on the target node can also be used as a new target node, and the preset function call relationship graph can be traversed based on the new target node and according to the influence relationship and the call relationship, until no new node is traversed based on the current target node, so that the function function corresponding to the traversed target node carrying the second node mark is used as the function to be tested.

[0078] Step S13: Generate a test code corresponding to the function to be tested based on the target pre-trained model, and use the test code to test the function to be tested.

[0079] In this embodiment, the test code corresponding to the function to be tested can be automatically generated by the pre-trained target pre-training model, and the test code is used to test the function to be tested. In this way, after visiting the entire function call graph and marking each function to be tested, because these function functions are already the most basic function nodes, unit testing can be performed for each function afterwards. Through the above technical scheme, in this embodiment, only the function functions affected by the code snippet can be unit tested at the time point in program development. Since the function test is to test the entire function function, the test time is longer than that of only picking out a few functions affected by the code snippet change. Therefore, the test speed of the unit test in this embodiment is faster than that of the function test (Function Test), and because each function function is separated by input parameters and return values, the design of the test conditions only needs to determine the input conditions and check the output conditions according to the scope of the function function, and a certain test effect can be achieved. At the same time, since the scope of the function function is smaller than the scope of the integrated test, the design of the test conditions can also be relatively simple.

[0080] In this embodiment, the code modification fragment corresponding to the code modification of the program to be tested can be obtained, and then the function function affected by the code modification fragment can be determined from the preset function call relationship diagram determined based on the relationship between the preset function functions in the program to be tested, so as to obtain the corresponding function to be tested, thereby generating the test code corresponding to the function to be tested based on the target pre-trained model, and using the test code to test the function to be tested. In this way, after each function function is developed, the corresponding function call relationship diagram can be generated, and after traversing the function call relationship diagram according to the code modification fragment, the function function affected by the code modification fragment is automatically determined, and the pre-trained model is used to generate content and code generation (Code Generation) related technologies based on artificial intelligence. After each function function is developed, the corresponding test code is automatically generated to generate a unit test of the function function, and the test of the function function can be completed in a shorter time, and the test results are fed back to the program developer, which helps the program developer to know the test results of each function function at the early stage of the program problem, and can improve the efficiency of code testing.

[0081] Based on the previous embodiment, it can be known that the present invention can generate a function call relationship diagram corresponding to a functional function, and generate test code for the functional function affected by the code modification fragment based on the code modification fragment to complete the test of the functional function. Next, the process of generating the test code will be explained in detail in this embodiment. Figure 4 A specific functional function testing method provided by an embodiment of the present invention includes:

[0082] Step S21: Obtain a code modification fragment corresponding to the code modification being performed on the program to be tested.

[0083] Step S22, determining the functional functions affected by the code modification fragment from a preset function call relationship graph to obtain a corresponding function to be tested; the preset function call relationship graph is determined based on the relationship between the preset functional functions in the program to be tested.

[0084] Step S23, determine whether the function input parameters of the function to be tested include the function return value of the preset external resource function to obtain a corresponding judgment result; based on the target pre-trained model and according to the judgment result, generate the test code corresponding to the function to be tested, and use the test code to test the function to be tested.

[0085] In this embodiment, taking into account some specific functions in the functional function, it is possible to determine whether the function input parameters of the function to be tested include the function return value of the preset external resource function to obtain the corresponding judgment result, and then generate the test code corresponding to the function to be tested based on the target pre-trained model and according to the judgment result. Specifically, if the function input parameters of the function to be tested do not include the function return value of the preset external resource function, the test code corresponding to the function to be tested is directly generated based on the target pre-trained model; if the function input parameters of the function to be tested include the function return value of the preset external resource function, a mock function corresponding to the function to be tested is generated, and the test code corresponding to the function to be tested is generated based on the mock function based on the target pre-trained model.

[0086] Regarding the generation of the above test code, it can be understood that the function test in this embodiment is a small-scale basic functional function unit test, so only a simulation function needs to be established to replace certain specific functions. Among them, the above specific functions mostly interact with the program's external environment resources to obtain the return value of the external resource function. For example: accessing a database, a Restful API (Application Programming Interface (API, Application Programming Interface) based on the REST (Representational State Transfer, Representational State Transfer) architectural style) network server that can obtain the return value according to the input parameters, and when testing, the tester cares about whether the program can process the return value of the external resource function. For example: an external resource function that accesses a database may return digital data 1, digital data 0, and empty data (null). In a general real environment, there may be 70 digital data 1, 29 digital data 0, and 1 empty data (null) in the distribution of 100 return value data. If you want to test in a real database environment, you need to run 100 records to get the three different types of data return values. Using a mock function can replace the external function that accesses the database and directly return the three types of data (0, 1, null) to the function to be tested. It can also save the time of accessing the actual database, making the test faster than testing in a real database environment. Finally, the function to be tested processes the result returned by the mock function. If the processing result meets the expected result, the test is successful. If the result does not meet the expected result, the test fails.

[0087] That is, in a specific embodiment, when the function input parameter of the function to be tested includes the function return value of the preset external resource function, the preset simulation function generation prompt word is obtained, and the preset pre-trained model is used to generate the prompt word according to the preset simulation function, and the code generation system with RAG (Retrieval Augmented Generation) function is used to generate the simulation function corresponding to the function to be tested, so as to generate the test code corresponding to the function to be tested according to the simulation function. And it should be pointed out that the simulation function in this embodiment needs to meet the following points.

[0088] a. Rapidly transmit data, reduce test time and increase test efficiency;

[0089] b. Ability to return various boundary condition return values, including some return values ​​that have a low probability of occurring normally (null data);

[0090] c. Ability to generate reasonable return values ​​based on past execution log files (log).

[0091] And if Figure 5 As shown, when generating a simulation function, first, the preset vector database can be queried based on the simulation function to obtain the corresponding query result, and then the target pre-trained model is used to generate the test code corresponding to the function to be tested according to the simulation function and the query result; wherein the query result includes the log file of the target function and the preset external resource function corresponding to the simulation function in the preset vector database. And in a specific embodiment, the preset test code generation prompt word can be obtained, and the simulation function, the preset test code generation prompt word and the query result are input into the target pre-trained model to generate the test code corresponding to the function to be tested using the target pre-trained model.

[0092] That is to say, Figure 5As shown, after finding the affected function to be tested through code snippets and function call graphs, it is necessary to check whether the function to be tested has a function that calls external resources. If so, it is marked as a function that needs to generate a simulation function, and then the function marked as a function that needs to generate a simulation function is input into the RAG code generation system to generate a simulation function. Specifically, before the code is generated, the RAG search results can provide reference code for the simulation function and the log file generated by the execution program to assist in generating the simulation function. And the function to be tested that does not call an external resource function also generates test code through the RAG code generation system. The main difference is that there is no need to prompt the RAG code generation system to generate a simulation function in the prompt word, and directly generate a test function to test the function to be tested. After executing the test of the function to be tested, the test results and the generated test function are reviewed and agreed by the program developer, and the generated test function and test results are input into the vector database (VectorDataBase) of the RAG code generation system. Among them, the vector database is dedicated to the RAG code generation system. It can quickly find similar data based on the vector data converted by the function to be tested, and provide it to the pre-trained model of the RAG code generation system to generate test code.

[0093] In a specific embodiment, the prompt words for generating a simulation function for a pre-trained model may be as follows:

[0094] Prompt 1: sPrompt = "Please refer to the following function to be tested {code of the function to be tested} to find out the external resource function that needs to be called in the function (e.g. access to the database or call to the external RestFul API), and simulate the external resource function, and write a mock function to simulate the input and output of the external resource function". Among them, {} represents the entire text of the function or log. Then input the generated mock function into the vector database for query, find other similar mock functions or related data (input and output logs), and input the output result of the vector database and the following prompt into the code generation pre-training model:

[0095] Prompt 2: sPrompt="Please refer to the following {test function code} and {simulated function code} of the function to be tested. The {log text} output by the function generates the test code for testing the function." In this way, the test code including the simulated function that simulates the external resource function can be generated to test the function to be tested. Based on the above technical solution, it can be understood that when executing the test code, it takes more time to build the test environment. For example, if there is a program that uses a database (DataBase), it is necessary to establish a corresponding test database and test data, and if a program uses the Restful API and remote connection, it is also necessary to establish a corresponding return value program. These environment constructions for the test program also take a long time. However, this embodiment can know which simulation functions of the test environment to prepare when modifying the code, which helps to reduce the testing time and increase the efficiency of feeding back the test results to the program developer. The developer will also have more time and willingness to deal with program errors.

[0096] It should also be pointed out that in this embodiment, a test log of the function to be tested can be generated during code testing, and the test log and test code can be saved to a preset vector database so that new test code can be generated based on the preset vector database. At the same time, in this embodiment, the target pre-trained model can continue to be trained based on the preset vector database so that new test code can be generated based on the trained target pre-trained model. In this way, after the program developer tests the function to be tested, if there is no problem in the user test, or if it can be tested normally after the user's modification, the test function and simulation function generated in this embodiment can be stored in the vector database as a reference example for the next generation of the test function and simulation function, and the log of the test or actual environment execution output can also be entered into the vector database. That is, the more developers participate in the generation of test functions and simulation functions, the more reference examples the vector database will have, thereby gradually improving the quality of the entire test function and simulation function generation. In this embodiment, the data inside the vector database can also be processed and used as training data. Figure 5 The code shown in the figure generates the data of the pre-trained model to further enhance the code generation capability of the pre-trained model. For example, it can be determined whether the relevant data currently stored in the vector database (including but not limited to the data corresponding to each code to be tested) is the data corresponding to the function to be tested that has been tested. If not, the above-mentioned relevant data and the corresponding function to be tested can be used as the training data of the code-generated pre-trained model to continue training the model so as to use the trained pre-trained model to test the function. And when storing the relevant data in the vector database, the data corresponding to the function to be tested that has been tested can be used to update the corresponding historical data in the vector database, so as to continue to train the model using the function to be tested and the updated relevant data. It can be understood that Figure 5The pre-trained model shown in and the above-mentioned pre-trained model can specifically be a large language model. Correspondingly, the code generation pre-trained model can be a specific code generation large language model.

[0097] Through the above technical solution, this embodiment can quickly automatically generate corresponding test codes for the code snippets newly added or modified by the program developer, and automatically mark the functions that need to be tested according to the code snippets modified by the developer, thereby improving the test efficiency and reducing the test time. And because the simulation function of the test environment can be constructed according to the function that needs to be tested in this embodiment, it is possible to know which simulation functions to prepare to replace the test environment when the code is modified, which helps to reduce the test time and increase the efficiency of feeding back the test results to the program developer.

[0098] Furthermore, an embodiment of the present invention also discloses an electronic device, Figure 6 It is a structural diagram of an electronic device according to an exemplary embodiment, and the content in the figure cannot be regarded as any limitation on the scope of use of the present invention. The electronic device may specifically include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25 and a communication bus 26. Among them, the memory 22 is used to store a computer program, and the computer program is loaded and executed by the processor 21 to implement the relevant steps in the functional function testing method disclosed in any of the aforementioned embodiments. In addition, the electronic device in this embodiment may specifically be an electronic computer.

[0099] In this embodiment, the power supply 23 is used to provide working voltage for each hardware device on the electronic device; the communication interface 24 can create a data transmission channel between the electronic device and the external device, and the communication protocol it follows is any communication protocol that can be applied to the technical solution of the present invention, and is not specifically limited here; the input and output interface 25 is used to obtain external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs and is not specifically limited here.

[0100] In addition, the memory 22, as a carrier for storing resources, can be a read-only memory, a random access memory, a disk or an optical disk, etc. The resources stored thereon can include an operating system 221, a computer program 222, etc., and the storage method can be temporary storage or permanent storage.

[0101] The operating system 221 is used to manage and control various hardware devices on the electronic device and the computer program 222, which can be Windows Server, Netware, Unix, Linux, etc. In addition to including a computer program that can be used to complete the function test method performed by the electronic device disclosed in any of the aforementioned embodiments, the computer program 222 can further include a computer program that can be used to complete other specific tasks.

[0102] Furthermore, the present invention also discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, the functional function testing method disclosed above is implemented. The specific steps of the method can refer to the corresponding contents disclosed in the above embodiments, and will not be repeated here.

[0103] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.

[0104] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.

[0105] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.

[0106] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.

[0107] The technical solution provided by the present invention is introduced in detail above. Specific examples are used in this article to illustrate the principle and implementation mode of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the idea of ​​the present invention, there will be changes in the specific implementation mode and application scope. In summary, the content of this specification should not be understood as limiting the present invention.

Claims

1. A functional test method, characterized in that: include: Get the code modification snippet corresponding to the code modification of the program to be tested; Determine the function affected by the code modification fragment from a preset function call relationship graph to obtain a corresponding function to be tested; the preset function call relationship graph is determined based on the relationship between the preset function functions in the program to be tested; Generate a test code corresponding to the function to be tested based on the target pre-trained model, and use the test code to test the function to be tested; The step of generating the test code corresponding to the function to be tested based on the target pre-trained model includes: Determine whether the function input parameters of the function to be tested include the function return value of the preset external resource function to obtain a corresponding determination result; Generate a test code corresponding to the function to be tested based on the target pre-trained model and according to the judgment result; The generating the test code corresponding to the function to be tested based on the target pre-trained model and according to the judgment result includes: If the function input parameters of the function to be tested do not include the function return value of the preset external resource function, directly generating the test code corresponding to the function to be tested based on the target pre-trained model; If the function input parameters of the function to be tested include the function return value of the preset external resource function, a simulation function corresponding to the function to be tested is generated, and a test code corresponding to the function to be tested is generated according to the simulation function based on the target pre-trained model; wherein the simulation function is used to return the function return value of the preset boundary condition, and the function return value includes various types of return values ​​corresponding to the preset external resource function; The generating a simulation function corresponding to the function to be tested includes: Get the preset simulation function to generate prompt words; Using a preset pre-trained model and generating prompt words according to the preset simulation function, the simulation function corresponding to the function to be tested is generated; Correspondingly, the target pre-trained model is used to generate the test code corresponding to the function to be tested according to the simulation function, including: Based on the simulation function, a preset vector database is queried to obtain a corresponding query result; the query result includes a log file of the target function corresponding to the simulation function in the preset vector database and the preset external resource function; The target pre-trained model is used to generate test code corresponding to the function to be tested according to the simulation function and the query result.

2. The performance function testing method according to claim 1, characterized in that: Before determining the functional function affected by the code modification fragment from the preset function call relationship graph, the method further includes: Determine the influence relationship between the preset function functions based on the function input parameters and function return values ​​respectively corresponding to the preset function functions in the program to be tested; The preset function call relationship graph corresponding to the program to be tested is generated according to the influence relationship and the calling relationship between each of the preset functional functions.

3. The performance function testing method according to claim 2, characterized in that: The determining the functional function affected by the code modification fragment from a preset function call relationship graph includes: According to the position of the code modification fragment in the preset function call relationship graph, determine the target node where the target function corresponding to the code modification fragment is located; Based on the target node and according to the impact relationship and the call relationship, the preset function call relationship graph is traversed to determine the functional function in the preset function call relationship graph that is affected by the code modification fragment.

4. The performance function testing method according to claim 3, characterized in that: Also includes: If a sub-function of the target function or a function input parameter of a sub-function of the target function is affected by the code modification fragment, configuring a first node mark and a second node mark for the target node; The first node mark indicates that the target node is a node that triggers a downward traversal operation, and the second node mark indicates that the target node is a node to be tested; If the function return value of the target function is affected by the code modification fragment, configuring a third node mark for the target node; The third node mark indicates that the target node is a node that triggers an upward traversal operation; Accordingly, traversing the preset function call relationship graph based on the target node and according to the influence relationship and the call relationship includes: Based on the first node tag and the third node tag of the target node and according to the influence relationship and the call relationship, the preset function call relationship graph is traversed.

5. The performance function testing method according to claim 4, characterized in that: The process of traversing the preset function call relationship graph based on the target node and according to the influence relationship and the call relationship also includes: Taking the node traversed based on the target node as a new target node, and continuing to traverse the preset function call relationship graph based on the new target node and according to the influence relationship and the call relationship, until no new node is traversed based on the current target node; The function function corresponding to the traversed target node carrying the second node mark is used as the function to be tested.

6. The performance function testing method according to claim 1, characterized in that: The generating the test code corresponding to the function to be tested by using the target pre-trained model and according to the simulation function and the query result includes: Get the preset test code generation prompt word; The simulation function, the preset test code generation prompt word and the query result are input into the target pre-training model, so as to generate the test code corresponding to the function to be tested by using the target pre-training model.

7. The performance function testing method according to any one of claims 1 to 6, characterized in that: Also includes: Generate a test log for the function to be tested; The test log and the test code are saved to a preset vector library so as to generate a new test code based on the preset vector library.

8. The performance function testing method according to claim 7, characterized in that: Also includes: The target pre-trained model is continuously trained based on the preset vector database so as to generate new test codes based on the trained target pre-trained model.

9. An electronic device, characterized in that: include: Memory for storing computer programs; A processor, used to execute the computer program to implement the steps of the functional function testing method as claimed in any one of claims 1 to 8.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, which, when executed by a processor, implements the steps of the functional function testing method as claimed in any one of claims 1 to 8.

11. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instruction is executed by a processor, the steps of the functional function testing method described in any one of claims 1 to 8 are implemented.

Citation Information

Patent Citations

  • Object testing method, object testing device, electronic equipment and readable storage medium

    CN113127362A

  • Test case generation method and device, equipment, medium and product

    CN118093352A

  • Automatic test code test method and device, storage medium and electronic equipment

    CN118503116A