Test script generation method and device, electronic equipment and storage medium
By optimizing the test requirement text and using the test script generation model for code representation learning, the problem of low efficiency in software testing in automotive industry is solved, efficient and automated test script generation is achieved, and manual operations are reduced.
Patent Information
- Application Number
- CN202410684904.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-29
- Publication Date
- 2025-04-08
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
In software testing in the automotive industry, as the software complexity increases, the number of test cases increases geometrically, resulting in inefficient testing work and large workload of testers. The existing automatic generation technology of test cases is difficult to meet the generation needs of large-scale test scripts.
By obtaining the demand text of the target test business, prompt optimization processing is performed to generate the boot text, and code representation learning and decoding of the boot text based on the test script generation model to generate the test script for the target test business.
It improves the efficiency of test script generation, reduces the workload of testers, and lowers the threshold for writing test scripts. The generated test scripts are more in line with actual test scenarios, saving time and cost.
Smart Images

Figure CN119782136A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the technical field of software testing, and in particular to a method and device for generating a test script, an electronic device, and a storage medium. Background Art
[0002] In the era of vehicle intelligence, the amount of software on cars is growing rapidly and the functions are becoming increasingly complex. However, this also puts higher demands on the quality and stability of software. Every software upgrade and release needs to undergo rigorous testing to ensure its safety and reliability in actual applications.
[0003] In the process of software testing, the design of test cases is crucial. It directly determines the coverage and effect of the testing work. However, with the increase in software complexity, the number of test cases has also increased exponentially, which undoubtedly brings huge challenges to the testing work. At present, although there are some test case automatic generation technologies, most of these technologies are only suitable for assisting in the generation of a small number of unit test case scripts. For scenarios that require a large number of test scripts, these technologies are often unable to cope with the situation. Therefore, how to improve the efficiency of test script generation and reduce the workload of testers has become a technical problem that needs to be solved in the current field of software testing in the automotive industry. Summary of the invention
[0004] The present invention provides a method and device for generating a test script, an electronic device and a storage medium, the main purpose of which is to improve the efficiency of generating test scripts and reduce the workload of testers.
[0005] According to a first aspect of the present disclosure, a method for generating a test script is provided, comprising:
[0006] Acquire a requirement text of a target test service, wherein the requirement text is a text generated according to the test requirement of the target test service;
[0007] Performing prompt optimization processing on the demand text to obtain a guiding text;
[0008] Based on the test script generation model, code representation learning is performed on the guide text, and the guide text vector obtained by the code representation learning is decoded to generate a test script for the target test business.
[0009] In some embodiments, before obtaining the requirement text of the target test business, the method further includes:
[0010] Preprocess the test case scripts in the test case library to obtain a training corpus;
[0011] Based on the business knowledge documents and business specification documents, the training corpus in the training corpus is annotated to generate a guide text for training;
[0012] The training guide text is input into the test script generation model for training, and the test script generation model is optimized and adjusted based on the test case script to obtain a trained test script generation model.
[0013] In some embodiments, performing prompt optimization processing on the demand text to obtain the guide text includes:
[0014] Performing semantic analysis on the requirement text to determine the test requirements expressed in the requirement text;
[0015] The test requirement is processed into a structured expression, and based on the structured expression of the test requirement, a standard test requirement text corresponding to the requirement text is generated;
[0016] Obtaining a guide template matching the standard test requirement text;
[0017] Based on the guide template, the standard test requirement text is optimized to obtain the guide text.
[0018] In some embodiments, the test script generation model is based on the test script, code representation learning is performed on the guide text, and the guide text vector obtained by the code representation learning is decoded to generate the test script of the target test service, including:
[0019] Based on the guide text, an initial code snippet is generated, and the initial code snippet is parsed to obtain code parsing data;
[0020] Encoding the guide text, and integrating the vector obtained by encoding with the code parsing data to obtain the guide text vector;
[0021] Based on the guide text vector, a context vector is generated, and the context vector is decoded to generate a test script for the target test service.
[0022] In some embodiments, after performing code representation learning on the guide text based on the test script generation model, decoding the guide text vector obtained by the code representation learning, and generating the test script of the target test service, the method further includes:
[0023] Obtaining the test results of the test script, and analyzing the test results to generate script feedback results;
[0024] Based on the script feedback result, the model parameters of the test script generation model are adjusted so as to perform tuning and learning processing on the test script generation model.
[0025] In some embodiments, the method further comprises:
[0026] Based on the test results, analyzing whether the test script meets the test requirements;
[0027] If the test requirements are met, the test script is updated to the test case library.
[0028] According to a second aspect of the present disclosure, a device for generating a test script is provided, comprising:
[0029] An acquisition unit, configured to acquire a requirement text of a target test service, wherein the requirement text is a text generated according to the test requirement of the target test service;
[0030] An optimization unit, used for performing prompt optimization processing on the demand text to obtain a guide text;
[0031] A generating unit is used to generate a model based on a test script, perform code representation learning on the guide text, and decode the guide text vector obtained by the code representation learning to generate a test script for the target test business.
[0032] In some embodiments, the apparatus further comprises:
[0033] A preprocessing unit, used for preprocessing the test case scripts in the test case library to obtain a training corpus before the acquisition unit acquires the requirement text of the target test business;
[0034] A tagging unit, used to tag the training corpus in the training corpus based on the business knowledge document and the business specification document to generate a guiding text for training;
[0035] The training unit is used to input the training guide text into the test script generation model for training, and optimize and adjust the test script generation model based on the test case script to obtain a trained test script generation model.
[0036] In some embodiments, the optimization unit comprises:
[0037] A first parsing module, used to perform semantic parsing on the requirement text to determine the test requirements expressed in the requirement text;
[0038] A first generating module is used to perform structured expression processing on the test requirement, and generate a standard test requirement text corresponding to the requirement text based on the structured expression of the test requirement;
[0039] An acquisition module, used to acquire a guide template matching the standard test requirement text;
[0040] The optimization module is used to optimize the standard test requirement text based on the guidance template to obtain the guidance text.
[0041] In some embodiments, the generating unit comprises:
[0042] A second parsing module is used to generate an initial code fragment based on the guide text, and parse the initial code fragment to obtain code parsing data;
[0043] An integration module, used for encoding the guide text, and integrating the vector obtained by encoding with the code parsing data to obtain the guide text vector;
[0044] The second generating module is used to generate a context vector based on the guide text vector, and decode the context vector to generate a test script for the target test service.
[0045] In some embodiments, the apparatus further comprises:
[0046] An analysis unit, configured to obtain a test result of the test script after inputting the guide text into a test script generation model to generate a test script of the target test business, and analyze the test result to generate a script feedback result;
[0047] A tuning unit is used to adjust the model parameters of the test script generation model based on the script feedback result, so as to perform tuning learning processing on the test script generation model.
[0048] In some embodiments, the apparatus further comprises:
[0049] An updating unit is used to analyze whether the test script meets the test requirements based on the test results; when the test requirements are met, the test script is updated to the test case library.
[0050] According to a third aspect of the present disclosure, there is provided an electronic device, including:
[0051] at least one processor; and
[0052] a memory communicatively connected to the at least one processor; wherein,
[0053] 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 described in the first aspect.
[0054] According to a fourth aspect of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to enable the computer to execute the method described in the first aspect.
[0055] According to a fifth aspect of the present disclosure, a computer program product is provided, comprising a computer program, wherein when the computer program is executed by a processor, the computer program implements the method as described in the first aspect above.
[0056] The present disclosure provides a method and device, electronic device and storage medium for generating a test script, obtaining a requirement text of a target test business, wherein the requirement text is a text generated according to the test requirements of the target test business; performing prompt optimization processing on the requirement text to obtain a guide text; based on a test script generation model, performing code representation learning on the guide text, and decoding the guide text vector obtained by the code representation learning to generate a test script for the target test business. Compared with the related art, by inputting the requirement text and performing prompt optimization processing, and generating a test script using a test script generation model, the threshold for writing test scripts can be lowered; the guide text after prompt optimization processing can more accurately convey the test requirements, so that the test script generation model can generate a script that is more in line with the actual test scenario. Compared with the traditional manual writing of test scripts, this method greatly reduces manual operations and saves time costs.
[0057] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present application, nor is it intended to limit the scope of the present application. Other features of the present application will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0058] The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present disclosure.
[0059] Figure 1 A flowchart of a method for generating a test script provided by an embodiment of the present disclosure;
[0060] Figure 2 A flowchart of a method for training a test script generation model provided in an embodiment of the present disclosure;
[0061] Figure 3 A flowchart of another method for generating a test script provided by an embodiment of the present disclosure;
[0062] Figure 4 A schematic diagram of the structure of a device for generating a test script provided by an embodiment of the present disclosure;
[0063] Figure 5A schematic diagram of the structure of another device for generating a test script provided by an embodiment of the present disclosure;
[0064] Figure 6 A schematic block diagram of an exemplary electronic device provided for an embodiment of the present disclosure. DETAILED DESCRIPTION
[0065] The following is a description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.
[0066] The following describes the test script generation method and apparatus, electronic device, and storage medium of the embodiments of the present disclosure with reference to the accompanying drawings.
[0067] Figure 1 A flowchart of a method for generating a test script provided in an embodiment of the present disclosure.
[0068] like Figure 1 As shown, the method comprises the following steps:
[0069] Step 101 : obtaining a requirement text of a target test service, wherein the requirement text is a text generated according to the test requirement of the target test service.
[0070] In the implementation of the present disclosure, when conducting the testing work of the target test business, it is first necessary to obtain the corresponding demand text. The demand text is not written arbitrarily, but is generated closely around the test requirements of the target test business. Specifically, the demand text is the result of concretizing and detailing the test requirements in text form after a comprehensive analysis and in-depth understanding of the target test business. These test requirements may cover all aspects of the target test business, including but not limited to business functions, performance requirements, security standards, and user experience. In order to ensure the accuracy and completeness of the demand text, it is usually written and reviewed by a professional testing team or business analyst. In the writing process, the actual operating environment of the target test business and the various situations that may be faced will be fully considered to ensure that the generated demand text can fully and accurately reflect the test requirements. In this way, a demand text that is highly matched with the target test business can be obtained, providing strong support for subsequent test script generation and testing work.
[0071] Step 102: Perform prompt optimization processing on the demand text to obtain a guiding text.
[0072] In the implementation of the present disclosure, after obtaining the requirement text of the target test business, the next key step is to perform prompt optimization processing on it to generate a guide text. The prompt optimization processing is intended to convert the original requirement text into a more instructive and operable guide text.
[0073] The original requirement text may contain complex business logic, professional terms or ambiguous expressions, which may cause the model to deviate from the understanding. Through Prompt optimization, these complex expressions can be converted into a form that is easier for the model to understand, thereby improving the model's accurate understanding of the test requirements.
[0074] By refining and reorganizing the key information in the requirement text, a more clear and specific guide sentence is formed. When it is found that the requirement text cannot accurately express the test requirements, the vague or unclear parts in the requirement text are clarified and supplemented to ensure that the guide text can accurately convey the test intention. For example, the requirement text can be modified and optimized in the form of a guide template file.
[0075] After prompt optimization, the guidance text not only retains the core information in the requirement text, but also adds more details and operational guidance, so that the test script generation model can better understand and execute the test task. Such guidance text will provide strong support and guidance for subsequent test script generation work.
[0076] Step 103 , based on the test script generation model, code representation learning is performed on the guide text, and the guide text vector obtained by the code representation learning is decoded to generate a test script for the target test business.
[0077] In the implementation of the present disclosure, after the prompt optimization processing of the requirement text is completed and the guide text is obtained, the guide text is input into the test script generation model. This test script generation model is specially designed to automatically generate a test script corresponding to the target test business based on the input guide text. The process of inputting the guide text into the test script generation model is actually a process of transferring human testing intentions and knowledge to the machine. The model will receive this guide text and perform complex calculations and analyses based on the knowledge, rules and structures learned internally. This process involves the understanding, parsing and conversion of the guide text, as well as the application of test script generation rules and logic.
[0078] When the model processes the guide text, it will automatically build a test script framework that meets the test requirements based on the key information, test objectives and constraints in the guide text. Then, the model will further fill in this framework and generate specific test steps, input data, expected results, etc. This process is highly automated and can greatly improve the efficiency of test script generation.
[0079] As part of the input of the test script generation model, the guide text plays a vital role. The guide text can be a short description or a functional requirement specification. By learning the code representation of the guide text, the model can capture the key information and convert it into a computer-understandable code representation. This process is usually implemented using natural language processing technology and deep learning models, such as recurrent neural networks (RNN), long short-term memory networks (LSTM) or Transformer.
[0080] In the code representation learning phase, the model learns how to convert the natural language information in the guide text into vector representations. These vector representations not only contain the semantic information in the guide text, but also incorporate the contextual information related to the test script. These vector representations are the basis for the model to generate test scripts in the future. Once the guide text vector representation is obtained, the model can enter the decoding phase. The role of the decoder is to convert these vector representations into specific test script codes. The decoder usually uses a sequence generation method, such as greedy search, beam search, etc., to generate possible test script candidates. During the generation process, the decoder considers the key information in the guide text, as well as the grammar and logic rules of the test script, to ensure that the generated test script not only meets the requirements of the guide text, but also can correctly execute and verify the target test business. The test script generation model outputs a test script corresponding to the target test business. This test script not only meets the test requirements, but also has a clear structure, accurate test steps and reasonable expected results. By using this test script, testers can easily test the target test business to ensure its quality and stability.
[0081] The present disclosure provides a method for generating a test script, obtaining a requirement text of a target test business, wherein the requirement text is a text generated according to the test requirements of the target test business; performing prompt optimization processing on the requirement text to obtain a guide text; based on a test script generation model, performing code representation learning on the guide text, and decoding the guide text vector obtained by the code representation learning to generate a test script for the target test business. Compared with related technologies, by inputting the requirement text and performing prompt optimization processing, and generating a test script using a test script generation model, the threshold for writing test scripts can be lowered; the guide text after prompt optimization processing can more accurately convey the test requirements, so that the test script generation model can generate a script that is more in line with the actual test scenario. Compared with the traditional manual writing of test scripts, this method greatly reduces manual operations and saves time costs.
[0082] Before using the test script generation model to generate test scripts, the test script generation model needs to be trained so that the test script generation model can understand and generate test scripts in the best state, ensuring that the generated scripts meet the test requirements and have high quality and practicality. Through sufficient training, the test script generation model can better understand the test requirements, generate test scripts that are more in line with actual scenarios, and improve the efficiency and quality of testing work.
[0083] In order to clearly illustrate the embodiments of the present disclosure, this embodiment provides a flowchart of a training method for a test script generation model.
[0084] like Figure 2 As shown, the method comprises the following steps:
[0085] Step 201, preprocess the test case scripts in the test case library to obtain a training corpus.
[0086] Specifically, in step 201, before using the test script generation model to generate the test script, training the test script generation model can ensure that the model can understand and generate the test script in the best state, thereby generating a script that meets the test requirements and has high quality and practicality.
[0087] Before the training corpus is input into the test script generation model for training, the test case scripts in the test case library need to be preprocessed to obtain the training corpus. The preprocessing process usually includes a series of operations, which are intended to optimize and standardize the test case scripts so that the model can better learn and understand the structure and pattern therein. In this embodiment, the preprocessing method may include but is not limited to the following methods: Data cleaning: remove redundant, irrelevant or erroneous information in the test script to ensure the accuracy and consistency of the data. Format unification: standardize the format of the test script, such as unifying variable naming rules, annotation styles, etc., which helps the model better recognize and understand the structure of the script. Word segmentation and tagging: split the test script into smaller units (such as words, phrases or sentences) and mark them appropriately so that the model can learn the vocabulary and grammatical structure in the script. Feature extraction: extract key features from the cleaned and labeled data. These features may include specific test steps, input data, expected results, etc. These features are essential for the model to generate high-quality test scripts.
[0088] Preprocessing the test case scripts in the test case library can improve the performance of the model, reduce noise interference, improve training efficiency, and enhance the generalization ability of the model.
[0089] Step 202: Based on the business knowledge document and the business specification document, the training corpus in the training corpus is annotated to generate a guiding text for training.
[0090] Step 203: input the training guide text into the test script generation model for training, and optimize and adjust the test script generation model based on the test case script to obtain a trained test script generation model.
[0091] Specifically, in steps 202 to 203, the training corpus is carefully annotated based on in-depth business knowledge documents and detailed business specification documents. The purpose of this step is to provide rich learning resources for the test script generation model to ensure that the model can accurately understand the structure, logic and business requirements of the test script. Annotation processing usually involves identifying and classifying key elements in the test script, such as test steps, input data, expected results, etc., and labeling these elements accordingly. After the annotation processing is completed, the corresponding training guide text is generated using these annotated training corpora. The test script generation model is trained using these processed training guide texts. During the training process, the model will continuously learn and adjust its own parameters to better adapt to and fit the training data. At the same time, the training process is monitored to evaluate the performance and performance of the model in real time. The test script generated by the test script generation model can be compared with the test case script, and the loss function can also be used to determine whether the loss value is within the expected range, and the performance of the model on the validation set can be further evaluated, such as calculating the accuracy and recall of the model. If the model performs up to the expected standard, the model can be considered trained and is ready to be used to generate actual test scripts.
[0092] In order to clearly illustrate the embodiment of the present disclosure, this embodiment provides a flowchart of another method for generating a test script.
[0093] like Figure 3 As shown, the method comprises the following steps:
[0094] Step 301 : obtaining a requirement text of a target test service, wherein the requirement text is a text generated according to the test requirement of the target test service.
[0095] Specifically in step 301, when conducting the test work of the target test business, it is first necessary to obtain the corresponding demand text. The demand text is not written at will, but is generated closely around the test requirements of the target test business. Specifically, the demand text is the result of concretizing and detailing the test requirements in text form after a comprehensive analysis and in-depth understanding of the target test business. These test requirements may cover all aspects of the target test business, including but not limited to business functions, performance requirements, security standards, and user experience. In order to ensure the accuracy and completeness of the demand text, it is usually written and reviewed by a professional testing team or business analyst. In the writing process, the actual operating environment of the target test business and the various situations that may be faced will be fully considered to ensure that the generated demand text can fully and accurately reflect the test requirements. In this way, a demand text that is highly matched with the target test business can be obtained, providing strong support for subsequent test script generation and testing work.
[0096] Step 302: semantically parse the requirement text to determine the test requirements expressed by the requirement text.
[0097] Step 303: perform structured expression processing on the test requirement, and generate a standard test requirement text corresponding to the requirement text based on the structured test requirement.
[0098] Step 304: Obtain a guidance template that matches the standard test requirement text.
[0099] Step 305: Based on the guide template, the standard test requirement text is optimized to obtain the guide text.
[0100] Specifically, in step 302 to step 305, natural language processing (NLP) technology is used to deeply analyze the requirement text. This includes but is not limited to lexical analysis, syntactic analysis, semantic understanding and other levels, aiming to fully capture the key information, logical structure and business intent in the text, so as to obtain the test requirements expressed by the requirement text. Through natural language processing, the test requirements expressed in the original requirement text can be converted into a structured and standardized test requirement text. This conversion process not only removes redundant information and ambiguous expressions in the text, but also clarifies the specific goals, conditions, steps and expected results of the test, thereby ensuring the accuracy and operability of the test requirements.
[0101] Obtain guidance templates that match the standard test requirement text from the preset template library. These templates are designed based on previous testing experience and business specifications, and are intended to provide a structured framework for guiding the generation of test scripts. By matching the standard test requirement text with the templates in the template library, you can find the guidance template that best suits the current test requirements. After obtaining the guidance template, optimize the standard test requirement text based on the template. This optimization process may include, but is not limited to, adjusting the text structure, refining the language expression, adding necessary prompts and constraints, etc., in order to make the guidance text more in line with the input requirements of the test script generation model, while improving the quality and practicality of the test script.
[0102] After the above processing, we finally get the optimized guide text, which not only retains the core information of the original requirement text, but also adds more details and operability guidance, providing strong support for the subsequent test script generation work.
[0103] Step 306: Based on the test script generation model, code representation learning is performed on the guide text, and the guide text vector obtained by code representation learning is decoded to generate a test script for the target test business.
[0104] Step 3061: Generate an initial code snippet based on the guide text, and parse the initial code snippet to obtain code parsing data.
[0105] Step 3062, encode the guide text, and integrate the vector obtained by encoding with the code parsing data to obtain the guide text vector.
[0106] Step 3063: Generate a context vector based on the guide text vector, and decode the context vector to generate a test script for the target test service.
[0107] Specifically, in step 306, after the prompt optimization processing of the requirement text is completed and the guide text is obtained, the guide text is input into the test script generation model. The process of inputting the guide text into the test script generation model is actually a process of transferring human test intentions and knowledge to the machine. The model will receive the guide text and perform complex calculations and analyses based on the knowledge, rules and structures learned internally. This process involves understanding, parsing and converting the guide text, as well as applying the test script generation rules and logic.
[0108] The test script generation model receives a guide text, which can be a simple description, comment, functional requirement, or other forms of natural language description. The guide text is input into the text encoding part of the test script generation model (for example, using the encoder part of the Transformer model), and is converted into a high-dimensional vector representation after word embedding, self-attention mechanism, etc. This vector representation captures the semantic information in the guide text. If specific code needs to be generated at this time, the test script generation model also needs to generate an initial code snippet based on the guide text. This initial code snippet will be parsed into a representation that is easier for the model to understand and process, such as an abstract syntax tree (AST) or a graph structure in a graph neural network (GNN). The vector representation of the guide text and the parsed representation of the code snippet are combined to form a joint representation (guide text vector). The guide text vector contains both the semantic information of the guide text and the structure and syntax information of the code.
[0109] Based on the guidance text vector, the test script generation model generates a context vector. This context vector is used as the input of the decoder to guide the generation of the test script. The decoder (for example, the decoder part of the Transformer model) starts working and gradually generates the test script based on the context vector. At each step, the decoder considers the generated text and the context vector to predict the next word or phrase. By gradually generating words or phrases, the decoder will eventually generate a complete test script. This test script should accurately reflect the intention of the guidance text and may also contain some specific details or explanations related to the code snippet.
[0110] The generated test script may go through some post-processing steps, such as syntax checking and semantic correction, to further improve its quality and readability. It should be noted that this process is an end-to-end training process, and the model will learn how to map the guide text and code snippets to high-quality test scripts through a large amount of data training. At the same time, this process also depends on the model architecture and training strategy. Different choices may affect the quality and effect of the final generated review text.
[0111] The test script generation model will output a test script corresponding to the target test business. This test script not only meets the test requirements, but also has a clear structure, accurate test steps and reasonable expected results. By using this test script, testers can easily test the target test business to ensure its quality and stability.
[0112] After the test script generation model generates the test script, tuning and learning the test script model can further improve the accuracy and efficiency of the model, enabling it to understand the test requirements more accurately; it can help the model better adapt to different test scenarios and requirements, and improve the generalization ability of the model, so that it can perform well when facing new or unknown test situations.
[0113] As an implementable method of an embodiment of the present disclosure, after the guide text is input into a test script generation model to generate a test script for the target test business, tuning and learning can be performed in the following ways including but not limited to: obtaining the test results of the test script and analyzing the test results to generate a script feedback result; based on the script feedback result, adjusting the model parameters of the test script generation model so as to perform tuning and learning processing on the test script generation model.
[0114] Specifically, after the test script generation model completes the generation of test scripts, the next step is to execute these test scripts and obtain the corresponding test results. These test results usually reflect the comparison between the actual performance of the target test business and the expected results. In order to extract valuable information from the test results, it is necessary to conduct a comprehensive analysis of the test results and generate script feedback results.
[0115] The process of analyzing test results includes recording the execution of the test script in detail, such as the test steps that were successfully executed, the test steps that failed, and any abnormal situations. At the same time, it is also necessary to compare the differences between the actual test results and the expected results and analyze the reasons for these differences. These reasons may include problems with the test data, differences in the test environment, errors in business logic, etc.
[0116] Based on these analyses, script feedback results can be generated. This feedback result not only includes the execution status and result comparison of the test script, but also includes detailed analysis and suggestions for test problems. It provides valuable feedback information for the tuning and learning of the test script generation model.
[0117] The test script generation model is tuned and learned based on the script feedback results. This process aims to make necessary adjustments and optimizations to the model based on the problems and suggestions in the feedback results to improve the quality and accuracy of the test scripts it generates. Tuning and learning may involve adjusting model parameters, reprocessing training data, or selecting a new model structure.
[0118] By comparing the execution results of the test script with the expected test requirements, this embodiment can verify whether the test script is generated as expected and can correctly execute the test task. Analyzing the test results helps to confirm whether the test script covers all test requirements, including functional points, performance indicators, safety requirements, etc., so as to ensure the comprehensiveness of the test. If there is a deviation between the test results and the test requirements, possible defects or errors in the test script can be discovered in time, and then corrected and improved.
[0119] As an implementable method of the embodiment of the present disclosure, after analyzing the execution results of the test script and the expected test requirements, the following method can be adopted but not limited to: based on the test results, analyze whether the test script meets the test requirements; if the test requirements are met, update the test script to the test case library.
[0120] Specifically, the execution results of the test script are compared with the expected test results. By comparing the differences between the two, it can be preliminarily determined whether the test script has achieved the expected test objectives. If the test results are consistent with the expected results and no exceptions or errors occur, it can be preliminarily considered that the test script meets the test requirements.
[0121] After analysis, if it is confirmed that the test script meets the test requirements, then the test script can be updated to the test case library. This step is of great significance for the maintenance and optimization of the test case library. By incorporating test scripts that meet the requirements into the library, the content of the test case library can be continuously enriched and improved, and the efficiency and quality of the test work can be improved.
[0122] It should be noted that the embodiments of the present disclosure may include multiple steps. For the convenience of description, these steps are numbered, but these numbers do not limit the execution time slots or execution order between the steps; these steps can be implemented in any order, and the embodiments of the present disclosure do not limit this.
[0123] Corresponding to the above test script generation method, the present invention also proposes a device based on test script generation. Since the device embodiment of the present invention corresponds to the above method embodiment, the details not disclosed in the device embodiment can be referred to the above method embodiment, and will not be repeated in the present invention.
[0124] Figure 4 A schematic diagram of a test script generation device provided by an embodiment of the present disclosure, such as Figure 4 As shown, including:
[0125] An acquisition unit 41 is used to acquire a requirement text of a target test service, wherein the requirement text is a text generated according to a test requirement of the target test service;
[0126] An optimization unit 42, configured to perform prompt optimization processing on the demand text to obtain a guide text;
[0127] The generating unit 43 is used to perform code representation learning on the guide text based on the test script generation model, and decode the guide text vector obtained by the code representation learning to generate a test script for the target test service.
[0128] The present disclosure provides a device for generating a test script, which obtains a requirement text of a target test business, wherein the requirement text is a text generated according to the test requirements of the target test business; performs prompt optimization processing on the requirement text to obtain a guide text; and inputs the guide text into a test script generation model to generate a test script for the target test business. Compared with related technologies, by inputting the requirement text and performing prompt optimization processing, and generating a test script using a test script generation model, the threshold for writing test scripts can be lowered; the guide text that has undergone prompt optimization processing can more accurately convey the test requirements, so that the test script generation model can generate a script that is more in line with the actual test scenario. Compared with the traditional manual writing of test scripts, this method greatly reduces manual operations and saves time costs.
[0129] Furthermore, in a possible implementation of this embodiment, as Figure 5 As shown, the device also includes:
[0130] A preprocessing unit 44 is used to preprocess the test case scripts in the test case library to obtain a training corpus before the acquisition unit acquires the requirement text of the target test business;
[0131] The annotation unit 45 is used to annotate the training corpus in the training corpus based on the business knowledge document and the business specification document to generate a guiding text for training;
[0132] The training unit 46 is used to input the training guide text into the test script generation model for training, and optimize and adjust the test script generation model based on the test case script to obtain a trained test script generation model.
[0133] Furthermore, in a possible implementation of this embodiment, as Figure 5 As shown, the optimization unit 42 includes:
[0134] A first parsing module 421 is used to perform semantic parsing on the requirement text to determine the test requirements expressed by the requirement text;
[0135] The first generating module 422 is used to perform structured expression processing on the test requirement and generate a standard test requirement text corresponding to the requirement text based on the structured expression of the test requirement.
[0136] An acquisition module 423 is used to acquire a guide template matching the standard test requirement text;
[0137] The optimization module 424 is used to optimize the standard test requirement text based on the guidance template to obtain the guidance text.
[0138] Furthermore, in a possible implementation of this embodiment, as Figure 5 As shown, the generating unit 43 includes:
[0139] A second parsing module 431 is used to generate an initial code fragment based on the guide text, and parse the initial code fragment to obtain code parsing data;
[0140] An integration module 432 is used to encode the guide text and integrate the vector obtained by encoding with the code parsing data to obtain the guide text vector;
[0141] The second generating module 433 is used to generate a context vector based on the guide text vector, and decode the context vector to generate a test script for the target test service.
[0142] Furthermore, in a possible implementation of this embodiment, as Figure 5 As shown, the device also includes:
[0143] The analyzing unit 47 is used for obtaining the test result of the test script after inputting the guide text into the test script generation model to generate the test script of the target test business, and analyzing the test result to generate a script feedback result;
[0144] The tuning unit 48 is used to adjust the model parameters of the test script generation model based on the script feedback result, so as to perform tuning and learning processing on the test script generation model.
[0145] Furthermore, in a possible implementation of this embodiment, as Figure 5 As shown, the device also includes:
[0146] The updating unit 49 is used to analyze whether the test script meets the test requirements based on the test results; when the test requirements are met, the test script is updated to the test case library.
[0147] It should be noted that the above explanation of the method embodiment is also applicable to the device of this embodiment, and the principle is the same, which is not limited in this embodiment.
[0148] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device, a readable storage medium and a computer program product.
[0149] Figure 6 A schematic block diagram of an example electronic device 500 that can be used to implement an embodiment of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or required herein.
[0150] like Figure 6 As shown, the device 500 includes a computing unit 501, which can perform various appropriate actions and processes according to a computer program stored in a ROM (Read-Only Memory) 502 or a computer program loaded from a storage unit 508 to a RAM (Random Access Memory) 503. In the RAM 503, various programs and data required for the operation of the device 500 can also be stored. The computing unit 501, the ROM 502, and the RAM 503 are connected to each other via a bus 504. An I / O (Input / Output) interface 505 is also connected to the bus 504.
[0151] A number of components in the device 500 are connected to the I / O interface 505, including: an input unit 506, such as a keyboard, a mouse, etc.; an output unit 507, such as various types of displays, speakers, etc.; a storage unit 508, such as a disk, an optical disk, etc.; and a communication unit 509, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 509 allows the device 500 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0152] The computing unit 501 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 501 include, but are not limited to, a CPU (Central Processing Unit), a GPU (Graphic Processing Units), various dedicated AI (Artificial Intelligence) computing chips, various computing units running machine learning model algorithms, a DSP (Digital Signal Processor), and any appropriate processor, controller, microcontroller, etc. The computing unit 501 performs the various methods and processes described above, such as the method for test script generation. For example, in some embodiments, the method for test script generation may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit 508. In some embodiments, part or all of the computer program may be loaded and / or installed on the device 500 via the ROM 502 and / or the communication unit 509. When the computer program is loaded into the RAM 503 and executed by the computing unit 501, one or more steps of the method described above may be performed. Alternatively, in other embodiments, the computing unit 501 may be configured to execute the aforementioned test script generation method in any other appropriate manner (for example, by means of firmware).
[0153] Various embodiments of the systems and techniques described above herein may be implemented in digital electronic circuit systems, integrated circuit systems, FPGAs (Field Programmable Gate Arrays), ASICs (Application-Specific Integrated Circuits), ASSPs (Application Specific Standard Products), SOCs (System On Chips), CPLDs (Complex Programmable Logic Devices), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include: being implemented in one or more computer programs that may be executed and / or interpreted on a programmable system including at least one programmable processor that may be a dedicated or general-purpose programmable processor that may receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0154] The program code for implementing the method of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0155] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or device, or any suitable combination of the foregoing. More specific examples of machine-readable storage media may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a RAM, a ROM, an EPROM (Electrically Programmable Read-Only-Memory) or a flash memory, an optical fiber, a CD-ROM (Compact Dis sc Read-Only Memory), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0156] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (Cathode-Ray Tube) or LCD (Liquid Crystal Display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0157] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: LAN (Local Area Network), WAN (Wide Area Network), the Internet, and blockchain networks.
[0158] A computer system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The relationship between the client and the server is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services ("Virtual Private Server", or "VPS" for short). The server may also be a server of a distributed system, or a server combined with a blockchain.
[0159] It should be noted that artificial intelligence is a discipline that studies how computers can simulate certain human thought processes and intelligent behaviors (such as learning, reasoning, thinking, planning, etc.), and includes both hardware-level and software-level technologies. Artificial intelligence hardware technologies generally include technologies such as sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, and big data processing; artificial intelligence software technologies mainly include computer vision technology, speech recognition technology, natural language processing technology, as well as machine learning / deep learning, big data processing technology, knowledge graph technology, and other major directions.
[0160] The various numerical numbers such as first and second involved in the present disclosure are only for the convenience of description and are not used to limit the scope of the embodiments of the present disclosure, but also indicate the order of precedence.
[0161] At least one in the present disclosure may also be described as one or more, and a plurality may be two, three, four or more, which is not limited in the present disclosure. In the embodiments of the present disclosure, for a technical feature, the technical features in the technical feature are distinguished by "first", "second", "third", "A", "B", "C" and "D", etc., and there is no order of precedence or size between the technical features described by the "first", "second", "third", "A", "B", "C" and "D".
[0162] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this disclosure can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved, and this document does not limit this.
[0163] The above specific implementations do not constitute a limitation on the protection scope of the present disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present disclosure shall be included in the protection scope of the present disclosure.
Claims
1. A method for generating a test script, characterized in that: include: Acquire a requirement text of a target test service, wherein the requirement text is a text generated according to the test requirement of the target test service; Performing prompt optimization processing on the demand text to obtain a guiding text; Based on the test script generation model, code representation learning is performed on the guide text, and the guide text vector obtained by the code representation learning is decoded to generate a test script for the target test business.
2. The method according to claim 1, characterized in that: Before obtaining the requirement text of the target test business, the method further includes: Preprocess the test case scripts in the test case library to obtain a training corpus; Based on the business knowledge documents and the business specification documents, the training corpus in the training corpus is annotated to generate a guiding text for training; The training guide text is input into the test script generation model for training, and the test script generation model is optimized and adjusted based on the test case script to obtain a trained test script generation model.
3. The method according to claim 1, characterized in that The step of performing prompt optimization processing on the demand text to obtain a guide text includes: Performing semantic analysis on the requirement text to determine the test requirements expressed in the requirement text; The test requirement is processed into a structured expression, and based on the structured expression of the test requirement, a standard test requirement text corresponding to the requirement text is generated; Obtaining a guide template matching the standard test requirement text; Based on the guide template, the standard test requirement text is optimized to obtain the guide text.
4. The method according to claim 1, characterized in that: The test script generation model is based on the test script, code representation learning is performed on the guide text, and the guide text vector obtained by the code representation learning is decoded to generate the test script of the target test service, including: Based on the guide text, an initial code snippet is generated, and the initial code snippet is parsed to obtain code parsing data; Encoding the guide text, and integrating the vector obtained by encoding with the code parsing data to obtain the guide text vector; Based on the guide text vector, a context vector is generated, and the context vector is decoded to generate a test script for the target test service.
5. The method according to claim 1, characterized in that After performing code representation learning on the guide text based on the test script generation model, decoding the guide text vector obtained by the code representation learning, and generating the test script of the target test service, the method further includes: Obtaining the test results of the test script, and analyzing the test results to generate script feedback results; Based on the script feedback result, the model parameters of the test script generation model are adjusted so as to perform tuning and learning processing on the test script generation model.
6. The method according to claim 5, characterized in that The method further comprises: Based on the test results, analyzing whether the test script meets the test requirements; If the test requirements are met, the test script is updated to the test case library.
7. A device for generating a test script, characterized in that: include: An acquisition unit, configured to acquire a requirement text of a target test service, wherein the requirement text is a text generated according to the test requirement of the target test service; An optimization unit, used for performing prompt optimization processing on the demand text to obtain a guide text; A generating unit is used to generate a model based on a test script, perform code representation learning on the guide text, and decode the guide text vector obtained by the code representation learning to generate a test script for the target test business.
8. 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 6.
9. 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-6.
10. A computer program product, characterized in that The invention comprises a computer program which, when executed by a processor, implements the method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Method for generating interface document code based on natural language description
CN116501306A
Test case generation method and device, terminal equipment and readable storage medium
CN117707922A
Test case code generation method and related equipment
CN117707983A
Test script generation method and device of test case and electronic equipment
CN118092881A
Cited By
Automatic testing method, device and equipment and storage medium
CN120179568A