Test case generation method and device, equipment and medium
Through the NLP-based classification model, a complete test case is generated, which solves the readability, reliability and maintenance problems when manually writing BDD scenarios, and improves the testing efficiency and coverage.
Patent Information
- Application Number
- CN202311231881.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-22
- Publication Date
- 2025-03-28
Smart Images

Figure CN119718899A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computers, and in particular to a test case generation method, device, equipment and medium. Background Art
[0002] BDD (Behavior Driven Development) is an agile software development technology that lowers the threshold for software testers. It encourages developers, QA (Quality Assurance) and non-technical personnel or business participants in software projects to collaborate with each other to lower the threshold for QA automated script writing. At the beginning of a BDD project, customers, developers, and testers work together to design the behavior of the system through full communication (discuss which test scenarios should be passed in order to successfully call this software / application), and testers write test cases that can describe the system behavior in a scripting language. Developers then write the relevant implementation code and ensure that the test case passes. This process is repeated to achieve the functionality of the entire system.
[0003] However, when manually writing BDD scenarios, they will inevitably be affected by the subjective thinking and understanding of the author, resulting in problems such as poor readability, low reliability, and difficult maintenance. In addition, the writing cycle is long, which can easily affect the overall development progress. Summary of the invention
[0004] The present application provides a test case generation method, apparatus, device and medium to solve or at least partially solve the above-mentioned problems existing in the prior art.
[0005] A first aspect of an embodiment of the present application provides a test case generation method, the method comprising:
[0006] Get the test cases;
[0007] Use the pre-trained classification model to predict the missing scenarios and feature descriptions of the above test cases to generate complete test cases;
[0008] The above classification model is obtained by training the initial semantic pre-training model using the training sample set to obtain a model for scene and feature prediction.
[0009] Optionally, the above classification model includes a scene classification sub-model and a feature classification sub-model;
[0010] The above pre-trained classification model is used to predict the missing scenarios and feature descriptions of the above test cases, and generate complete test cases, including:
[0011] Input the annotations of the above test cases into the above scenario classification sub-model to predict the scenario corresponding to the above test cases;
[0012] The code and comments of the above test cases are spliced and input into the above feature classification sub-model to predict the features corresponding to the above test cases;
[0013] The code, comments, and predicted scenarios and features of the above test cases are combined to obtain a complete test case.
[0014] Optionally, the classification model includes a scene classification sub-model, and training the scene classification sub-model includes:
[0015] Using natural language processing technology to perform feature conversion on the annotations of the training samples, obtain a first feature vector matrix corresponding to the training samples, and encode the scenes of the training samples to obtain real scene labels corresponding to the training samples;
[0016] Using the initial scene classification sub-model to extract features from the first eigenvector matrix, and using the naive Bayes classification algorithm to perform classification prediction, to obtain the predicted scene labels corresponding to the training samples;
[0017] Based on the predicted scene labels and real scene labels corresponding to the above training samples, the loss function is calculated, and the model parameters of the above initial scene classification sub-model are updated according to the above loss function until the above loss function converges, thereby obtaining the scene classification sub-model for scene prediction.
[0018] Optionally, the feature conversion of the annotations of the training samples using natural language processing technology to obtain a first feature vector matrix corresponding to the training samples includes:
[0019] Extract the annotations of the above training samples as text features;
[0020] Perform word segmentation processing on the above text features to obtain word segmentation features;
[0021] The above word segmentation features are converted into vector form to obtain the first feature vector matrix corresponding to the above training samples.
[0022] Optionally, the classification model includes a feature classification sub-model, and training the feature classification sub-model includes:
[0023] The codes and comments of the above training samples are spliced together to obtain the features to be detected;
[0024] Using natural language processing technology to perform feature conversion on the features to be detected, obtaining a second feature vector matrix corresponding to the training samples, and encoding the feature descriptions of the training samples to obtain true feature labels corresponding to the training samples;
[0025] Using the initial feature classification sub-model to extract features from the second feature vector matrix, and using the naive Bayes classification algorithm to perform classification prediction, to obtain the predicted feature labels corresponding to the training samples;
[0026] Based on the predicted feature labels and true feature labels corresponding to the above training samples, the loss function is calculated, and the model parameters of the above initial feature classification sub-model are updated according to the above loss function until the above loss function converges, thereby obtaining the feature classification sub-model for feature prediction.
[0027] Optionally, the above method further includes:
[0028] Generate corresponding scripts based on the above test cases;
[0029] Execute the above script, test the above script using the above training sample set, and generate a test report;
[0030] The execution results of the above scripts are reviewed according to the above test reports to optimize the above classification model.
[0031] Optionally, each training sample in the above training sample set includes a code snippet, a comment, a corresponding scenario and a feature description.
[0032] A second aspect of an embodiment of the present application provides a test case generation device, the device comprising:
[0033] Acquisition module, used to obtain the test cases;
[0034] An inference module is used to use a pre-trained classification model to predict the missing scenarios and feature descriptions of the above test cases and generate complete test cases;
[0035] The above classification model is a model for scene and feature prediction obtained by training an initial semantic pre-training model using a training sample set. Each training sample in the above training sample set includes a code snippet, an annotation, and a corresponding scene and feature description.
[0036] A third aspect of an embodiment of the present application provides a readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the steps in the method described above in the first aspect of the present application are implemented.
[0037] A fourth aspect of an embodiment of the present application provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executed, implements the steps of the method described above in the first aspect of the present application.
[0038] Compared with the prior art, this application has the following advantages:
[0039] The embodiment of the present application collects training sample data including code snippets, comments, corresponding scenarios and feature descriptions, trains the semantic pre-training model based on NLP natural language processing technology, obtains a classification model that can predict scenarios and features, and directly uses the classification model to infer the missing scenarios and features in the code, comments and other tags, and generates complete test cases. On the one hand, test cases can be quickly generated through natural language models, which effectively improves the efficiency of software development testing, and can predict and generate a large number of accurate natural language sentences, enhance the coverage of tests, and help to comprehensively test software development systems. On the other hand, the classification model based on NLP natural language processing technology pays more attention to the semantic and logical consistency of sentences, can improve the readability and comprehensibility of generated sentences, and enhance the reliability and accuracy of test scenario writing. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] Figure 1 is a flow chart of a test case generation method proposed in one embodiment of the present application;
[0041] Figure 2 is a flow chart of a test case generation method proposed in another embodiment of the present application;
[0042] Figure 3 It is a structural diagram of a test case generation device proposed in one embodiment of the present application. DETAILED DESCRIPTION
[0043] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0044] There are some disadvantages to manually writing BDD (Behavior Driven Development) scenarios, including:
[0045] 1. Subjectivity: Since BDD scenarios are manually written, they are easily affected by the subjective thinking and understanding of the author. This may lead to inconsistency or ambiguity in the scenarios, thus reducing reliability and accuracy.
[0046] 2. Poor readability: Manually written BDD scenarios may contain grammatical errors, non-standard wording, or poor formatting, which reduces the readability of the scenario. This may cause confusion for developers or other relevant personnel when understanding and interpreting the scenario.
[0047] 3. Difficulty in maintenance: As the project develops and requirements change, BDD scenarios need to be constantly updated and maintained. Manually written scenarios have high maintenance costs because every time the requirements or business logic are changed, developers need to manually update the corresponding scenarios, which may lead to omissions or errors.
[0048] 4. Consistency issues: In large projects, multiple developers are often involved in writing BDD scenarios. Since each person's writing style and understanding may be different, there will be consistency issues between scenarios, which may cause misunderstandings and conflicts in teamwork and communication.
[0049] 5. Time consumption: Writing complex BDD scenarios usually takes a lot of time and effort, especially when multiple interactions and multiple scenarios are involved. This may lead to delays in development progress, especially when developers need to spend more time writing and debugging scenarios.
[0050] In view of this, the embodiment of the present application collects training sample data including code snippets, comments, corresponding scenarios and feature descriptions, trains the semantic pre-training model based on NLP natural language processing technology, and obtains a classification model that can predict scenarios and features. Therefore, the classification model can be directly used to infer the missing scenarios and features in the code, comments and other tags, and generate complete test cases. The classification model based on NLP natural language processing technology uses existing knowledge bases and rules to generate scenarios, which can effectively improve the efficiency of software development testing, while reducing the interference of personal subjective thinking and improving the consistency and accuracy of the scenarios.
[0051] Please refer to Figure 1 , Figure 1 1 is a flow chart of a test case generation method proposed in one embodiment of the present application. Figure 1 As shown, the method comprises the following steps:
[0052] Step S101: Obtain a test case.
[0053] In this embodiment, when writing a test case, the test case generally includes a code snippet, comments, corresponding scenarios and feature descriptions. For example, a test case for performing an addition operation is shown below:
[0054] Code snippet:
[0055] def add_numbers(a,b):
[0056] return a+b
[0057] Notes:
[0058] #This function is used to add two numbers.
[0059] Scenario and feature description:
[0060] Scenario: Addition calculation
[0061] Features: Add two numbers
[0062] In a project, customers, developers, and testers may work together to design the behavior of the system through full communication (discuss which test scenarios should be passed in order to successfully call this software / application), and multiple developers may participate in writing BDD scenarios. However, each person has a different understanding, which may lead to consistency issues in the scenarios, and the content in the test cases may not be completely valid. Therefore, for such incomplete or incomplete test cases, the valid parts they contain can be used to infer the corresponding missing parts. For example, a test case containing code snippets and comments is obtained as a test case, and then based on the code snippets and comments, the missing scenarios and feature descriptions of the test case are inferred and predicted to complete the test case.
[0063] Step S102: using a pre-trained classification model to predict the missing scenarios and feature descriptions of the above test cases, and generating complete test cases.
[0064] The above classification model is a model for scene and feature prediction obtained by training an initial semantic pre-training model using a training sample set. Each training sample in the above training sample set includes a code snippet, an annotation, and a corresponding scene and feature description.
[0065] In this embodiment, the classification model can be obtained in the following manner: First, data with written scenarios and features can be collected as training samples to construct a training sample set. These training samples contain code snippets, comments, corresponding scenarios and feature descriptions to provide input and training targets for the model. Then, the code, comments and other tags (such as test numbers, test names, etc.) are converted into feature representations that can be understood by the machine learning algorithm. For example, they can be implemented by converting them into word vectors, AST (abstract syntax trees) or other similar forms. After that, a sequence-to-sequence model or a semantic pre-training model (such as BERT) can be used for training. The sequence-to-sequence model can process input sequences of indefinite length and generate output sequences corresponding thereto. The semantic pre-training model can understand the context of the input code, as well as the semantic information of the comments and tags to generate matching scenarios and feature descriptions. After training, a classification model is obtained, and the trained model can be used directly to infer the missing scenarios and feature descriptions in the code, comments and other tags.
[0066] Optionally, the above classification model includes a scene classification sub-model and a feature classification sub-model;
[0067] The above-mentioned use of a pre-trained classification model to predict the missing scenarios and feature descriptions of the above-mentioned test cases to generate complete test cases includes: inputting the annotations of the above-mentioned test cases into the above-mentioned scenario classification sub-model to predict the scenarios corresponding to the above-mentioned test cases; concatenating the codes and annotations of the above-mentioned test cases, and inputting them into the above-mentioned feature classification sub-model to predict the features corresponding to the above-mentioned test cases; merging the codes, annotations and predicted scenarios and feature descriptions of the above-mentioned test cases to obtain a complete test case.
[0068] In this embodiment, the training process of the scene classification sub-model and the feature classification sub-model is the same. The scene classification sub-model is used to predict the corresponding scene label according to the annotation information of the test case; the feature classification sub-model is used to predict the corresponding feature label according to the combined feature information of the code snippet and annotation of the test case. Exemplarily, the program snippet of the prediction process is as follows:
[0069] test_sample={
[0070] 'code':'def multiply_numbers(a,b):\n return a*b',
[0071] 'comment':'This function is used to multiply two numbers.'
[0072] }
[0073] # Pass the annotations of the test samples into the trained model for prediction.
[0074] predicted_scene=pipeline.predict([test_sample['comment']])
[0075] print('Inferred scene:', predicted_scene[0])
[0076] #Pass the code and comments of the test sample into the trained model for prediction.
[0077] predicted_feature=pipeline.predict([test_sample['code']+”+test_sample['comment']])
[0078] print('Inferred features:', predicted_feature[0])
[0079] Based on the pre-trained model, the comments of the test case can be predicted to obtain the inferred scenario and scenario label, and then the code and comments can be spliced together, and the model can be used for prediction again to obtain the inferred feature description and feature label. Thus, the code, comments, and predicted scenarios and feature descriptions of the test case can be combined to obtain a complete test case.
[0080] Please refer to Figure 2 , Figure 2 FIG. 1 is a flow chart of a test case generation method proposed in another embodiment of the present application. Figure 2 As shown, the method comprises the following steps:
[0081] Step S201: obtaining a training sample set, wherein each training sample in the training sample set includes a code snippet, an annotation, a corresponding scenario and a feature description.
[0082] Exemplarily, the constructed training sample set is as follows:
[0083]
[0084] Among them, code represents a code snippet, comment represents a comment, scene represents a scene, and feature represents a feature description. For example, in the greeting scene, the corresponding code is executed to send a personalized greeting sentence "Hello, Little Patrick!" to the customer.
[0085] Step S202: Convert the code snippets, comments, corresponding scenarios and feature descriptions of the training samples into feature vectors.
[0086] Step S203: using the above training samples to train the initial semantic pre-training model to obtain a classification model for scene and feature prediction.
[0087] In this embodiment, the above-mentioned classification model includes a scene classification sub-model, and the process of training the scene classification sub-model includes: using natural language processing technology to perform feature conversion on the annotations of the above-mentioned training samples to obtain the first eigenvector matrix corresponding to the above-mentioned training samples, and encoding the scenes of the above-mentioned training samples to obtain the real scene labels corresponding to the above-mentioned training samples; using the initial scene classification sub-model to extract features from the above-mentioned first eigenvector matrix, and using the naive Bayes classification algorithm to perform classification prediction to obtain the predicted scene labels corresponding to the above-mentioned training samples; based on the predicted scene labels and real scene labels corresponding to the above-mentioned training samples, calculating the loss function, and updating the model parameters of the above-mentioned initial scene classification sub-model according to the above-mentioned loss function until the above-mentioned loss function converges, thereby obtaining the scene classification sub-model for scene prediction.
[0088] Exemplarily, the process of extracting features from training samples based on natural language processing technology NLP and using a naive Bayes classifier to train a model is as follows:
[0089] #Remove comments and scene labels
[0090] comments=[sample['comment']for sample in train_samples]
[0091] labels=[sample['scene']for sample in train_samples]
[0092] #Use Tokenization for word segmentation
[0093] tokenized_comments=[nltk.word_tokenize(comment)for comment incomments]
[0094] #Use CountVectorizer to convert into feature vector
[0095] vectorizer=CountVectorizer()
[0096] features=vectorizer.fit_transform([”.join(tokens)for tokens intokenized_comments])
[0097] #Build a classifier model
[0098] classifier=MultinomialNB()
[0099] #Build the Pipeline of feature extraction and classifier
[0100] pipeline=Pipeline([
[0101] ('vectorizer',vectorizer),
[0102] ('classifier',classifier) ])
[0104] #Model training
[0105] pipeline.fit(comments,labels)
[0106] Among them, in the process of converting the features of the annotations of the training samples to obtain the first feature vector matrix corresponding to the training samples, the annotations of the training samples are first extracted as text features, and then the Tokenization tool is used to segment the text features, and the sentences in the annotation text are divided into character string sequences to obtain the segmentation features. Then, the CountVectorizer tool is used to convert the segmentation features into vector form to obtain the first feature vector matrix corresponding to the training samples as the input of the model. At the same time, when extracting the annotation text features, the scenes of the training samples are encoded to obtain the real scene labels corresponding to the training samples as the prediction targets of the model.
[0107] After that, a naive Bayes classifier model, such as Multinomia1NB, is constructed, and feature extraction and naive Bayes classifier models are combined based on the Pipeline processing mechanism to obtain a workflow of a semantic pre-training model. The workflow is used to extract and predict the first feature vector matrix of the training sample, and the model is trained based on the real scene labels corresponding to the training sample to update the model parameters and obtain a classification model for scene prediction.
[0108] Optionally, the above-mentioned classification model also includes a feature classification sub-model, and the process of training the feature classification sub-model includes: splicing the code and annotations of the above-mentioned training samples to obtain the features to be detected; using natural language processing technology to perform feature conversion on the above-mentioned features to be detected to obtain a second feature vector matrix corresponding to the above-mentioned training samples, and encoding the feature description of the above-mentioned training samples to obtain the true feature labels corresponding to the above-mentioned training samples; using the initial feature classification sub-model to extract features from the above-mentioned second feature vector matrix, and using the naive Bayes classification algorithm to perform classification prediction to obtain the predicted feature labels corresponding to the above-mentioned training samples; based on the predicted feature labels and true feature labels corresponding to the above-mentioned training samples, calculating the loss function, and updating the model parameters of the above-mentioned initial feature classification sub-model according to the above-mentioned loss function until the above-mentioned loss function converges, thereby obtaining a feature classification sub-model for feature prediction.
[0109] In this embodiment, the training process of the feature classification sub-model is similar to the training process of the scene classification sub-model, and will not be repeated here.
[0110] Step S204: Use the trained classification model to infer the missing scenarios and features in the test case.
[0111] In this embodiment, the codes and comments of the test cases are predicted based on the trained classification model, so that the most likely scenarios and feature labels can be predicted, for example:
[0112] # Make predictions
[0113] test_comment = 'Please calculate the median of the given list.'
[0114] predicted_label=pipeline.predict([test_comment])
[0115] print('Prediction scenario:', predicted_label[0])
[0116] Step S205: Generate corresponding scripts or codes according to the results of model inference, and execute tests.
[0117] In this embodiment, firstly, a corresponding script is generated according to the above test case, then the script is executed, the script is tested using a training sample set, and a test report is generated. Specifically, the test case can be converted into a script code through the BDD automated testing framework Behave, which can be an automated script, a programming script, or other types of code. Then, the generated script is executed and applied to a test environment or an actual environment. During the test execution process, the script can be tested using test cases or sample data to verify the correctness and reliability of the script. During the test execution process, operations such as logging, error handling, and anomaly detection can be performed to ensure the stability and quality of the script, and a test report can be generated at the same time.
[0118] Step S206: review the execution results of the script according to the test report to optimize the classification model.
[0119] In this embodiment, by reviewing the execution results of the script, possible problems or errors are identified and fixed. For example, the classification model can be optimized by adaptive gradient methods such as Adagrad, Adadelta, and RMSprop. It optimizes the model by adaptively adjusting the gradient descent step size, has high computational efficiency, and requires little memory. It has good application effects in application scenarios with large-scale data and parameters.
[0120] Optimization work may include but is not limited to the following: performance optimization, such as modifying and optimizing nested loops, dead loops, circle query statements, etc. in the code to reduce computing time and memory usage; algorithm optimization, such as adjusting the time and space complexity of the model algorithm to improve the accuracy of the algorithm; model generation optimization, such as improving the generation capability of the model by improving the training data set. Thus, the accuracy and efficiency of model inference and use case generation can be improved through the optimization process.
[0121] Using a test case generation method of the present application in BDD agile development testing can:
[0122] 1. Improve testing efficiency: Traditional manual testing methods usually require a lot of human resources and time. The BDD testing method combined with the NLP generation scenario characteristics uses natural language models to quickly generate test cases, effectively improving testing efficiency.
[0123] 2. Enhanced test coverage: The BDD test method combined with the NLP generation scenario characteristics can generate a large number of accurate natural language sentences and conduct a comprehensive test of the system's generation capabilities. By generating and verifying different sentences, the test coverage can be enhanced and more potential problems and errors can be discovered.
[0124] 3. Enhance the human-computer interaction experience: NLP generation scenarios usually involve application scenarios of human-computer interaction, such as machine translation, intelligent customer service, etc. The BDD testing method combined with the characteristics of NLP generation scenarios focuses on the semantic and logical consistency of sentences, which can improve the readability and comprehensibility of sentences generated by the system, thereby enhancing the human-computer interaction experience.
[0125] 4. Improve system generation capabilities: During the test, not only is the correctness of the generated statements verified, but also whether they meet the semantic and logical requirements in specific scenarios, thereby improving the generation quality of the system and being able to comprehensively evaluate and improve the system's statement generation capabilities.
[0126] 5. Enhance system transparency and explainability: Through the comprehensibility of test cases and results, we can better understand the system generation process, help find problems and provide explanations, and make the system generation process more transparent.
[0127] Based on the same inventive concept, an embodiment of the present application provides a test case generation device. Figure 3 , Figure 3 : is a schematic diagram of a test case generation device proposed in an embodiment of the present application, comprising:
[0128] Acquisition module, used to obtain the test cases;
[0129] An inference module is used to use a pre-trained classification model to predict the missing scenarios and feature descriptions of the above test cases and generate complete test cases;
[0130] The above classification model is a model for scene and feature prediction obtained by training an initial semantic pre-training model using a training sample set. Each training sample in the above training sample set includes a code snippet, an annotation, and a corresponding scene and feature description.
[0131] Optionally, the above inference module includes:
[0132] A first inference module is used to input the annotation of the test case into the scenario classification sub-model to predict the scenario corresponding to the test case;
[0133] The second inference module is used to splice the code and comments of the above-mentioned test case and input them into the above-mentioned feature classification sub-model to predict the features corresponding to the above-mentioned test case;
[0134] The test case generation module is used to merge the code, comments, and predicted scenarios and features of the above test cases to obtain a complete test case.
[0135] Optionally, the above device further includes:
[0136] A first feature conversion module is used to perform feature conversion on the annotations of the training samples using natural language processing technology to obtain a first feature vector matrix corresponding to the training samples, and to encode the scenes of the training samples to obtain real scene labels corresponding to the training samples;
[0137] A first prediction module is used to extract features from the first feature vector matrix using an initial scene classification sub-model, and to perform classification prediction using a naive Bayes classification algorithm to obtain a predicted scene label corresponding to the training sample;
[0138] The first training module is used to calculate the loss function based on the predicted scene labels and real scene labels corresponding to the above training samples, and update the model parameters of the above initial scene classification sub-model according to the above loss function until the above loss function converges, thereby obtaining the scene classification sub-model for scene prediction.
[0139] Optionally, the first feature conversion module includes:
[0140] An annotation feature extraction submodule, used to extract the annotations of the above training samples as text features;
[0141] The word segmentation submodule is used to perform word segmentation processing on the above text features to obtain word segmentation features;
[0142] The conversion submodule is used to convert the above word segmentation features into a vector form to obtain a first feature vector matrix corresponding to the above training samples.
[0143] Optionally, the above device further includes:
[0144] A feature splicing module is used to splice the code and annotations of the above training samples to obtain the features to be detected;
[0145] The second feature conversion module is used to perform feature conversion on the above-mentioned features to be detected by using natural language processing technology to obtain a second feature vector matrix corresponding to the above-mentioned training sample, and encode the feature description of the above-mentioned training sample to obtain a real feature label corresponding to the above-mentioned training sample;
[0146] The second prediction module is used to extract features from the second feature vector matrix using the initial feature classification sub-model, and perform classification prediction using the naive Bayes classification algorithm to obtain the predicted feature labels corresponding to the training samples;
[0147] The second training module is used to calculate the loss function based on the predicted feature labels and true feature labels corresponding to the above training samples, and update the model parameters of the above initial feature classification sub-model according to the above loss function until the above loss function converges, thereby obtaining the feature classification sub-model for feature prediction.
[0148] Optionally, the above device further includes:
[0149] A script generation module is used to generate corresponding scripts based on the above test cases;
[0150] The script testing module is used to execute the above script, test the above script using the above training sample set, and generate a test report.
[0151] Optionally, it also includes:
[0152] The optimization module is used to review the execution results of the above script according to the above test report and optimize the above classification model through expert experience.
[0153] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0154] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0155] Those skilled in the art will appreciate that the embodiments of the present application can be provided as methods, devices, or computer program products. Therefore, the present application can adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0156] The embodiments of the present application are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0157] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0158] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for implementing the process in the computer or other programmable terminal device. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0159] Although the preferred embodiments of the present application have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present application.
[0160] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.
[0161] The above is a detailed introduction to a test case generation method, device, equipment and medium provided by the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea; at the same time, for general technical personnel in this field, according to the idea of the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A test case generation method, characterized in that: The method comprises: Get the test cases; Using a pre-trained classification model to predict the missing scenarios and feature descriptions of the test case to generate a complete test case; The classification model is a model for scene and feature prediction obtained by training an initial semantic pre-training model using a training sample set.
2. The method according to claim 1, characterized in that The classification model includes a scene classification sub-model and a feature classification sub-model; The method of using the pre-trained classification model to predict the missing scenarios and feature descriptions of the test case to be tested, and generating a complete test case, includes: Inputting the annotation of the test case into the scenario classification sub-model to predict the scenario corresponding to the test case; The code and comments of the test case are spliced and input into the feature classification sub-model to predict the feature corresponding to the test case; The code, comments, and predicted scenarios and features of the test case are combined to obtain a complete test case.
3. The method according to claim 1, characterized in that The classification model includes a scene classification sub-model, and training the scene classification sub-model includes: Using natural language processing technology to perform feature conversion on the annotations of the training samples to obtain a first feature vector matrix corresponding to the training samples, and encoding the scenes of the training samples to obtain real scene labels corresponding to the training samples; Using the initial scene classification sub-model to extract features from the first feature vector matrix, and using the naive Bayes classification algorithm to perform classification prediction to obtain a predicted scene label corresponding to the training sample; Based on the predicted scene labels and real scene labels corresponding to the training samples, a loss function is calculated, and the model parameters of the initial scene classification sub-model are updated according to the loss function until the loss function converges, thereby obtaining a scene classification sub-model for scene prediction.
4. The method according to claim 3, characterized in that The step of using natural language processing technology to perform feature conversion on the annotations of the training samples to obtain a first feature vector matrix corresponding to the training samples includes: Extracting annotations of the training samples as text features; Performing word segmentation processing on the text features to obtain word segmentation features; The word segmentation features are converted into vector form to obtain a first feature vector matrix corresponding to the training sample.
5. The method according to claim 1, characterized in that The classification model includes a characteristic classification sub-model, and training the characteristic classification sub-model includes: Splicing the code and annotation of the training sample to obtain features to be detected; Using natural language processing technology to perform feature conversion on the feature to be detected, obtain a second feature vector matrix corresponding to the training sample, and encode the feature description of the training sample to obtain a real feature label corresponding to the training sample; Using the initial feature classification sub-model to perform feature extraction on the second feature vector matrix, and using the naive Bayes classification algorithm to perform classification prediction to obtain the predicted feature label corresponding to the training sample; Based on the predicted feature labels and true feature labels corresponding to the training samples, a loss function is calculated, and the model parameters of the initial feature classification sub-model are updated according to the loss function until the loss function converges, thereby obtaining a feature classification sub-model for feature prediction.
6. The method according to claim 1, characterized in that The method further comprises: Generate corresponding scripts according to the test cases; Execute the script, test the script using the training sample set, and generate a test report; The execution results of the script are reviewed according to the test report to optimize the classification model.
7. The method according to claim 1, characterized in that Each training sample in the training sample set includes a code snippet, an annotation, a corresponding scenario and a feature description.
8. A test case generating device, characterized in that: The device comprises: Acquisition module, used to obtain test cases; An inference module, used to predict the missing scenarios and feature descriptions of the test case using a pre-trained classification model, and generate a complete test case; The classification model is a model for scene and feature prediction obtained by training an initial semantic pre-training model using a training sample set, and each training sample in the training sample set includes a code snippet, an annotation, and a corresponding scene and feature description.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps in the method according to any one of claims 1 to 7 are implemented.
10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.