Automated test script management method, device, computer equipment and storage medium
By using large language models to generate object code and automatically manage automated test scripts, the problem of high maintenance and management of automated test scripts in the existing technology is solved, and efficient test script management and maintenance is achieved.
Patent Information
- Application Number
- CN202410484324.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-22
- Publication Date
- 2025-02-11
- Estimated Expiration
- 2044-04-22
AI Technical Summary
In the prior art, automated test scripts require manual maintenance and management, resulting in high maintenance costs and low efficiency.
By inputting the code generation prompt word into the large language model, the object code is generated, and the file path information is extracted from the object code, and the target file in the automatic test project is matched. If the target file is not matched, a new test file is generated and added to the project; if the target file is matched, the target file is updated according to the difference between the target file and the target code.
Whether it is creating new test projects or updating test projects, it can effectively reduce the workload of manually writing test scripts, improve testing efficiency, and reduce manual workload and test project maintenance costs.
Smart Images

Figure CN118445178B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of software testing technology, and in particular to an automated test script management method, apparatus, computer equipment and storage medium. Background Art
[0002] In the software development process, interface automation testing is a key link to ensure that various system components can work together normally and an effective means to improve testing efficiency. Traditionally, the writing of interface automation test cases mostly relies on manual coding and is inefficient. With the development of artificial intelligence technology, it is gradually possible to use artificial intelligence technology to generate automated test scripts on demand. However, after obtaining the script, it is still necessary to manually manage and maintain the script, which cannot be well applied in actual test scenarios and has a high maintenance cost. Summary of the invention
[0003] The purpose of this application is to solve at least one of the above-mentioned technical deficiencies, especially the defect that the automated test scripts in the prior art need to be maintained and managed manually.
[0004] In a first aspect, an embodiment of the present application provides an automated test script management method, comprising:
[0005] Input the code generation prompt words into the large language model to obtain the target code;
[0006] Extract file path information from the object code;
[0007] According to the file path information, match and retrieve the target file corresponding to the target code in the automated test project;
[0008] If the target file is not matched, a new test file is generated according to the target code, and the new test file is added to the automated test project;
[0009] If the target file is matched, the target file is updated according to the difference between the code in the target file and the target code.
[0010] In one embodiment, the automated test project includes folders corresponding to each layer in the preset layered architecture, the folders are used to store test files of all interfaces of the layer, the file names of the test files are the same as the corresponding interface names, and the file path information includes the target layer name and the target interface name; according to the file path information, matching retrieval is performed in the directory of the automated test project, including:
[0011] Determine the target search path according to the target layer name and the target interface name;
[0012] In an automated test project, check whether there are files matching the target search path.
[0013] In one embodiment, adding a new test file to an automated test project includes:
[0014] Determine the target storage path according to the target layer name;
[0015] Add new test files to the automated test project according to the target storage path.
[0016] In one of the embodiments, the preset layered architecture includes an interface call layer, a business layer, an assertion layer, a scenario layer and a data driver layer; the data driver layer is used to provide test data for the scenario layer; the scenario layer is used to encapsulate the automated test project into a test scenario and define test parameters in the test scenario; the business layer is used to convert the test parameters into interface parameters; the interface call layer is used to request the corresponding interface according to the interface parameters and obtain response data; the assertion layer is used to assert the response data.
[0017] In one embodiment, updating the target file according to the difference between the code in the target file and the target code includes:
[0018] Read the code in the target file to get the original code;
[0019] If the target code has a new method, then add the new method to the original code to obtain an updated code; the new method is a method with the same name that does not exist in the original code;
[0020] Update the target file according to the updated code.
[0021] In one embodiment, updating the target file according to the difference between the code in the target file and the target code includes:
[0022] Read the code in the target file to get the original code;
[0023] If there are methods with the same name in the target code and the original code, compare the input parameters of each pair of methods with the same name;
[0024] If the input parameters are different, add the method with the same name in the target code to the original code to get the updated code;
[0025] If the input parameters are the same, the method with the same name in the original code is replaced with the method with the same name in the target code to obtain the updated code;
[0026] Update the target file according to the updated code.
[0027] In one embodiment, comparing the input parameters of each pair of methods with the same name includes:
[0028] Compare in turn whether the number of input parameters is the same, whether each parameter in the input parameter has a corresponding parameter with the same name, and whether each pair of parameters with the same name have the same data type;
[0029] If the comparison results are all yes, then the input parameters are determined to be the same;
[0030] Otherwise, it is determined that the input parameters are different.
[0031] In one embodiment, updating the target file according to the update code includes:
[0032] When matching the target file, record the path of the target file;
[0033] Generate updated test files based on updated code;
[0034] Based on the path of the target file, replace the target file with the updated test file.
[0035] In one of the embodiments, the code generation hint includes target interface information and a test script template.
[0036] In a second aspect, an embodiment of the present application provides an automated test script management device, comprising:
[0037] The model interaction module is used to input the code generation prompt words into the large language model to obtain the target code;
[0038] An information extraction module is used to extract file path information from the target code;
[0039] A matching and retrieval module is used to match and retrieve the target file corresponding to the target code in the automated test project according to the file path information;
[0040] The first processing module is used to generate a new test file according to the target code when no target file is matched, and add the new test file to the automated test project;
[0041] The second processing module is used to update the target file according to the difference between the code in the target file and the target code when the target file is matched.
[0042] In a third aspect, an embodiment of the present application provides a computer device comprising one or more processors and a memory, wherein the memory stores computer-readable instructions, and when the computer-readable instructions are executed by one or more processors, the steps of the automated test script management method in any of the above embodiments are executed.
[0043] In a fourth aspect, an embodiment of the present application provides a storage medium, in which computer-readable instructions are stored. When the computer-readable instructions are executed by one or more processors, the one or more processors execute the steps of the automated test script management method in any of the above embodiments.
[0044] It can be seen from the above technical solutions that the embodiments of the present application have the following advantages:
[0045] Based on the automated test script management method in this embodiment, by inputting the test script generation prompt words into the large language model, the target code that meets the test requirements is obtained. The file path information involved is then extracted from the generated target code, and the target file corresponding to the target code is matched and retrieved in the automated test project according to the file path information. If a matching target file cannot be found, a new test file is generated according to the target code and added to the automated test project. If a matching target file can be found in the test project, it is updated according to the difference between the code in the target file and the target code. This solution can be used both in new test projects and updated test projects. The coding ability of the large language model can greatly reduce the workload of manually writing test scripts and improve test efficiency. The target code generated by the large language model can be automatically integrated into the automated test project, which is convenient for the subsequent maintenance and use of the automatically generated code, further reducing the manual workload and the maintenance cost of the test project. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0047] Figure 1 A flowchart of an automated test script management method provided by one embodiment of the present application;
[0048] Figure 2 A schematic diagram of a process for matching and retrieving target files in one embodiment of the present application;
[0049] Figure 3 A schematic diagram of a process for adding a new test file to an automated test project in one embodiment of the present application;
[0050] Figure 4 A schematic diagram of a process for updating a target file in one embodiment of the present application;
[0051] Figure 5This is a schematic diagram of a process for updating a target file in another embodiment of the present application;
[0052] Figure 6 A schematic diagram of a module of an automated test script management device provided by an embodiment of the present application;
[0053] Figure 7 An internal structure diagram of a computer device provided for one embodiment of the present application. DETAILED DESCRIPTION
[0054] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0055] This application embodiment provides an automated test script management method, see Figure 1 , including steps S102 to S110.
[0056] S102, inputting the code generation prompt words into the large language model to obtain the target code.
[0057] It can be understood that the code generation prompt refers to the text used to instruct the large language model to generate the corresponding automated test script, and these texts carry the need for the user to generate automated test code. Automated test code is an executable code used to complete specific test tasks in interface testing. The large language model is a large-scale neural network model based on massive corpus training, with powerful natural language understanding and generation capabilities, and can understand the intention contained in the text input by the user, thereby realizing on-demand text generation. The large language model here can be a publicly used third-party model, such as Chatgpt, Claude, etc. By accessing the open interfaces of these third-party models, the generation of target code can be achieved. The large language model can also be a dedicated model trained by itself. It should be noted that the large language model selected in this embodiment should have coding capabilities and can write executable automated interface test code. In this embodiment, various test requirements for the original designed interface can be generated separately in the early stage of software development. It can also be generated separately for various test requirements of the newly added interface after the software is launched. All test-related test files will be collected in the automated test project, and this embodiment can dynamically produce new target codes for the automated test project according to user needs. It can be used to add new test files in automated testing projects, and can also use the target code to add, modify, and replace test files.
[0058] After receiving the target code fed back by the large language model, the code analysis tool can be used to perform static analysis and format optimization to improve the code quality. The code analysis tool can be selected according to the language type of the target code. For example, FindBugs, PMD, etc. can be used for Java, and pylint can be used for Python. The analysis information of the code analysis tool will carry problem indications related to the target code, which indicate the location and type of the problem in the target code. Since the problem prompt is generally not directly output in a form with complete semantics (for example, output in the form of key-value pairs, error type codes, etc.), at this time, the interpretation method of the problem prompt can be input to the large language model first to form a context to inform the large language model of the correspondence between the data and the problem in the problem prompt. Then input the problem indication to the large language model so that it can modify the target code and obtain the modified target code.
[0059] S104, extracting file path information from the target code.
[0060] It can be understood that the file path information refers to the information about the storage path of the test file corresponding to the target code and the storage path in the automated test project. The automated test project in this embodiment is a project file formed by the collection of all test files of the software test. The storage of each test file in the automated test project will be classified according to certain storage rules, and the basis of classification will be reflected in the code corresponding to each test file, so the target code also carries information about the storage location of the corresponding file in the automated test project. By extracting this part of information, the file path information corresponding to the target code can be obtained.
[0061] For example, in some embodiments, the file name of the test file is the same as the corresponding interface name. According to the total path of the automated test project and the interface name, the complete path of the test file can be combined. Therefore, the interface name can be used as file path information. When instructing the large language model to generate the target code, it will be instructed to add the interface name of the interface targeted by the target code in the form of a comment in the target code. Before the interface name, a retrieval mark for extracting the interface name can be added to facilitate the extraction of the interface name. For example, interface:getUserInfo. Among them, interface: is a retrieval mark, and the interface name is getUserInfo.
[0062] S106, matching and retrieving the target file corresponding to the target code in the automated test project according to the file path information.
[0063] It can be understood that what is stored in the automated test project are test files, and the content in the test files is the code. If you want to use the target code in the automated test project, you need to choose different ways to convert the target code into a test file according to the situation. Specifically, the situation here can be divided into whether the target code generated this time already has a related test file. If not, it is necessary to create a brand new test file based on the target code. If so, it is necessary to update the target code to its corresponding test file, that is, the target file. The file path information is related to the storage path of the target file. If the target code is for a brand new test requirement, there will be no corresponding target file in the automated test project, and the target file cannot be matched according to the file path information. On the contrary, the target file can be matched in the automated test project. These two different matching results will correspond to step S108 and step S110 respectively.
[0064] S108: If the target file is not matched, a new test file is generated according to the target code, and the new test file is added to the automated test project.
[0065] It can be understood that if the target file is not matched in the automated test project based on the file path information, it means that a new test file needs to be created in the automated test project based on the target file, that is, a new test file. For example, if a new interface is added to the software, it is necessary to add a test file related to the interface to the automated test project. At this time, you can write code to generate prompt words as needed, and call the large language model to generate the corresponding target code. Based on this target code, generate a new test file and add it to the automated test project according to the file path information.
[0066] The generation of the newly added test file includes saving the target code as a test file in a preset format and naming it according to a unified naming rule and the naming information extracted from the target code. Since the file path information reflects the storage location of the test file corresponding to the target code in the automated test project, the newly added test file is the test file corresponding to the target code, and the newly added test file can be stored in the automated test project according to the instructions of the file path information.
[0067] S110: If the target file is matched, the target file is updated according to the difference between the code in the target file and the target code.
[0068] It can be understood that if the target file is matched in the automated test project according to the file path information, it means that the content that exists in the target code but not in the code in the target file needs to be added to the target file. For example, for the interface opened by the background database, three types of data A, B, and C are currently obtained from the interface, and there is code for testing these three data acquisition methods in the test file of the interface in the automated test project. When it is necessary to obtain D data from the interface, the test D data acquisition method should be added to the test file of the interface. At this time, the code generation prompt word can be written as needed, and the large language model can be called to generate the corresponding target code. According to the difference between the target code and the code in the test file corresponding to the interface, the test file is updated. Specifically, after finding the difference between the code in the target file and the target code, the appropriate update method can be selected according to the different types of differences to update the target file, so that the part that the code in the target file does not have is completed. The specific update method can be to directly modify the content of the target file, or to generate a new test file with updated content, and directly overwrite the original target file with the new test file.
[0069] Based on the automated test script management method in this embodiment, by inputting the test script generation prompt words into the large language model, the target code that meets the test requirements is obtained. The file path information involved is then extracted from the generated target code, and the target file corresponding to the target code is matched and retrieved in the automated test project according to the file path information. If a matching target file cannot be found, a new test file is generated according to the target code and added to the automated test project. If a matching target file can be found in the test project, it is updated according to the difference between the code in the target file and the target code. This solution can be used both in new test projects and updated test projects. The coding ability of the large language model can greatly reduce the workload of manually writing test scripts and improve test efficiency. The target code generated by the large language model can be automatically integrated into the automated test project, which is convenient for the subsequent maintenance and use of the automatically generated code, further reducing the manual workload and the maintenance cost of the test project.
[0070] In one of the embodiments, in software engineering design, the software architecture is often designed according to the layered idea, that is, the software system is divided into multiple levels of models, each level is responsible for specific functions or tasks, and can communicate and call other levels. The preset layered architecture is the architecture of the automated testing project in this embodiment, which is composed of multiple levels. Therefore, when designing the storage structure of files in the automated testing project, they will also be classified and stored according to the same layered idea. The general directory includes folders corresponding to each layer in the preset layered architecture, and the folders are used to store test files for all interfaces in this layer. The names of these folders are also designed according to the names of the corresponding layers. The file name of the test file is the same as the corresponding interface name. That is, in the corresponding folder of a certain layer, each test file corresponds to an interface that needs to be tested in that layer, and all methods that need to be tested in that interface are included in the corresponding test file. Based on the design of this storage structure, please refer to Figure 2 , according to the file path information, a matching search is performed in the directory of the automated test project, including step S202 and step S204.
[0071] S202, determining a target search path according to a target layer name and a target interface name.
[0072] It can be understood that the file path information in this embodiment includes the target layer name and the target interface name. The interface that the target code tests specifically is called the target interface, and the layer where the target interface is located in the preset layered architecture is called the target layer. The target interface name is the name of the target interface, and the target layer name refers to the name of the target layer. In the storage structure design in this embodiment, each layer has a corresponding folder under the general directory of the automated test project, and the name of the folder is the same as the corresponding layer name. The general directory path of the automated test project is known. By combining the general directory path with the layer name that needs to be accessed, the path of the folder corresponding to the layer that needs to be accessed can be obtained.
[0073] Furthermore, this embodiment needs to check whether the target file exists in the target layer, and the total directory path is combined with the target layer name to obtain the complete access path of the target layer. To check whether the target file exists in a specific folder, you can try to read the file according to the complete path of the target file. If the file can be read, it means that the target file exists, otherwise it means that it does not exist. Since the test files in the corresponding folders of each layer use the name of the targeted interface as their own file names, the complete access path of the target layer is combined with the target interface name to obtain the complete access path of the target file, that is, the target retrieval path. By trying to read the file corresponding to the target retrieval path, it can be determined whether the target file exists in the folder corresponding to the target layer. This embodiment makes full use of the hierarchical file storage structure of the automated test project and improves the efficiency and reliability of matching retrieval. Through flexible configuration and mapping mechanisms, it can adapt to the hierarchical architecture of different test projects and improve the applicability of the method.
[0074] Based on this, when instructing the large language model to generate the target code, it is necessary to instruct it to add the target interface name and target layer name to the target code. It can be added in the form of comments, adding corresponding search marks before the target interface name and target layer name, so as to facilitate the extraction of the target layer name and target interface name from the target code through regular expressions or string processing methods. For example, add interface:getUserInfo and layer:data to the target code respectively. Among them, interface: is the search mark corresponding to the target interface name, and the target interface name is getUserInfo. layer: is the search mark corresponding to the target layer name, and the target layer name is data.
[0075] S204, in the automated test project, searching whether there is a file matching the target search path.
[0076] It can be understood that after obtaining the target search path, it is necessary to read the file in the automated test project. According to the result of the file reading, it can be determined whether the target file exists in the automated test project. Specifically, if the file is read according to the target search path, it means that the target file exists in the automated test project. Otherwise, it means that the target file does not exist in the automated test project. Since the target search path is the complete access path of the target file, there is no need to traverse the entire automated test project. It is highly targeted when performing retrieval, which greatly improves the efficiency of matching retrieval.
[0077] In one of the embodiments, the preset layered architecture includes an interface call layer, a business layer, an assertion layer, a scenario layer, and a data driver layer. The data driver layer is used to provide test data for the scenario layer. Its main responsibility is to store and manage various test data required for the test scenario, and provide these data for the upper scenario layer. These test data can come from various data sources, such as CSV files, databases, API interfaces, etc. The data driver layer is responsible for collecting, cleaning and organizing the data. The data driver layer provides a standardized data access interface so that the scenario layer can easily call the required test data without having to worry about the specific storage format of the data.
[0078] The scenario layer is used to encapsulate the automated test project into test scenarios and define test parameters in the test scenarios. Its main responsibility is to divide the automated test project into multiple repeatable test scenarios and define the test parameters required for each scenario. The scenario layer calls the test data provided by the data driver layer, converts it into test parameters, and provides input for the downstream business layer and interface call layer.
[0079] The business layer is used to convert test parameters into interface parameters. Its main responsibility is to receive test parameters from the scenario layer and convert them into the parameter format required by the corresponding interface call layer. The business layer writes the corresponding data conversion logic according to the definition of the interface to be tested to ensure that the test parameters can be correctly mapped to the interface parameters. The business layer can also perform operations such as data verification and formatting to ensure the correctness and legality of the parameters.
[0080] The interface call layer is used to request the corresponding interface according to the interface parameters and obtain the response data. Its main responsibility is to receive the interface parameters from the business layer, call the corresponding interface through network requests, and obtain the response data of the interface. The interface call layer can also perform error handling, retry mechanisms, etc. to ensure the reliability of interface calls.
[0081] The assertion layer is used to assert the response data. Its main responsibility is to receive the response data from the interface call layer and perform assertion checks on it according to the expected test results. The assertion layer defines a series of assertion rules, such as response status code, response data structure, response data content, etc., to verify whether the behavior of the interface meets expectations. The assertion layer can also generate test reports based on the assertion results.
[0082] In one embodiment, the code generation prompt includes target interface information and test script template. It can be understood that the target interface information refers to the information related to the target interface when testing the specific functions of the target interface. The target interface information required for different test requirements is different, and the required information can be extracted from the interface document. For example, in the automated test project using the preset layered architecture, the target interface information required by the interface call layer includes the target interface definition, input parameter type, input parameter format, target interface name, etc. The test script template refers to a code structure template for writing test cases, which contains common test framework syntax and test steps. Including the test script template in the prompt can help the large language model generate a code structure that meets the requirements of the test framework. The test script templates used for different test requirements are different and should be designed according to the specific situation. For example, in the automated test project using the preset layered architecture, each layer is responsible for different functions, and the test steps included in the test phase will also be different, thereby affecting the design of the test script template. In some embodiments, business demand information can also be added to the code generation prompt, and the business demand information is a description of the functions related to the test. The large language model can be made to better understand the interface test needs, thereby optimizing the target code.
[0083] In one embodiment, see Figure 3 , adding the new test file to the automated test project, including step S302 and step S304.
[0084] S302, determining a target storage path according to the target layer name.
[0085] It can be understood that the target layer name refers to the name of the target layer, and the target layer name can be extracted from the file path information. The automated test project uses a preset hierarchical architecture for classified storage. Each layer corresponds to a folder for storing the test files of that layer, and the name of the folder is the same as the corresponding layer name. The total directory path of the automated test project is known. By combining the total directory path with the layer name to be accessed, the path of the folder corresponding to the layer to be accessed can be obtained. New test files need to be stored in the folder corresponding to the target layer. By combining the target layer name with the total directory path, the complete access path of the target layer can be obtained, which is the target storage path.
[0086] S304, adding the newly added test file to the automated test project according to the target storage path.
[0087] It is understandable that after determining the target storage path for the newly added test file, it needs to be actually added to the file system of the automated test project. This process can be to directly save the target code in a preset format to the target storage path, or to first save the target code in a default folder and then transfer it to the automated test project through a file transfer instruction.
[0088] In one embodiment, see Figure 4 , updating the target file according to the difference between the code in the target file and the target code, including steps S402 to S406.
[0089] S402, read the code in the target file to obtain the original code.
[0090] It is understandable that after finding the target file in the automated test project, it is necessary to compare the difference between the code in the target file and the target code. Therefore, it is necessary to read the code in the target file first, and the result of the reading is the original code. This can be done through relevant file operation commands, such as the open() instruction in the python language. If the command used in the matching retrieval is the read command, this step only assigns the read content to a variable, which is convenient for subsequent difference comparison.
[0091] S404: If the target code has a new method, then add the new method to the original code to obtain an updated code.
[0092] It can be understood that by comparing the names of each method in the target code and the original code, methods that exist in the target code but not in the original code can be found. These methods are called newly added methods. This part of the method in the target code needs to be added to the original method to obtain the updated code. When writing code, the name of the method and the function of the method match each other. The method in the target code that has a different name from the original code is the newly added method. Therefore, the specific comparison method can be to parse the abstract syntax trees of the target code and the original code respectively, and extract all the methods they include respectively. Match the name of each method in the target code with the name of each method in the original code one by one, mark the method that does not have the same name in the target code as a newly added method, and add the code related to the newly added method to the original code to obtain the updated code.
[0093] S406, updating the target file according to the update code.
[0094] It can be understood that in order to update the target file, its complete access path needs to be known. When the target file is matched, the path of the target file can be recorded. After obtaining the path, the write instruction can be used to directly write the new method into the target file, and the content in the target file becomes the update code. It is also possible to add the content of the new method to the variable corresponding to the original code, delete the content in the target file using the delete command, and write the content of the variable into the target file. It is also possible to add the content of the new method to the variable corresponding to the original code, and then save the variable as an update test file according to the corresponding naming rules and default storage location, and then replace the target file with the update test file according to the path of the target file.
[0095] In one embodiment, see Figure 5 , updating the target file according to the difference between the code in the target file and the target code, including steps S502 to S510.
[0096] S502, read the code in the target file to obtain the original code.
[0097] It is understandable that after finding the target file in the automated test project, it is necessary to compare the difference between the code in the target file and the target code. Therefore, it is necessary to read the code in the target file first, and the result of the reading is the original code. This can be done through relevant file operation commands, such as the open() instruction in the python language. If the command used in the matching retrieval is the read command, this step only assigns the read content to a variable, which is convenient for subsequent difference comparison.
[0098] S504: If there are methods with the same name in the target code and the original code, compare the input parameters of each pair of methods with the same name.
[0099] It is understandable that when writing code, the name of the method matches the function of the method. When comparing the target code and the original code, if methods with the same name are found in both, it is necessary to further determine whether these methods with the same name need to be updated. The key is to compare whether the input parameters of the two methods with the same name are the same, and select the processing methods in step S506 and step S508 for processing according to the comparison results.
[0100] The specific comparison process can be carried out in sequence from the three dimensions of the number of input parameters, whether the input parameters correspond one-to-one, and whether the corresponding input parameters have the same data type. That is, compare whether the number of input parameters is the same, whether each parameter in the input parameters of the same-name method of the target code and the original code has a corresponding parameter of the same name, and whether each pair of parameters of the same name has the same data type. If the comparison results are all yes, the input parameters are determined to be the same. Otherwise, the input parameters are determined to be different. Arranging the comparison order in this way can improve the efficiency of the comparison. The comparison of the number of input parameters is very simple. If the number is different, the comparison can be stopped directly and the input parameters are determined to be different. If the number of input parameters is the same, each input parameter of each pair of methods with the same name can be further matched one by one according to the parameter name. As long as one input parameter of the same-name method cannot find the same input parameter, the comparison can be stopped and the input parameters are determined to be different. If each parameter in the input parameters of the same-name method of the target code and the original code has a corresponding input parameter of the same name, the data type of each pair of input parameters with the same name is further compared. As long as the data types of a pair of input parameters with the same name are different, the comparison can be stopped and the input parameters are determined to be different. Otherwise, the input parameters can be determined to be the same.
[0101] S506, if the input parameters are not the same, then add the method with the same name in the target code to the original code to obtain the updated code.
[0102] It can be understood that the type of input parameters is related to the function and logic inside the method. If the input parameters are different, it means that a new method with similar test functions but different internal logic needs to be added to the target file. At this time, the code of the method with the same name can be added to the original code to obtain the updated code.
[0103] S508, if the input parameters are the same, the method with the same name in the original code is replaced with the method with the same name in the target code to obtain an updated code.
[0104] It can be understood that if the input parameters are the same, it means that the internal logic of the method with the same name in the target file needs to be modified. At this time, the method with the same name in the original code needs to be replaced with the method with the same name in the target code to obtain the updated code.
[0105] S510, updating the target file according to the update code.
[0106] It can be understood that in order to update the target file, it is necessary to know its complete access path, and the path of the target file can be recorded when the target file is matched. After obtaining the path, for step S506, the method with the same name in the target code can be directly written into the target file using a write instruction, and the content in the target file becomes the update code. For step S508, the content related to the method with the same name in the target file can be deleted using a delete instruction, and the method with the same name in the target code can be written into the target file using a write instruction, and the content in the target file becomes the update code. The variable corresponding to the original code can also be modified, and the content in the target file can be deleted using a delete command, and the content of the variable can be written into the target file. It can also be modified that the variable corresponding to the original code is stored in the variable, and the variable is saved in the default position according to the corresponding naming rule, and then according to the path of the target file, the target file is replaced with this file.
[0107] This application embodiment provides an automated test script management device. Figure 6 , including a model interaction module 610, an information extraction module 620, a matching retrieval module 630, a first processing module 640 and a second processing module 650.
[0108] The model interaction module 610 is used to input the code generation prompt words into the large language model to obtain the target code. The information extraction module 620 is used to extract the file path information from the target code. The matching retrieval module is used to match and retrieve the target file corresponding to the target code in the automated test project according to the file path information 630. The first processing module 640 is used to generate a new test file according to the target code when the target file is not matched, and add the new test file to the automated test project. The second processing module 650 is used to update the target file according to the difference between the code in the target file and the target code when the target file is matched.
[0109] In one embodiment, the automated test project includes folders corresponding to each layer in the preset hierarchical architecture, and the folders are used to store test files of all interfaces in the layer. The file names of the test files are the same as the corresponding interface names, and the file path information includes the target layer name and the target interface name. The matching retrieval module 630 is used to determine the target retrieval path according to the target layer name and the target interface name; in the automated test project, it is searched whether there is a file matching the target retrieval path.
[0110] In one of the embodiments, the first processing module 640 is used to determine a target storage path according to a target layer name; and add a new test file to the automated test project according to the target storage path.
[0111] In one of the embodiments, the preset layered architecture includes an interface call layer, a business layer, an assertion layer, a scenario layer and a data driver layer; the data driver layer is used to provide test data for the scenario layer; the scenario layer is used to encapsulate the automated test project into a test scenario and define test parameters in the test scenario; the business layer is used to convert the test parameters into interface parameters; the interface call layer is used to request the corresponding interface according to the interface parameters and obtain response data; the assertion layer is used to assert the response data.
[0112] In one embodiment, the second processing module 650 is used to read the code in the target file to obtain the original code; if there is a new method in the target code, the new method is added to the original code to obtain an updated code; the new method is a method with the same name that does not exist in the original code; and the target file is updated according to the updated code.
[0113] In one embodiment, the second processing module 650 is used to read the code in the target file to obtain the original code; if there are methods with the same name in the target code and the original code, the input parameters in each pair of methods with the same name are compared; if the input parameters are different, the methods with the same name in the target code are added to the original code to obtain updated code; if the input parameters are the same, the methods with the same name in the original code are replaced with the methods with the same name in the target code to obtain updated code; and the target file is updated according to the updated code.
[0114] In one embodiment, the second processing module 650 is used to compare in sequence whether the number of input parameters is the same, whether each parameter in the input parameters has a corresponding parameter with the same name, and whether each pair of parameters with the same name has the same data type; if the comparison results are all yes, it is determined that the input parameters are the same; otherwise, it is determined that the input parameters are not the same.
[0115] In one embodiment, the second processing module 650 is used to record the path of the target file when matching the target file; generate an update test file according to the update code; and replace the target file with the update test file according to the path of the target file.
[0116] In one of the embodiments, the code generation hint includes target interface information and a test script template.
[0117] For the specific limitations of the automated test script management device, please refer to the limitations of the automated test script management method above, which will not be repeated here. Each module in the above-mentioned automated test script management device can be implemented in whole or in part by software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory in the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules. It should be noted that the division of modules in the embodiment of the present application is schematic and is only a logical function division. There may be other division methods in actual implementation.
[0118] An embodiment of the present application provides a computer device, including one or more processors and a memory, wherein computer-readable instructions are stored in the memory. When the computer-readable instructions are executed by the one or more processors, the following are performed: inputting a code generation prompt word into a large language model to obtain a target code; extracting file path information from the target code; matching and retrieving a target file corresponding to the target code in an automated testing project based on the file path information; if the target file is not matched, generating a new test file based on the target code, and adding the new test file to the automated testing project; if the target file is matched, updating the target file based on the difference between the code in the target file and the target code.
[0119] In one of the embodiments, the automated testing project includes folders corresponding to each layer in a preset hierarchical architecture, the folders are used to store test files for all interfaces of this layer, the file name of the test file is the same as the corresponding interface name, and the file path information includes the target layer name and the target interface name; when the computer-readable instructions are executed by one or more processors, the following are executed: determining a target retrieval path based on the target layer name and the target interface name; in the automated testing project, searching whether there are files that match the target retrieval path.
[0120] In one embodiment, when the computer-readable instructions are executed by one or more processors, the following are performed: determining a target storage path according to a target layer name; and adding a new test file to an automated test project according to the target storage path.
[0121] In one embodiment, when the computer-readable instructions are executed by one or more processors, the following are performed: reading the code in the target file to obtain the original code; if there is a new method in the target code, adding the new method to the original code to obtain an updated code; the new method is a method with the same name that does not exist in the original code; and updating the target file according to the updated code.
[0122] In one embodiment, when the computer-readable instructions are executed by one or more processors, the following is performed: reading the code in the target file to obtain the original code; if there are methods with the same name in the target code and the original code, comparing the input parameters in each pair of methods with the same name; if the input parameters are different, adding the method with the same name in the target code to the original code to obtain an updated code; if the input parameters are the same, replacing the method with the same name in the original code with the method with the same name in the target code to obtain an updated code; and updating the target file according to the updated code.
[0123] In one embodiment, when the computer-readable instructions are executed by one or more processors, the following are performed: comparing in sequence whether the number of input parameters is the same, whether each parameter in the input parameters has a corresponding parameter with the same name, and whether each pair of parameters with the same name has the same data type; if the comparison results are all yes, it is determined that the input parameters are the same; otherwise, it is determined that the input parameters are not the same.
[0124] In one embodiment, when the computer-readable instructions are executed by one or more processors, the following are performed: when a target file is matched, a path of the target file is recorded; an update test file is generated according to the update code; and according to the path of the target file, the target file is replaced with the update test file.
[0125] Indicatively, Figure 7 As shown, Figure 7 A schematic diagram of the internal structure of a computer device provided in an embodiment of the present application. Figure 7 The computer device 700 includes a processing component 702, which further includes one or more processors, and a memory resource represented by a memory 701, for storing instructions executable by the processing component 702, such as an application. The application stored in the memory 701 may include one or more modules, each corresponding to a set of instructions. In addition, the processing component 702 is configured to execute instructions to perform the steps of the automated test script management method of any of the above embodiments.
[0126] The computer device 700 may further include a power supply component 703 configured to perform power management of the computer device 700 , a wired or wireless model interface 704 configured to connect the computer device 700 to the model, and an input / output (I / O) interface 705 .
[0127] An embodiment of the present application provides a storage medium, in which computer-readable instructions are stored. When the computer-readable instructions are executed by one or more processors, the one or more processors execute: inputting a code generation prompt word into a large language model to obtain a target code; extracting file path information from the target code; matching and retrieving a target file corresponding to the target code in an automated testing project based on the file path information; if the target file is not matched, generating a new test file based on the target code, and adding the new test file to the automated testing project; if the target file is matched, updating the target file based on the difference between the code in the target file and the target code.
[0128] In one of the embodiments, the automated testing project includes folders corresponding to each layer in a preset hierarchical architecture, the folders are used to store test files for all interfaces of the layer, the file name of the test file is the same as the corresponding interface name, and the file path information includes a target layer name and a target interface name; when the computer-readable instructions are executed by one or more processors, the one or more processors execute: determining a target retrieval path based on the target layer name and the target interface name; and searching in the automated testing project whether there are files that match the target retrieval path.
[0129] In one embodiment, when the computer-readable instructions are executed by one or more processors, the one or more processors execute: determining a target storage path according to a target layer name; and adding a new test file to an automated test project according to the target storage path.
[0130] In one embodiment, when the computer-readable instructions are executed by one or more processors, the one or more processors execute: reading the code in the target file to obtain the original code; if there is a new method in the target code, adding the new method to the original code to obtain an updated code; the new method is a method with the same name that does not exist in the original code; and updating the target file according to the updated code.
[0131] In one embodiment, when the computer-readable instructions are executed by one or more processors, the one or more processors execute: reading the code in the target file to obtain the original code; if there are methods with the same name in the target code and the original code, comparing the input parameters in each pair of methods with the same name; if the input parameters are different, adding the method with the same name in the target code to the original code to obtain updated code; if the input parameters are the same, replacing the method with the same name in the original code with the method with the same name in the target code to obtain updated code; and updating the target file according to the updated code.
[0132] In one embodiment, when the computer-readable instructions are executed by one or more processors, the one or more processors execute: comparing in sequence whether the number of input parameters is the same, whether each parameter in the input parameters has a corresponding parameter with the same name, and whether each pair of parameters with the same name has the same data type; if the comparison results are all yes, it is determined that the input parameters are the same; otherwise, it is determined that the input parameters are not the same.
[0133] In one embodiment, when the computer-readable instructions are executed by one or more processors, the one or more processors execute: when matching a target file, recording the path of the target file; generating an updated test file based on the update code; and replacing the target file with the updated test file based on the path of the target file.
[0134] 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.
[0135] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The various embodiments can be combined as needed, and the same or similar parts can refer to each other.
[0136] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. An automated test script management method, characterized in that: The automated test script is used to perform interface testing, and the automated test script management method includes: Input the code generation prompt word into the large language model to obtain the target code; the target code is an executable code used to complete the test task in the interface test, the test file corresponding to the target code is stored in the automated test project, the file name of the test file is the same as the corresponding interface name, the automated test project includes a folder corresponding to each layer in the preset layered architecture, the folder is used to store the test files of all interfaces of this layer and the name is the same as the layer name of this layer, when the large language model generates the target code, the code generation prompt word will instruct the large language model to add the target interface name and the target layer name in the form of comments, and add the corresponding search mark before the target interface name and the target layer name, the target The interface name is the name of the target interface, the target interface is the interface for targeted testing of the target code, the target layer name is the name of the target layer, the target layer is the layer where the target interface is located in the preset hierarchical architecture; the preset hierarchical architecture includes an interface call layer, a business layer, an assertion layer, a scenario layer and a data driver layer; the data driver layer is used to provide test data for the scenario layer; the scenario layer is used to encapsulate the automated test project into a test scenario and define test parameters in the test scenario; the business layer is used to convert the test parameters into interface parameters; the interface call layer is used to request the corresponding interface according to the interface parameters and obtain response data; the assertion layer is used to assert the response data; Extracting file path information from the target code; the file path information includes the target interface name and the target layer name; the extracting file path information from the target code includes: extracting the target interface name and the target layer name from the target code according to the search flag; According to the file path information, the target file corresponding to the target code is matched and retrieved in the automated test project; the matching and searching in the directory of the automated test project according to the file path information includes: determining the target search path according to the target layer name and the target interface name; searching in the automated test project whether there is a file matching the target search path; If the target file is not matched, a new test file is generated according to the target code, and the new test file is added to the automated test project; If the target file is matched, the target file is updated according to the difference between the code in the target file and the target code.
2. The automated test script management method according to claim 1, characterized in that: The adding the newly added test file to the automated test project includes: Determine a target storage path according to the target layer name; According to the target storage path, the newly added test file is added to the automated test project.
3. The automated test script management method according to claim 1, characterized in that: The updating of the target file according to the difference between the code in the target file and the target code comprises: Read the code in the target file to obtain the original code; If the target code has a newly added method, then the newly added method is added to the original code to obtain an updated code; the newly added method is a method with a same name that does not exist in the original code; The target file is updated according to the update code.
4. The automated test script management method according to claim 1, characterized in that: The updating of the target file according to the difference between the code in the target file and the target code comprises: Read the code in the target file to obtain the original code; If there are methods with the same name in the target code and the original code, compare the input parameters of each pair of methods with the same name; If the input parameters are different, then the method with the same name in the target code is added to the original code to obtain an updated code; If the input parameters are the same, the method with the same name in the original code is replaced with the method with the same name in the target code to obtain the updated code; The target file is updated according to the update code.
5. The automated test script management method according to claim 4, characterized in that: The comparing of the input parameters in each pair of methods with the same name includes: Compare in sequence whether the number of the input parameters is the same, whether each parameter in the input parameters has a corresponding parameter with the same name, and whether each pair of the parameters with the same name have the same data type; If the comparison results are all yes, it is determined that the input parameters are the same; Otherwise, it is determined that the input parameters are different.
6. The automated test script management method according to any one of claims 3 to 5, characterized in that: The updating of the target file according to the update code comprises: When the target file is matched, the path of the target file is recorded; Generate an update test file according to the update code; According to the path of the target file, the target file is replaced with the update test file.
7. The automated test script management method according to claim 1, characterized in that: The code generation prompt includes target interface information and a test script template.
8. An automated test script management device, characterized in that: The automated test script is used to perform interface testing, and the automated test script management device includes: A model interaction module is used to input a code generation prompt word into a large language model to obtain a target code; the target code is an executable code used to complete a test task in an interface test; a test file corresponding to the target code is stored in an automated test project; the file name of the test file is the same as the corresponding interface name; the automated test project includes folders corresponding to each layer in a preset hierarchical architecture; the folders are used to store test files of all interfaces of the current layer and have the same name as the layer name of the current layer; when the large language model generates the target code, the code generation prompt word will instruct the large language model to add a target interface name and a target layer name in the form of a comment, and add a corresponding search mark before the target interface name and the target layer name; the target interface name is the name of the target interface, and the target interface The interface is a targeted test interface of the target code. The test file corresponding to the target code is stored in the automated test project. The file name of the test file is the same as the corresponding interface name. The target layer name is the name of the target layer. The target layer is the layer where the target interface is located in the preset hierarchical architecture. The preset hierarchical architecture includes an interface call layer, a business layer, an assertion layer, a scenario layer and a data driver layer. The data driver layer is used to provide test data for the scenario layer. The scenario layer is used to encapsulate the automated test project into a test scenario and define test parameters in the test scenario. The business layer is used to convert the test parameters into interface parameters. The interface call layer is used to request the corresponding interface according to the interface parameters and obtain response data. The assertion layer is used to assert the response data. An information extraction module is used to extract file path information from the target code; the file path information includes the target interface name and the target layer name; the extracting the file path information from the target code includes: extracting the target interface name and the target layer name from the target code according to the search flag; A matching retrieval module is used to match and retrieve the target file corresponding to the target code in the automated test project according to the file path information; the matching retrieval is performed in the directory of the automated test project according to the file path information, including: determining the target retrieval path according to the target layer name and the target interface name; and searching in the automated test project whether there is a file matching the target retrieval path; A first processing module, configured to generate a new test file according to the target code if no target file is matched, and add the new test file to the automated test project; The second processing module is used to update the target file according to the difference between the code in the target file and the target code when the target file is matched.
9. A computer device, characterized in that: It includes one or more processors and a memory, wherein the memory stores computer-readable instructions, and when the computer-readable instructions are executed by the one or more processors, the steps of the automated test script management method according to any one of claims 1 to 7 are executed.
10. A storage medium, characterized in that: The storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by one or more processors, the one or more processors execute the steps of the automated test script management method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Test code updating method and device, electronic equipment and storage medium
CN113190448A
Automatic testing method and device, electronic equipment and storage medium
CN115357488A
Test case code generation method and related equipment
CN117707983A