GPT-based test script generation method and device
The GPT-based test script generation method automates the creation of accurate test scripts by preprocessing and optimizing data, addressing inefficiencies in manual writing and rework, thereby enhancing software testing efficiency and accuracy.
Patent Information
- Application Number
- CN202411314147.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-20
- Publication Date
- 2024-12-06
AI Technical Summary
Traditional manual test script writing is time-consuming, requires coding skills, prone to errors, and necessitates rework when program or business logic changes, failing to meet the efficiency and accuracy demands of modern software testing.
A method and device utilizing a GPT model, specifically a Transformer architecture, to preprocess and optimize test data, learn code structure, and generate automated test scripts based on user interface, code structure, and business logic, incorporating training mechanisms to enhance model accuracy and efficiency.
Automatically generates high-accuracy test scripts, reducing manual effort and costs, improving testing efficiency, and enhancing adaptability to complex scenarios.
Smart Images

Figure CN119088716A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of computer technology, and in particular, relates to a test script generation method and device based on GPT. Background Art
[0002] In related technologies, with the rapid development of the software industry, the scale and complexity of software products are also increasing. Traditional manual testing methods can no longer meet the needs of efficient and accurate testing. Therefore, software testing automation has become a trend and a necessary means. By writing test scripts, user behavior can be simulated, test cases can be automatically executed, and the accuracy of software functions and performance stability can be verified.
[0003] However, test scripts are usually written manually by testers, which not only requires testers to have certain coding skills, but also requires a lot of time and effort. In addition, manually written scripts may contain some errors and omissions, and when the program or business logic changes, the test scripts need to be rewritten to meet specific test requirements. Therefore, how to better realize the generation of test scripts has become an urgent problem to be solved. Summary of the invention
[0004] In view of the above shortcomings of the prior art, the purpose of the invention is to provide a method and device for generating test scripts based on GPT. The method improves the generation efficiency and accuracy of test scripts.
[0005] In a first aspect of the present invention, a test script generation method based on GPT is proposed, comprising: S1, obtaining target data and preprocessing the target data, the target data comprising first data and historical data, the first data comprising code data and test requirement document data, the historical data comprising historical test scripts, historical test cases, and historical test data; S2, pre-training a GPT model of a Transformer architecture based on the preprocessed target data to obtain the pre-trained GPT model, and optimizing the pre-trained GPT model based on the preprocessed code data, the historical test scripts, and the historical test cases to obtain a target GPT model; S3, based on the target GPT model, generating target test cases and target test steps according to the user interface, code structure, and business logic, and generating a target test script according to the target test cases and target test steps.
[0006] Furthermore, the target data is preprocessed, including: cleaning the target data; and performing structured processing on the cleaned target data to obtain key information of the target data.
[0007] Furthermore, the pre-trained GPT model is optimized based on the pre-processed code data, the historical test scripts and the historical test cases to obtain a target GPT model, including: fine-tuning the pre-trained GPT model based on the pre-processed code data, the historical test cases and the historical test scripts to obtain the fine-tuned GPT model; and fine-tuning the fine-tuned GPT model using project test cases to obtain the target GPT model.
[0008] Furthermore, the pre-trained GPT model is fine-tuned based on the pre-processed code data, the historical test cases and the historical test scripts, including: introducing a code structure learning mechanism into the pre-trained GPT model, performing a first training on the pre-processed code data to obtain the key structure and features of the code data; and determining the corresponding page structure based on the key structure and features of the code data.
[0009] Furthermore, it also includes: presetting the input format and output format of the GPT model after the first training; dividing the preprocessed historical test cases into a training set, a validation set and a test set, and performing a second training on the GPT model after the first training based on the training set, and updating the GPT model parameters of the second training through a back propagation algorithm and a gradient descent method, and continuing to perform a third training on the GPT model after the second training; evaluating the GPT model after the third training based on the validation set, and integrating the GPT model after the third training based on the evaluation result.
[0010] Furthermore, it also includes: extracting target features of the preprocessed historical test script, the target features including structural features, operational features and data features of the script; using the preprocessed historical test script as a training set to perform a fourth training on the GPT model after the third training, and using a project test data set to evaluate the performance of the GPT model after the fourth training.
[0011] Furthermore, based on the target GPT model, target test cases and target test steps are generated according to the user interface, code structure and business logic, and a target test script is generated according to the target test cases and target test steps, including: generating the target test cases covering critical paths and boundary conditions according to the user interface, code structure and business logic; converting the target test cases into specific target test steps; determining the target framework of the target test script; and generating the target test script according to the target test cases and target test steps under the target framework.
[0012] In the second aspect of the present invention, a test script generation device based on GPT is proposed, including: an acquisition module, used to acquire target data and preprocess the target data, the target data including first data and historical data, the first data including code data and test requirement document data, and the historical data including historical test scripts, historical test cases, and historical test data; a training module, used to pre-train a GPT model of a Transformer architecture based on the preprocessed target data to obtain the pre-trained GPT model, and optimize the pre-trained GPT model based on the preprocessed code data, the historical test scripts, and the historical test cases to obtain a target GPT model; a generation module, used to generate target test cases and target test steps based on the target GPT model according to the user interface, code structure, and business logic, and generate a target test script according to the target test cases and target test steps.
[0013] According to a third aspect of the present invention, an electronic device is proposed, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute any of the methods described in the first aspect of the present invention.
[0014] According to a fourth aspect of the present invention, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to enable the computer to execute any one of the methods according to the first aspect of the present invention.
[0015] The beneficial effects of the present invention are as follows:
[0016] The test script generation method based on GPT of the present invention obtains target data and pre-processes the target data, wherein the target data includes first data and historical data, wherein the first data includes code data and test requirement document data, and the historical data includes historical test scripts, historical test cases, and historical test data; the GPT model of the Transformer architecture is pre-trained based on the pre-processed target data to obtain the pre-trained GPT model, and the pre-trained GPT model is optimized based on the pre-processed code data, historical test scripts, and historical test cases to obtain the target GPT model; based on the target GPT model, according to the user interface, code structure, and business logic, target test cases and target test steps are generated, and a target test script is generated according to the target test cases and target test steps. The method automatically generates test scripts, improves the generation efficiency and accuracy of test scripts, and reduces the time and cost of manually writing test scripts. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] The accompanying drawings are only used to illustrate specific embodiments and are not considered to limit the present invention. In the entire drawings, the same reference symbols represent the same components. Obviously, the drawings described below are only some embodiments recorded in the embodiments of the present invention. For those of ordinary skill in the art, other drawings can also be obtained based on these drawings.
[0018] Figure 1 is a flow chart of a test script generation method based on GPT according to an embodiment of the present invention;
[0019] Figure 2 is a flow chart of a method for generating a test script based on GPT according to a specific embodiment of the present invention;
[0020] Figure 3 is a structural block diagram of a test script generating device based on GPT according to an embodiment of the present invention;
[0021] Figure 4 It is a structural block diagram of an electronic device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0022] In order to enable those skilled in the art to better understand the technical solutions in the embodiments of the present invention, the technical solutions of the present invention will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all of the embodiments. It should be understood that these descriptions are only exemplary and are not intended to limit the scope of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in the field without making creative work should fall within the scope of protection of the present invention.
[0023] Furthermore, in the following description, descriptions of well-known structures and technologies are omitted to avoid unnecessarily obscuring the concepts disclosed in the present invention.
[0024] In the description of the present invention, it should be noted that, unless otherwise clearly specified and limited, the orientation or position relationship indicated by the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inside", "outside", etc. is based on the orientation or position relationship shown in the drawings, which is only for the convenience of describing the present invention and simplifying the description, and does not indicate or imply that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as a limitation of the present invention. In addition, the terms "first", "second", and "third" are only used for descriptive purposes and cannot be understood as indicating or implying relative importance. The terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be indirectly connected through an intermediate medium, or it can be a connection between the two elements. For those of ordinary skill in the art, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0025] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present invention. Instead, they are merely examples of methods and systems consistent with some aspects of the present invention as detailed in the appended claims.
[0026] The present invention proposes a test script generation method, apparatus and related equipment based on GPT. Specifically, the test script generation method, apparatus and related equipment based on GPT of an embodiment of the present invention are described below with reference to the accompanying drawings.
[0027] Figure 1 It is a flow chart of a test script generation method based on GPT according to an embodiment of the present invention. It should be noted that the test script generation method based on GPT in the embodiment of the present invention can be applied to the test script generation device based on GPT in the embodiment of the present invention. The test script generation device based on GPT can be configured on an electronic device or in a server. This embodiment of the present application does not limit this.
[0028] like Figure 1 As shown, the test script generation method based on GPT includes:
[0029] S110, acquiring target data and preprocessing the target data, the target data including first data and historical data, the first data including code data and test requirement document data, and the historical data including historical test scripts, historical test cases, and historical test data.
[0030] In an embodiment of the present invention, target data is acquired, cleaned, and structured processing is performed on the cleaned target data to obtain key information of the target data.
[0031] That is to say, when the target data is obtained, the target data can be cleaned, that is, noise, duplication and irrelevant information can be removed, and then the cleaned target data can be structured to extract the key information of the target data, where the key information includes but is not limited to test steps, input data, expected output and other information.
[0032] S120, pre-training the GPT model of the Transformer architecture based on the preprocessed target data to obtain a pre-trained GPT model, and optimizing the pre-trained GPT model based on the preprocessed code data, historical test cases and historical test scripts to obtain a target GPT model.
[0033] In an embodiment of the present invention, after preprocessing the target data, the GPT model of the Transformer architecture can be pretrained based on the preprocessed target data to obtain a pretrained GPT model, and the pretrained GPT model can be fine-tuned based on the preprocessed code data, historical test cases, and historical test scripts to obtain a fine-tuned GPT model; the fine-tuned GPT model is refined using project test cases to obtain a target GPT model. The specific implementation method can refer to the subsequent embodiments.
[0034] Among them, the GPT model that pre-trains the pre-processed target data adopts the Transformer architecture, which can ensure that the GPT model can capture long-distance dependencies.
[0035] S130, based on the target GPT model, according to the user interface, code structure and business logic, generate target test cases and target test steps, and generate target test scripts according to the target test cases and target test steps.
[0036] That is to say, the user interface, code structure and business logic are determined, and when the target GPT model is obtained, the target test case and target test steps are generated based on the user interface, code structure and business logic, and then the target test script is generated. The specific implementation method can be referred to the subsequent embodiments.
[0037] According to the GPT-based test script generation method of an embodiment of the present invention, target data is obtained and preprocessed, the target data includes first data and historical data, the first data includes code data and test requirement document data, and the historical data includes historical test scripts, historical test cases, and historical test data; the GPT model of the Transformer architecture is pre-trained based on the pre-processed target data to obtain a pre-trained GPT model, and the pre-trained GPT model is optimized based on the pre-processed code data, historical test scripts, and historical test cases to obtain a target GPT model; based on the target GPT model, according to the user interface, code structure, and business logic, target test cases and target test steps are generated, and a target test script is generated according to the target test cases and target test steps. This method automatically generates test scripts, improves the generation efficiency and accuracy of test scripts, and reduces the time and cost of manually writing test scripts.
[0038] In order to make it easier for those skilled in the art to understand the present invention, Figure 2 A method for generating a test script based on GPT according to a specific embodiment of the present invention is as follows: Figure 2 As shown, the GPT-based test script generation method includes:
[0039] S210, acquiring target data, the target data including first data and historical data, the first data including code data and test requirement document data, and the historical data including historical test scripts, historical test cases, and historical test data.
[0040] In an embodiment of the present invention, code data of front-end applications written in different languages can be obtained, including Vue, Html, CSS, React, JavaScript, etc., as well as component library codes such as ElementUI, IviewUI, etc. used.
[0041] S220, preprocessing the target data.
[0042] In an embodiment of the present invention, target data is acquired, cleaned, and structured processing is performed on the cleaned target data to obtain key information of the target data.
[0043] S230, pre-training the GPT model of the Transformer architecture based on the preprocessed target data to obtain a pre-trained GPT model.
[0044] In an embodiment of the present invention, a GPT model based on the Transformer architecture may be first constructed, and then the GPT model based on the Transformer architecture may be pre-trained based on the preprocessed target data to obtain a pre-trained GPT model.
[0045] S240, fine-tune the pre-trained GPT model based on the preprocessed code data, historical test scripts, and historical test cases to obtain a fine-tuned GPT model.
[0046] In an embodiment of the present invention, when a pre-trained GPT model is obtained and a code structure learning mechanism is introduced into the pre-trained GPT model, a first training is performed on the preprocessed code data to obtain the key structure and features of the code data; and the corresponding page structure is determined based on the key structure and features of the code data.
[0047] That is to say, the code structure learning mechanism is introduced into the pre-trained GPT model, that is, the embedded deep understanding capability is embedded in the model, so that it can accurately capture and analyze the key structure and features of the code data. At the same time, the corresponding interface rendering is input into the model. The model uses image recognition technology with the help of a rich sample of user interface screenshots and a cross-validation mechanism of the corresponding code to establish an accurate mapping between the code structure and the user interface effect it presents.
[0048] For example, the key structures of the parsed code data include: Html, Head, Body, Style, P, Input, Img, Button and El-form, where the Html tag represents the root tag (top-level tag) of the entire Html file, the Head tag represents the attributes of the page, the Body tag represents the content displayed on the page, the Style tag represents the style of the page, the P tag represents text, the Input tag represents the input box, the Img tag is a picture tag, the Button tag is a button, and the tag is a form. The corresponding page structure can be determined based on these tags and tag contents. It can be seen that the first training is performed on the preprocessed code data, and the model can learn the corresponding tag functions. For example, the model can learn that the Input text box in the code is used for users to input information; the Form form is used to collect all the information that needs to be filled in; the Button button is used to operate submission; thereby accurately learning the operations and functional points required by the page, allowing the model to identify the functional points that need to be tested in the code.
[0049] In an embodiment of the present invention, after the model is trained based on the preprocessed code data, the input format and output format of the first trained GPT model are preset; the preprocessed historical test cases are divided into a training set, a validation set and a test set, and the first trained GPT model is subjected to a second training based on the training set, and the GPT model parameters of the second training are updated through the back propagation algorithm and the gradient descent method, and the GPT model after the second training is continued to be subjected to a third training; the third trained GPT model is evaluated based on the validation set, and the third trained GPT model is integrated based on the evaluation result.
[0050] Among them, the input format of the preset first trained GPT model includes a text description of the test case, input data, etc., and the output format includes a detailed description of the expected results and test steps, etc.
[0051] Among them, the preprocessed historical test cases are divided into training set, verification set and test set, which can be divided in the ratio of 70%, 15% and 15%.
[0052] Among them, the back propagation algorithm is an effective method used in neural networks to calculate gradients (i.e., the derivative of the loss function with respect to the model parameters). During the training process, data is forward propagated through the neural network to obtain the predicted output of the model. Then, the error (i.e., loss) between the predicted output and the true output is calculated. The back propagation algorithm uses the chain rule to calculate the gradient from the output layer to the input layer layer by layer, that is, to calculate the partial derivative of the loss function with respect to the parameters of each layer. The gradient descent method is an optimization algorithm used to minimize the loss function by iteratively adjusting parameters. In each iteration, it first calculates the gradient of the loss function with respect to the current parameters (i.e., the steepest ascent direction), and then updates the parameters in the opposite direction of this gradient (i.e., the steepest descent direction). The magnitude of the update is controlled by the learning rate, which is a hyperparameter that determines the size of the step taken in the direction of the gradient.
[0053] That is, the GPT model parameters of the second training are updated through the back propagation algorithm and the gradient descent method. During the training process, the validation set is used regularly to evaluate the performance of the model, and the model parameters and training strategies are adjusted according to the evaluation results. Early stopping technology is used to prevent overfitting, and the best model is saved after the training is completed. After that, the trained model is evaluated using the test set, and the accuracy, recall rate, F1 score and other indicators of the model on the test set are calculated.
[0054] In an embodiment of the present invention, test function points can be identified by performing model training on preprocessed code data, and then the mapping relationship between the structure in the code data and the test case can be determined by performing model training on preprocessed historical test cases.
[0055] In an embodiment of the present invention, based on model training on preprocessed historical test cases, target features of the preprocessed historical test scripts are extracted, and the target features include structural features, operational features and data features of the scripts; the preprocessed historical test scripts are used as training sets to perform a fourth training on the GPT model after the third training, and the project test data set is used to evaluate the performance of the GPT model after the fourth training.
[0056] Among them, the target test dataset can be understood as a test dataset that exists in the real project in addition to the training model, the purpose of which is to verify the model function.
[0057] That is to say, after completing the model training of the preprocessed historical test cases, continue to deepen the model training process, focus on enhancing its in-depth understanding of the test scripts and representation learning capabilities, and extract the target features of the preprocessed historical test scripts, where the target features include the structural features, operation features and data features of the scripts, where the structural features of the scripts include loops, conditional judgments, etc., the operation features include clicks, inputs, etc., and the data features include the type and range of input data, etc. The preprocessed historical test scripts are used as training sets to perform the fourth training on the GPT model after the third training. During the training process, the model will learn how to map the features of the test scripts to the results or behaviors of the test execution.
[0058] S250, use the project test cases to perform fine-tuning training on the fine-tuned GPT model to obtain the target GPT model.
[0059] In an embodiment of the present invention, in order to further improve the performance of the fine-tuned GPT model in generating intelligent test scripts, the model is refined using project test cases. Through these targeted trainings, the model can more accurately understand the test requirements and generate test scripts that meet expectations, thereby better adapting to various complex test scenarios.
[0060] Among them, project test cases can be understood as test cases manually written for real projects in addition to training models, which are used to verify model functions.
[0061] In an embodiment of the present invention, the pre-trained GPT model is fine-tuned based on the pre-processed code data, historical test cases and historical test scripts to obtain a fine-tuned GPT model; the fine-tuned GPT model is refined using project test cases to obtain a target GPT model. Through model training, the obtained target GPT model can generate test scripts according to the user interface, code structure and business logic information.
[0062] S260, based on the target GPT model, generates target test cases and target test steps according to the user interface, code structure and business logic.
[0063] In an embodiment of the present invention, when the target GPT model is obtained, based on the target GPT model, target test cases covering critical paths and boundary conditions are generated according to the user interface, code structure and business logic; and the target test cases are converted into specific target test steps.
[0064] S270, generating a target test script according to the target test case and the target test steps.
[0065] In an embodiment of the present invention, a target framework of a target test script is determined; under the target framework, a target test script is generated according to target test cases and target test steps.
[0066] In one embodiment of the present invention, when generating a target test data set, you can open a browser, enter the URL of the software to be tested, and then enter the user name and password in the test set on the login page. If the login fails, the user is prompted that the login failed. If the login is successful, the user successfully jumps to the user homepage, and then determines whether the target test data set has been tested. If yes, a test report is output, and if not, continue to enter a different user name and password to log in. That is, the ability to generate test scripts is achieved.
[0067] According to the GPT-based test script generation method of the embodiment of the present invention, the automatic generation of test scripts reduces the time and cost of manually writing scripts, and significantly improves the test efficiency. Through the learning ability of the deep learning model (such as the GPT model), the key structures and features in the code can be more accurately identified, so as to generate test cases and test steps that are more in line with the test requirements, and improve the accuracy of the test; the model can process front-end application codes written in different languages, including Vue, Html, CSS, React, JavaScript, etc., as well as different component library codes, and has strong adaptability. Through continuous training and optimization of the model, its ability and effect of generating test scripts can be continuously improved, and it has good scalability; the automatically generated test scripts can promptly discover defects and problems in the software, and help the development team to repair them in time, thereby improving the overall quality of the software. Through refined training, the model can more accurately understand the test requirements, generate more expected test scripts, and further ensure the quality of the software; reduce the repetitive work of testers and reduce the cost of testing.
[0068] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods of each embodiment of the present application.
[0069] According to one aspect of an embodiment of the present invention, a test script generating device based on GPT is also proposed. Figure 3 is a structural block diagram of a test script generating device based on GPT according to an embodiment of the present invention; Figure 3 As shown, including:
[0070] An acquisition module 310 is used to acquire target data and preprocess the target data, wherein the target data includes first data and historical data, wherein the first data includes code data and test requirement document data, and the historical data includes historical test scripts, historical test cases, and historical test data;
[0071] A training module 320 is used to pre-train the GPT model of the Transformer architecture based on the pre-processed target data to obtain the pre-trained GPT model, and optimize the pre-trained GPT model based on the pre-processed code data, the historical test script and the historical test case to obtain a target GPT model;
[0072] The generation module 330 is used to generate target test cases and target test steps based on the target GPT model, according to the user interface, code structure and business logic, and generate a target test script based on the target test cases and target test steps.
[0073] According to the GPT-based test script generation device of the embodiment of the present invention, the target data is obtained and preprocessed, the target data includes first data and historical data, the first data includes code data and test requirement document data, and the historical data includes historical test scripts, historical test cases, and historical test data; the GPT model of the Transformer architecture is pre-trained based on the pre-processed target data to obtain the pre-trained GPT model, and the pre-trained GPT model is optimized based on the pre-processed code data, historical test scripts, and historical test cases to obtain the target GPT model; based on the target GPT model, according to the user interface, code structure, and business logic, target test cases and target test steps are generated, and the target test script is generated according to the target test cases and target test steps. The test script is thus automatically generated, which improves the generation efficiency and accuracy of the test script and reduces the time and cost of manually writing the test script.
[0074] Optionally, the acquisition module 310 is specifically used to clean the target data; perform structured processing on the cleaned target data to obtain key information of the target data.
[0075] Optionally, the training module 320 is specifically used to fine-tune the pre-trained GPT model based on the pre-processed code data, the historical test cases and the historical test scripts to obtain the fine-tuned GPT model; and use project test cases to perform fine-tuning training on the fine-tuned GPT model to obtain the target GPT model.
[0076] Optionally, the training module 320 is specifically used to perform a first training on the preprocessed code data by introducing a code structure learning mechanism into the pre-trained GPT model to obtain the key structure and features of the code data; and determine the corresponding page structure based on the key structure and features of the code data.
[0077] Optionally, the training module 320 is specifically used to preset the input format and output format of the GPT model after the first training; divide the preprocessed historical test cases into a training set, a validation set and a test set, and perform a second training on the GPT model after the first training based on the training set, and update the GPT model parameters of the second training through a back propagation algorithm and a gradient descent method, and continue to perform a third training on the GPT model after the second training; evaluate the GPT model after the third training based on the validation set, and integrate the GPT model after the third training based on the evaluation result.
[0078] Optionally, the training module 320 is specifically used to extract target features of the preprocessed historical test script, wherein the target features include structural features, operational features and data features of the script; use the preprocessed historical test script as a training set to perform a fourth training on the GPT model after the third training; and use a project test data set to evaluate the performance of the GPT model after the fourth training.
[0079] Optionally, the generation module 330 is specifically used to generate the target test cases covering critical paths and boundary conditions based on the user interface, code structure and business logic; convert the target test cases into specific target test steps; determine the target framework of the target test script; and generate the target test script according to the target test cases and target test steps under the target framework.
[0080] According to one aspect of an embodiment of the present invention, an electronic device is provided.
[0081] Figure 4 Schematic diagram of the structure of an electronic device according to an embodiment of the present invention. Figure 4 As shown, the electronic device may include one or more ( Figure 4Only one is shown in the figure) processor 102 (processor 102 may include but is not limited to a microprocessor (Microprocessor Unit, referred to as MPU) or a programmable logic device (Programmable logic device, referred to as PLD)) and a memory 104 for storing data. In an exemplary embodiment, the electronic device may also include a transmission device 106 and an input / output device 108 for communication functions. It can be understood by those skilled in the art that Figure 4 The structure shown is for illustration only and does not limit the structure of the above terminal device. Figure 4 More or fewer components as shown, or with Figure 4 Equivalent functions or comparisons shown Figure 4 A different configuration with more features is shown.
[0082] The memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as the computer program corresponding to the test script generation method based on GPT in the embodiment of the present invention. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, to implement the above method. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the terminal device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0083] The transmission device 106 is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of the switching device. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, referred to as NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0084] The present invention provides a non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to enable the computer to execute a test script generation method based on GPT.
[0085] The applicant of the present invention has made a detailed explanation and description of the implementation examples of the present invention in conjunction with the drawings in the specification. However, those skilled in the art should understand that the above implementation examples are only preferred implementation schemes of the present invention, and the detailed description is only to help readers better understand the spirit of the present invention, but not to limit the scope of protection of the present invention. On the contrary, any improvements or modifications based on the inventive spirit of the present invention should fall within the scope of protection of the present invention.
[0086] In addition, each functional unit in each embodiment of the present invention may be integrated into a processing module, or each unit may exist physically separately, or two or more units may be integrated into one module. The above-mentioned integrated module may be implemented in the form of hardware or in the form of a software functional module. If the integrated module is implemented in the form of a software functional module and sold or used as an independent product, it may also be stored in a computer-readable storage medium.
[0087] The storage medium mentioned above may be a read-only memory, a magnetic disk or an optical disk, etc. Although the embodiments of the present invention have been shown and described above, it can be understood that the above embodiments are exemplary and cannot be understood as limiting the present invention. A person of ordinary skill in the art may change, modify, replace and modify the above embodiments within the scope of the present invention.
[0088] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the embodiments of the present invention, rather than to limit them. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that they can still modify the technical solutions recorded in the above embodiments, or replace some of the technical features therein by equivalents; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention. Any changes or replacements that can be easily thought of by those skilled in the art within the technical scope disclosed in the present invention should be covered within the protection scope of the present invention.
Claims
1. A test script generation method based on GPT, characterized in that: include: S1, acquiring target data and preprocessing the target data, the target data including first data and historical data, the first data including code data and test requirement document data, the historical data including historical test scripts, historical test cases, and historical test data; S2, pre-training the GPT model of the Transformer architecture based on the pre-processed target data to obtain the pre-trained GPT model, and optimizing the pre-trained GPT model based on the pre-processed code data, the historical test script and the historical test case to obtain a target GPT model; S3, based on the target GPT model, generate target test cases and target test steps according to the user interface, code structure and business logic, and generate a target test script according to the target test cases and target test steps.
2. The test script generation method based on GPT according to claim 1, characterized in that: Preprocessing the target data includes: Cleaning the target data; The cleaned target data is subjected to structured processing to obtain key information of the target data.
3. The test script generation method based on GPT according to claim 1, characterized in that: Optimizing the pre-trained GPT model based on the pre-processed code data, the historical test scripts, and the historical test cases to obtain a target GPT model includes: Fine-tune the pre-trained GPT model based on the pre-processed code data, the historical test cases, and the historical test scripts to obtain the fine-tuned GPT model; The fine-tuned GPT model is refined by using project test cases to obtain the target GPT model.
4. The GPT-based test script generation method according to claim 3, characterized in that: Fine-tuning the pre-trained GPT model based on the pre-processed code data, the historical test cases, and the historical test scripts includes: In the case where a code structure learning mechanism is introduced into the pre-trained GPT model, a first training is performed on the pre-processed code data to obtain key structures and features of the code data; The corresponding page structure is determined according to the key structure and features of the code data.
5. The GPT-based test script generation method according to claim 4, characterized in that: Also includes: Presetting the input format and output format of the GPT model after the first training; Divide the preprocessed historical test cases into a training set, a validation set, and a test set, and perform a second training on the GPT model after the first training based on the training set, and update the GPT model parameters of the second training by a back propagation algorithm and a gradient descent method, and continue to perform a third training on the GPT model after the second training; The GPT model after the third training is evaluated based on the validation set, and the GPT model after the third training is integrated based on the evaluation result.
6. The GPT-based test script generation method according to claim 5, characterized in that: Also includes: Extracting target features of the preprocessed historical test script, wherein the target features include structural features, operational features, and data features of the script; The preprocessed historical test scripts are used as training sets to perform a fourth training on the GPT model after the third training, and a project test data set is used to evaluate the performance of the GPT model after the fourth training.
7. The test script generation method based on GPT according to claim 1, characterized in that: Based on the target GPT model, target test cases and target test steps are generated according to the user interface, code structure and business logic, and a target test script is generated according to the target test cases and target test steps, including: Generate the target test cases covering key paths and boundary conditions according to the user interface, code structure and business logic; Convert the target test case into specific target test steps; Determining a target framework for the target test script; Under the target framework, a target test script is generated according to the target test case and target test steps.
8. A test script generation device based on GPT, characterized in that: include: An acquisition module, used to acquire target data and preprocess the target data, wherein the target data includes first data and historical data, wherein the first data includes code data and test requirement document data, and the historical data includes historical test scripts, historical test cases, and historical test data; A training module, used to pre-train the GPT model of the Transformer architecture based on the pre-processed target data to obtain the pre-trained GPT model, and optimize the pre-trained GPT model based on the pre-processed code data, the historical test scripts and the historical test cases to obtain a target GPT model; A generation module is used to generate target test cases and target test steps based on the target GPT model, according to the user interface, code structure and business logic, and to generate a target test script based on the target test cases and target test steps.
9. An electronic device, characterized in that: include: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 7.
10. A non-transitory computer-readable storage medium storing computer instructions, characterized in that: The computer instructions are used to cause the computer to execute the method according to any one of claims 1 to 7.
