Software test case generation method and system based on bidirectional long and short memory algorithm
By applying the bidirectional long and short memory algorithm (Bi-LSTM) in software testing, test cases are automatically generated and coverage evaluation is carried out, and the problems of strong dependence on demand documents, insufficient coverage and difficulty in review in the existing technology are solved, and more efficient and more accurate software testing is achieved.
Patent Information
- Application Number
- CN202510185665.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-20
- Publication Date
- 2025-03-21
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Existing software test case writing methods rely on requirements and technical documents, resulting in limited writing efficiency and accuracy, insufficient coverage and difficult review.
Using a two-way long and short memory algorithm (Bi-LSTM) method, through deep learning of software requirements documents, code and logs, test cases are automatically generated, reducing dependence on documents, and optimizing test cases through coverage evaluation.
Improve the relevance and accuracy of test cases, optimize the test process, ensure higher coverage and test quality, reduce maintenance costs, and improve testing efficiency.
Smart Images

Figure CN119669099A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of software testing, and in particular to a method and system for generating software testing cases based on a bidirectional long short-term memory algorithm. Background Art
[0002] Software testing is a crucial link in the entire life cycle of software development, which aims to discover defects and errors in software to ensure the quality and reliability of software products. Test case writing is a core activity in the software testing process, which usually relies on requirement documents and technical documents to design a series of test steps, input data and expected results. However, the existing test case writing methods have the following problems: 1. Excessive reliance on requirement documents and technical documents: The traditional test case writing process requires testers to have an in-depth understanding of requirement documents and technical documents, which often requires a lot of time and expertise. When requirements change or documents are incomplete, the efficiency and accuracy of test case writing will be affected.
[0003] 2. Insufficient test case coverage: Due to the complexity of the software system, manually written test cases may not cover all functional points and abnormal situations, resulting in potential defects not being detected.
[0004] 3. Test case review is difficult: The test case review is a time-consuming and laborious process, which requires the reviewers to have rich experience and professional knowledge. In actual operation, due to the large number of test cases, the review process is often difficult to be comprehensive and in-depth, resulting in some imperfect or invalid test cases not being discovered and corrected in time. Summary of the invention
[0005] The purpose of the present invention is to provide a software test case generation method and system based on a bidirectional long short-term memory algorithm, aiming to reduce the dependence on requirement documents and technical documents, improve the coverage of test cases, and simplify the review process of test cases, thereby improving the overall efficiency and effectiveness of software testing.
[0006] In order to solve the above technical problems, the present invention provides a method for generating software test cases based on a bidirectional long short-term memory algorithm, comprising the following steps: Get the files to be processed; Preprocess the files to be processed to obtain preprocessed text data; The preprocessed text data is input into the trained Bi-LSTM network for feature extraction to obtain text features; Generate test cases based on text features.
[0007] Preferably, preprocessing the file to be processed to obtain preprocessed text data specifically includes the following steps: Perform text cleaning on the files to be processed, remove irrelevant format information, special characters and blank characters, and obtain text-cleaned data; Perform word segmentation on the data after text cleaning to obtain the word segmentation results; The word segmentation results are vectorized to obtain preprocessed text data.
[0008] Preferably, vectorization is performed on the word segmentation results to obtain preprocessed text data, which specifically includes the following steps: Use the Word2Vec model to convert the word segmentation results into vector representations, map each word into a vector space of fixed dimension, and represent each word as a 100-dimensional vector as preprocessed text data; The preprocessed text data is a sequence, in which each element represents a word or a tag.
[0009] Preferably, the Bi-LSTM network comprises an input layer, a hidden layer and an output layer; The text data input by the input layer is pre-processed text data; Each preprocessed text data is converted into a sequence, where each element represents a word or a token, which are the basic units of text data, and the basic units are words, phrases or specific code elements; The word embedding dimension of the input vector is: Each word or token is converted into a vector of dimension 100 through word embedding technique; the conversion captures the semantic information of the vocabulary; The sequence representation of the input vector is as follows: Each word in a text sequence is represented as a 100-dimensional vector, and the entire sequence thus forms a three-dimensional data structure, where the first dimension is the sequence length, the second dimension is the word embedding dimension, and the third dimension is the batch size.
[0010] Preferably, the Bi-LSTM network comprises two hidden layers, each hidden layer consists of 128 Bi-LSTM units; each Bi-LSTM unit is used to learn long-term dependencies in sequence data; The Bi-LSTM unit is set as: Input gate: responsible for controlling the input of new information into the cell state; Forget gate: responsible for deciding which information should be forgotten from the cell state; Output gate: responsible for controlling the output of cell state information to the hidden state; Cell state: carries information transmitted through the sequence; Activation function: In the input gate, forget gate, output gate and cell state, the tanh function is used as the activation function to introduce nonlinear characteristics; The tanh function is the hyperbolic tangent function: ; Where e is the base of the natural logarithm; the tanh function maps the input value to the interval (-1, 1) and has the ability to introduce nonlinear characteristics; Each hidden layer consists of a forward LSTM and a backward LSTM, which enables the network to capture the forward and backward dependencies of sequence data simultaneously; The function of the forward LSTM is to process sequence data, learn and encode the forward context information of each time step from the beginning to the end of the sequence; The output of the forward LSTM is: At each time step, the forward LSTM unit outputs the hidden state vector ; The function of backward LSTM is: to process sequence data, learn and encode the backward context information of each time step from the end to the beginning of the sequence; The output of the backward LSTM is: At each time step t, the backward LSTM unit outputs the hidden state vector ; Output concatenation: At each time step t, the hidden state vector of the forward LSTM and the hidden state vector of the backward LSTM Splice together to form a complete representation of this time step ; The splicing formula is: ; Where: is a vector of dimension 2n, where n is the dimension of the hidden state of each individual LSTM unit; After the output of each Bi-LSTM layer, a Dropout layer is added with a Dropout rate of 0.5. Each neuron has a 50% probability of being dropped. This process is performed independently in each forward propagation and back propagation. In each forward propagation, the output of each neuron is will be multiplied by a random ,if If is 0, is 0, that is, the neuron is discarded; if is 1, then Remain unchanged, that is, the neurons are retained; this process is independent at each iteration, so different neurons are discarded at each iteration; ; Where: is the neuron output after applying Dropout; is a Bernoulli random variable. For each neuron i, the probability of its value being 1 is 1−p, that is, the neuron is retained; the probability of its value being 0 is p, that is, the neuron is discarded; is the raw neuron output; is the Dropout rate.
[0011] Preferably, the output layer is located at the top of the Bi-LSTM network, responsible for converting the output of the hidden layer, mapping the output of the Bi-LSTM hidden layer to the final test case feature vector; the dimension of the output vector is 10, representing the feature vector of the generated test case; The activation function of the output layer uses the softmax function for classification tasks and the linear function for regression tasks: The softmax function formula is: ; Where: z is the linear combination of the fully connected layers; e is the base of the natural logarithm, and the softmax function outputs a probability distribution; each element represents the predicted probability of the corresponding category.
[0012] Preferably, the parameters of the Bi-LSTM network are configured as follows: Optimizer: Use Adam optimizer for gradient descent with a learning rate of 0.001; Loss function: Use the cross entropy loss function for classification problems to measure the difference between the probability distribution predicted by the model and the true label; Number of training rounds: The number of training rounds is 50; the model will iterate the training data 50 times, and the model performance will be evaluated after each round of training to monitor the training progress and avoid overfitting; Batch size: The batch size is 32; in each training iteration, the model will use 32 samples to update the parameters.
[0013] Preferably, the training process of the Bi-LSTM network is: Obtain historical data, and divide the historical data into a training set and a validation set; the ratio of the training set to the validation set is 8:2; Input the training data in the training set into the Bi-LSTM network; The output is computed through a forward pass through the network; the output of each time step is passed to the next time step until the entire sequence has been processed; Use the cross entropy loss function to calculate the error between the predicted result and the true label; Update the network weights according to the gradient of the loss function through the back-propagation algorithm, calculate the derivative of the loss function with respect to each weight, and use the derivative to adjust the weight; Select the optimal hyperparameter combination through cross-validation. Under each hyperparameter combination, train the model and evaluate its performance on the validation set. Compare the model performance under different hyperparameter combinations and select the hyperparameter combination with the best performance on the validation set as the selected hyperparameter combination. Retrain the model with the selected hyperparameter combination, using the training and validation sets to obtain the best model performance.
[0014] Preferably, the method further comprises the following steps: Perform coverage evaluation based on test cases and software requirements to obtain coverage; Optimize the corresponding test cases according to the coverage evaluation results to obtain the test case optimization results; The calculation formula of the coverage is: Where: T is the test case set; R is the software requirement set; C(T, R) is the correspondence between test cases and software requirements; C(T, R)_covered is the requirement set actually covered; |R| is the total number of elements in the requirement set; |C(T, R)_covered| is the total number of elements in the requirement set actually covered.
[0015] The present invention also provides a software test case generation system based on a bidirectional long short-term memory algorithm, comprising: An acquisition module is used to obtain files to be processed; A preprocessing module is used to preprocess the files to be processed to obtain preprocessed text data; Feature extraction module, used to input the preprocessed text data into the trained Bi-LSTM network for feature extraction to obtain text features; The test case generation module is used to generate test cases based on text features.
[0016] Compared with the prior art, the present invention has the following beneficial effects: The present invention innovatively applies a bidirectional long short-term memory network (Bi-LSTM) to automatically generate software test cases. This technology can effectively parse and convert complex sequence data, providing intelligent support for the creation of test cases.
[0017] The present invention achieves an in-depth understanding of software requirement documents, codes, and logs through deep learning algorithms, thereby improving the relevance and accuracy of test cases.
[0018] The present invention can optimize the test process and ensure that the test cases can cover more test scenarios, including routine operations and potential abnormal situations. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] The specific implementation modes of the present invention are further described in detail below with reference to the accompanying drawings.
[0020] Figure 1 The present invention is a flowchart of a method for generating software test cases based on a bidirectional long short-term memory algorithm. DETAILED DESCRIPTION
[0021] Many specific details are set forth in the following description to facilitate a full understanding of the present invention. However, the present invention can be implemented in many other ways than those described herein, and those skilled in the art can make similar generalizations without violating the connotation of the present invention, so the present invention is not limited to the specific implementation disclosed below.
[0022] The terms used in one or more embodiments of this specification are only for the purpose of describing specific embodiments, and are not intended to limit one or more embodiments of this specification. The singular forms of "a", "said" and "the" used in one or more embodiments of this specification and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used in one or more embodiments of this specification refers to and includes any or all possible combinations of one or more associated listed items.
[0023] It should be understood that although the terms first, second, etc. may be used to describe various information in one or more embodiments of this specification, this information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of one or more embodiments of this specification, the first may also be referred to as the second, and similarly, the second may also be referred to as the first. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0024] The present invention is further described in detail below in conjunction with the accompanying drawings: like Figure 1 As shown, the present invention provides a method for generating software test cases based on a bidirectional long short-term memory algorithm, comprising the following steps: Get the files to be processed; Preprocess the files to be processed to obtain preprocessed text data; The preprocessed text data is input into the trained Bi-LSTM network for feature extraction to obtain text features; Generate test cases based on text features.
[0025] Preferably, preprocessing the file to be processed to obtain preprocessed text data specifically includes the following steps: Perform text cleaning on the files to be processed, remove irrelevant format information, special characters and blank characters, and obtain text-cleaned data; Perform word segmentation on the data after text cleaning to obtain the word segmentation results; The word segmentation results are vectorized to obtain preprocessed text data.
[0026] Preferably, vectorization is performed on the word segmentation results to obtain preprocessed text data, which specifically includes the following steps: Use the Word2Vec model to convert the word segmentation results into vector representations, map each word into a vector space of fixed dimension, and represent each word as a 100-dimensional vector as preprocessed text data; The preprocessed text data is a sequence, in which each element represents a word or a tag.
[0027] Preferably, the Bi-LSTM network comprises an input layer, a hidden layer and an output layer; The text data input by the input layer is pre-processed text data; Each preprocessed text data is converted into a sequence, where each element represents a word or a token, which are the basic units of text data, and the basic units are words, phrases or specific code elements; The word embedding dimension of the input vector is: Each word or token is converted into a vector of dimension 100 through word embedding technique; the conversion captures the semantic information of the vocabulary; The sequence representation of the input vector is as follows: Each word in a text sequence is represented as a 100-dimensional vector, and the entire sequence thus forms a three-dimensional data structure, where the first dimension is the sequence length, the second dimension is the word embedding dimension, and the third dimension is the batch size.
[0028] Preferably, the Bi-LSTM network comprises two hidden layers, each hidden layer consists of 128 Bi-LSTM units; each Bi-LSTM unit is used to learn long-term dependencies in sequence data; The Bi-LSTM unit is set as: Input gate: responsible for controlling the input of new information into the cell state; Forget gate: responsible for deciding which information should be forgotten from the cell state; Output gate: responsible for controlling the output of cell state information to the hidden state; Cell state: carries information transmitted through the sequence; Activation function: In the input gate, forget gate, output gate and cell state, the tanh function is used as the activation function to introduce nonlinear characteristics; The tanh function is the hyperbolic tangent function: ; Where e is the base of the natural logarithm; the tanh function maps the input value to the interval (-1, 1) and has the ability to introduce nonlinear characteristics; Each hidden layer consists of a forward LSTM and a backward LSTM, which enables the network to capture the forward and backward dependencies of sequence data simultaneously; The function of the forward LSTM is to process sequence data, learn and encode the forward context information of each time step from the beginning to the end of the sequence; The output of the forward LSTM is: At each time step, the forward LSTM unit outputs the hidden state vector ; The function of backward LSTM is: to process sequence data, learn and encode the backward context information of each time step from the end to the beginning of the sequence; The output of the backward LSTM is: At each time step t, the backward LSTM unit outputs the hidden state vector ; Output concatenation: At each time step t, the hidden state vector of the forward LSTM and the hidden state vector of the backward LSTM Splice together to form a complete representation of this time step ; The splicing formula is: ; Where: is a vector of dimension 2n, where n is the dimension of the hidden state of each individual LSTM unit; After the output of each Bi-LSTM layer, a Dropout layer is added with a Dropout rate of 0.5. Each neuron has a 50% probability of being dropped. This process is performed independently in each forward propagation and back propagation. In each forward propagation, the output of each neuron is will be multiplied by a random ,if If is 0, is 0, that is, the neuron is discarded; if is 1, then Remain unchanged, that is, the neurons are retained; this process is independent at each iteration, so different neurons are discarded at each iteration; ; Where: is the neuron output after applying Dropout; is a Bernoulli random variable. For each neuron i, the probability of its value being 1 is 1−p, that is, the neuron is retained; the probability of its value being 0 is p, that is, the neuron is discarded; is the raw neuron output; is the Dropout rate.
[0029] Preferably, the output layer is located at the top of the Bi-LSTM network, responsible for converting the output of the hidden layer, mapping the output of the Bi-LSTM hidden layer to the final test case feature vector; the dimension of the output vector is 10, representing the feature vector of the generated test case; The activation function of the output layer uses the softmax function for classification tasks and the linear function for regression tasks: The softmax function formula is: ; Where: z is the linear combination of the fully connected layers; e is the base of the natural logarithm, and the softmax function outputs a probability distribution; each element represents the predicted probability of the corresponding category.
[0030] Preferably, the parameters of the Bi-LSTM network are configured as follows: Optimizer: Use Adam optimizer for gradient descent with a learning rate of 0.001; Loss function: Use the cross entropy loss function for classification problems to measure the difference between the probability distribution predicted by the model and the true label; Number of training rounds: The number of training rounds is 50; the model will iterate the training data 50 times, and the model performance will be evaluated after each round of training to monitor the training progress and avoid overfitting; Batch size: The batch size is 32; in each training iteration, the model will use 32 samples to update the parameters.
[0031] Preferably, the training process of the Bi-LSTM network is: Obtain historical data, and divide the historical data into a training set and a validation set; the ratio of the training set to the validation set is 8:2; Input the training data in the training set into the Bi-LSTM network; The output is computed through a forward pass through the network; the output of each time step is passed to the next time step until the entire sequence has been processed; Use the cross entropy loss function to calculate the error between the predicted result and the true label; Update the network weights according to the gradient of the loss function through the back-propagation algorithm, calculate the derivative of the loss function with respect to each weight, and use the derivative to adjust the weight; Select the optimal hyperparameter combination through cross-validation. Under each hyperparameter combination, train the model and evaluate its performance on the validation set. Compare the model performance under different hyperparameter combinations and select the hyperparameter combination with the best performance on the validation set as the selected hyperparameter combination. Retrain the model with the selected hyperparameter combination, using the training and validation sets to obtain the best model performance.
[0032] Preferably, the method further comprises the following steps: Perform coverage evaluation based on test cases and software requirements to obtain coverage; Optimize the corresponding test cases according to the coverage evaluation results to obtain the test case optimization results; The calculation formula of the coverage is: Where: T is the test case set; R is the software requirement set; C(T, R) is the correspondence between test cases and software requirements; C(T, R)_covered is the requirement set actually covered; |R| is the total number of elements in the requirement set; |C(T, R)_covered| is the total number of elements in the requirement set actually covered.
[0033] The present invention also provides a software test case generation system based on a bidirectional long short-term memory algorithm, comprising: An acquisition module is used to obtain files to be processed; A preprocessing module is used to preprocess the files to be processed to obtain preprocessed text data; Feature extraction module, used to input the preprocessed text data into the trained Bi-LSTM network for feature extraction to obtain text features; The test case generation module is used to generate test cases based on text features.
[0034] The application value of the software test case generation method based on the bidirectional long short-term memory algorithm of the present invention is: 1. Improve testing efficiency: Automatically generate test cases to reduce the workload of testers and speed up testing progress.
[0035] 2. Improve test quality: Test cases generated by deep learning algorithms are more targeted and help discover software defects.
[0036] 3. Reduce maintenance costs: Automatically evaluate test case coverage, which helps to adjust test strategies in a timely manner and reduce subsequent maintenance costs.
[0037] 4. Optimize human resources: Free testers from the tedious work of test case writing and reviewing, allowing them to focus more on test strategies and advanced testing tasks.
[0038] In the present invention, the following methods are used to improve the overall process of software testing: 1. Application of Bi-LSTM: This paper uses the feature of Bi-LSTM that it can consider both forward and backward related information when learning sequence data, and conducts in-depth analysis of sequence data such as software requirement documents, codes, and logs. It uses the Bi-LSTM algorithm in deep learning to automatically learn features from a large amount of unstructured data, understand software project documents and codes, and generate high-quality test cases. The Bi-LSTM network's ability to process sequence data is used to process input sequences of different lengths, effectively learn long-distance dependencies, understand the complex logic in software requirement documents and the control flow in the code, and optimize the generation of high-quality test cases.
[0039] 2. Test case generation: Input data preprocessing: After text cleaning and word segmentation of the input data, vectorization and sequence encoding technology are used to convert raw data such as requirement documents, codes, and logs into a format suitable for Bi-LSTM processing. The Bi-LSTM network is used to automatically learn the features of the input data. Through its unique gating mechanism, it captures the dependencies in the data, reduces manual intervention, and can also discover and utilize features that are difficult to identify manually, so as to more accurately understand the functions and structure of the software. Based on the features learned by Bi-LSTM, test cases are automatically generated, including test steps, input data, and expected results. This generation method is dynamically generated according to data features to ensure that test cases can cover software functions more comprehensively. This preprocessing method can represent data more effectively.
[0040] It has the following novel features Dynamic feature learning: The method of the present invention does not define features statically, but dynamically learns features from data through a Bi-LSTM network, which makes the test case generation process more intelligent and adaptive.
[0041] End-to-end generation process: From raw data preprocessing to feature learning, and then to test case generation, the present invention provides an end-to-end solution, which is relatively rare in existing test case generation technologies.
[0042] Data-driven generation strategy: Different from the traditional rule-based method, this invention adopts a data-driven strategy, using deep learning networks to extract information from actual data to generate more accurate and effective test cases.
[0043] 3. Test case coverage evaluation: By analyzing the correspondence between test cases and software requirements through the Bi-LSTM network, potential coverage blind spots can be automatically identified. This method is objective and efficient, and can systematically discover functional points that are not covered by existing test cases.
[0044] The coverage evaluation results can guide testers to supplement or optimize test cases in a targeted manner. Through the analysis of the Bi-LSTM network, testers can clearly understand which functional points require more test cases, thereby improving the comprehensiveness and effectiveness of the test. The coverage is calculated as follows: Let (T) be the test case set, (R) be the software requirement set, (C(T, R)) be the correspondence between the test case (T) and the software requirement (R), (C(T,R)_covered) be the actual covered requirement set, (|R|) be the total number of elements in the requirement set, (|C(T,R)_covered|) be the total number of elements in the actual covered requirement set, and the coverage calculation formula is: The advantages are: Deep learning driven coverage evaluation: Using Bi-LSTM network to evaluate test case coverage is an innovative deep learning method in the field of test evaluation, which can more accurately identify deficiencies in test cases.
[0045] Double coverage of functions and codes: Focusing not only on the coverage at the code level but also on the coverage at the functional requirement level, this double coverage assessment ensures that the test cases can more comprehensively reflect the actual usage of the software.
[0046] Automatically identify blind spots: Automatically identify coverage blind spots through the Bi-LSTM network, providing an efficient and objective test case optimization method.
[0047] 4. Optimize the test case review process: The Bi-LSTM network is used to automatically evaluate the quality of test cases, including the effectiveness, necessity and coverage of test cases. Through pre-set evaluation criteria, the network can quickly screen out high-quality test cases.
[0048] By introducing a preliminary screening mechanism, only those test cases that the Bi-LSTM network evaluates as having possible problems or low quality will be submitted to the reviewers. In this way, the reviewers can focus on the test cases that need the most attention, improving the efficiency and accuracy of the review.
[0049] In order to better illustrate the technical effect of the present invention, the present invention provides the following specific embodiments to illustrate the above technical process: Embodiment 1: A software test case generation system based on a bidirectional long short-term memory algorithm, comprising: 1. Data preprocessing module 1.1 Text Extraction and Cleaning Extract functional descriptions, user stories, and acceptance criteria from the requirements documents of software projects; extract code comments, class names, method names, and variable names from the code base to understand the behavior and structure of the software; extract error information, exception reports, and system status from log files to identify abnormal lines of the software.
[0050] Use natural language processing technology to clean text, including removing irrelevant characters, unifying terminology, and eliminating ambiguity.
[0051] 1.2 Word segmentation and vectorization The cleaned text is segmented, that is, the cleaned text is decomposed into a sequence of words or phrases, which is the basic step of text analysis.
[0052] The word segmentation results are converted into vector representations using the Word2Vec model. Word2Vec is a neural network model that can learn the contextual relationship of words in a text and map each word into a vector space of fixed dimension. Each word or phrase is represented as a 100-dimensional vector, which can capture the semantic information of the word and provide a suitable input format for the subsequent Bi-LSTM network.
[0053] 2. Bidirectional Long Short-Term Memory Network (Bi-LSTM) Construction 2.1 Input Layer 2.1.1 Input Data Format Data source: data available in the Bi-LSTM network processed by the data preprocessing module.
[0054] Data representation: Each text data item is converted into a sequence, where each element represents a word or token. These words or tokens are the basic units of text data, which can be words, phrases, or specific code elements.
[0055] 2.1.2 Input vector dimensions Word embedding dimension: Each word or token is converted into a vector of dimension 100 using word embedding technique. The conversion captures the semantic information of the vocabulary, enabling machine learning models to better understand text data.
[0056] Sequence representation: Each word in a text sequence is represented as a 100-dimensional vector, and the entire sequence thus forms a three-dimensional data structure, where the first dimension is the sequence length, the second dimension is the word embedding dimension (100), and the third dimension is the batch size (if processing multiple sequences).
[0057] 2.1.3 Input layer function Text vectorization: The core function of the input layer is to convert text sequences into numerical vectors that can be processed by the Bi-LSTM network. Use a pre-trained word embedding model (such as Word2Vec or GloVe) to map each word to a 100-dimensional vector. Combine all word vectors in order into a matrix with a shape of [sequence length, word embedding dimension] Example: Suppose there is a sentence containing 10 words. After word embedding, the input layer will receive a 10×100 matrix as input. Simplified Python code example; import numpy as np from gensim.models import Word2Vec # Assume we have a pre-trained Word2Vec model pretrained_w2v_model = Word2Vec.load('pretrained_word2vec.model') # Word segmentation function, convert text data into a word list def tokenize(text): # Here we use simple space segmentation. In actual applications, more complex segmentation methods may be needed. return text.split() # Text vectorization function def vectorize_text(text, word2vec_model, vector_size=100): tokens = tokenize(text) word_vectors = [word2vec_model.wv[word] for word in tokens if word inword2vec_model.wv] # If the sequence length is less than the preset length, it will be padded; if it exceeds the preset length, it will be truncated padded_word_vectors = np.pad(word_vectors, ((0, max(0, vector_size -len(word_vectors))), (0, 0)), 'constant') return padded_word_vectors[:vector_size, :] # Example text sample_text = "The quick brown fox jumps over the lazy dog" # Call function to vectorize text vectorized_text = vectorize_text(sample_text, pretrained_w2v_model) print(vectorized_text.shape) # The output should be (10, 100) if the sample text has exactly 10 words.
[0058] 2.2 Hidden Layer 2.2.1 Hidden layer structure The Bi-LSTM network contains two hidden layers, each of which consists of 128 Bi-LSTM units.
[0059] Each Bi-LSTM unit is designed to learn long-term dependencies in sequence data, which is crucial for understanding and generating test cases.
[0060] 2.2.2 Bi-LSTM unit settings Input Gate: Responsible for controlling the input of new information into the cell state.
[0061] Forget Gate: Responsible for deciding which information should be forgotten from the cell state.
[0062] Output Gate: Responsible for controlling the output of cell state information to the hidden state.
[0063] Cell State: is the core of the LSTM unit, which carries the information passed through the sequence.
[0064] Activation function: In the input gate, forget gate, output gate, and cell state, the tanh function is used as the activation function to introduce nonlinear characteristics.
[0065] Tanh function, that is, hyperbolic tangent function: ; Where e is the base of the natural logarithm (approximately equal to 2.71828). The tanh function maps the input value to the interval (-1, 1) and has the ability to introduce nonlinear characteristics.
[0066] 2.2.3 Bidirectional structure Hidden layer design: Each hidden layer consists of a forward LSTM and a backward LSTM. This structure enables the network to capture the forward and backward dependencies of sequence data simultaneously.
[0067] Forward LSTM: Function: Process sequence data, learn and encode the forward context information of each time step from the beginning to the end of the sequence.
[0068] Output: At each time step, the forward LSTM unit outputs a hidden state vector, denoted as
[0069] Backward LSTM: Function: Process sequence data, learn and encode the backward context information of each time step from the end to the beginning of the sequence.
[0070] Output: At each time step t, the backward LSTM unit outputs a hidden state vector, denoted as .
[0071] Output splicing: At each time step t, the hidden state of the forward LSTM is and the hidden state of the backward LSTM are concatenated to form a complete representation of that time step .
[0072] Splicing formula: ; in, is a vector of dimension 2n, where n is the dimension of the hidden state of each individual LSTM unit 2.2.4 Dropout Layer After the output of each Bi-LSTM layer, a Dropout layer is added with a Dropout rate of 0.5. Therefore, each neuron has a 50% probability of being dropped. This process is performed independently in each forward propagation and backpropagation, so different neurons are dropped in each iteration, which enhances the generalization ability of the model and prevents overfitting; In each forward propagation, the output of each neuron is , will be multiplied by a random ,if If is 0, is 0 (the neuron is discarded), if is 1, then Remain unchanged (the neuron is kept). This process is independent at each iteration, so different neurons are discarded at each iteration; ; is the neuron output after applying Dropout is a Bernoulli random variable, for each neuron i, its value is 1 with probability 1−p (the neuron is retained) and 0 with probability p (the neuron is discarded) is the original neuron output is the dropout rate, which is 0.5 in this example 2.3 Output Layer Output layer structure: The output layer is located at the top of the Bi-LSTM network and is responsible for transforming the output of the hidden layer and mapping the output of the Bi-LSTM hidden layer to the final test case feature vector.
[0073] Output vector dimensions: The output vector has a dimension of 10 and represents the feature vector of the generated test case.
[0074] Activation function: The activation function of the output layer is used for classification tasks, using the softmax function, and for regression tasks, using the linear function The softmax function formula is: ; Among them, z is the linear combination of the fully connected layers, e is the base of the natural logarithm, and the softmax function outputs a probability distribution, where each element represents the predicted probability of the corresponding category.
[0075] 2.4 Network parameter settings 2.4.1 Network Structure 2.4.1.1 Network layers: Input Layer: Layer 1 (word embedding layer): Convert each word in the text sequence into a vector of fixed dimension.
[0076] Hidden Layer: 2 layers (each layer contains 128 Bi-LSTM units): Each Bi-LSTM layer combines forward and backward LSTM units to capture bidirectional dependencies in sequence data.
[0077] Output layer: Layer 1 (fully connected layer): converts the output of the hidden layer into the final prediction result.
[0078] 2.4.1.2 Parameter Configuration Dropout rate: The dropout rate after each hidden layer is 0.5: this means that in each training iteration, 50% of the neuron outputs in each hidden layer will be randomly dropped to reduce overfitting.
[0079] Optimizer: Gradient descent using Adam optimizer with a learning rate of 0.001: The Adam optimizer combines momentum and adaptive learning rate methods and generally performs well in deep learning models.
[0080] Loss function: Use the cross entropy loss function: for classification problems, it measures the difference between the probability distribution predicted by the model and the true label.
[0081] Number of training rounds: The number of training rounds is 50: the model will iterate the training data 50 times, and the model performance will be evaluated after each round of training to monitor the training progress and avoid overfitting.
[0082] Batch size: Batch size is 32: In each training iteration, the model will use 32 samples to update the parameters. This is a commonly used setting that provides enough information for gradient estimation while maintaining computational efficiency.
[0083] With the above parameter settings, the network will be ready to be trained to learn how to recognize and generate test cases from text data of software projects. 2.5 Network Training and Optimization 2.5.1 Training Data Preparation Data source: Use historical data (including requirement documents, code, and logs) as training data. These data contain rich contextual information, which is essential for training models to understand the specific requirements of software projects.
[0084] Data partitioning: The data is divided into training set and validation set in a ratio of 8:2. This means that 80% of the data is used to train the model, while the remaining 20% is used to verify the performance of the model and monitor overfitting during training.
[0085] 2.5.2 Training Process Forward propagation: The training data is input into the Bi-LSTM network and the output is calculated through the forward propagation of the network. The output of each time step will be passed to the next time step until the entire sequence is processed.
[0086] Loss calculation: The cross entropy loss function is used to calculate the error between the predicted result and the true label. The cross entropy loss function is suitable for classification problems and can effectively measure the difference between two probability distributions.
[0087] Backward Propagation: The network weights are updated according to the gradient of the loss function through the back-propagation algorithm. This process involves calculating the derivatives of the loss function with respect to each weight and using these derivatives to adjust the weights to reduce the prediction error.
[0088] 2.5.3 Hyperparameter Tuning Cross Validation: The optimal hyperparameter combination is selected through cross-validation. Cross-validation usually refers to dividing the data set into several subsets and using different subsets for training and validation to ensure the generalization ability of the model on unknown data.
[0089] Tuning process: Under each hyperparameter combination, the model is trained and its performance is evaluated on the validation set.
[0090] Compare the model performance under different hyperparameter combinations and select the hyperparameter combination that performs best on the validation set.
[0091] Retrain the model using the chosen combination of hyperparameters, this time typically using the entire training data (including the previous validation set) to achieve the best model performance.
[0092] Through the above training and optimization process, the Bi-LSTM network will be able to learn how to identify high-quality test cases from the text data of software projects, thereby improving the efficiency and accuracy of software testing. 3Test Case Generation Module 3.1 Feature Extraction Feature extraction purpose: The trained Bi-LSTM network is used to extract features of text data in order to identify key functions and potential risk points, which are the basis for generating effective test cases.
[0093] Feature extraction process: The preprocessed text data is input into the trained Bi-LSTM network.
[0094] The network extracts high-level features from the text through its learned weights and structure, which can capture the semantic and contextual information of the text.
[0095] Feature extraction usually occurs in the hidden layers of the Bi-LSTM network, and the outputs of these layers contain deep representations of the text.
[0096] Identification of key functions and risk points: By analyzing the output of the hidden layer, key functional descriptions and potential risk points in the text can be identified, which is crucial for subsequent test case generation.
[0097] 3.2 Use Case Generation Generate test cases: Based on the extracted features, test cases are automatically generated. This process involves converting the output of the network into specific test steps and conditions.
[0098] Test case content: Test Objective: Clearly states the functionality or component that the test case is intended to verify.
[0099] Input conditions: Describe the conditions that need to be met before executing the test case, including environment settings, data preparation, etc.
[0100] Execution steps: List the steps to execute the test case in detail, including operations and actions.
[0101] Expected results: Define the expected results or behaviors after the test is executed, which is used to determine whether the test passes.
[0102] Generation logic: The test case generation module may use rule engines, template filling, or sequence-to-sequence modeling techniques to convert features into test cases described in natural language.
[0103] The generated test cases need to be quality checked to ensure that they are executable, effective, and cover key functions and potential risk points.
[0104] 4Coverage evaluation and optimization module 4.1 Coverage Evaluation Purpose of the assessment: By analyzing the correspondence between the generated test cases and software requirements, the coverage of the test cases is evaluated to ensure that the test cases can fully cover the software requirements.
[0105] Evaluation Process: For each test case, determine the portion of the software requirements it covers.
[0106] Count the covered and uncovered demand points, and calculate coverage indicators such as demand coverage rate, statement coverage rate, etc.
[0107] Identification of uncovered demand points: Identify the requirements that are not covered by the test cases, which may be blind spots or omissions in the test.
[0108] Provide documentation and reports for identified uncovered requirements and provide clear guidance for supplementing test cases.
[0109] 4.4 Use Case Optimization Optimization purpose: According to the coverage evaluation results, the test cases are optimized to improve the overall coverage of the test cases and ensure the software quality.
[0110] Optimization measures: Add new test cases to cover uncovered requirements.
[0111] Modify existing test steps to cover more requirements or verify specific functions more accurately.
[0112] Optimization process: Based on the evaluation results, determine the optimization plan, including the test cases that need to be added or modified.
[0113] Implement optimization measures and update the test case library.
[0114] The Bi-LSTM network is used to re-evaluate the optimized test cases to ensure the effectiveness of the improvement measures.
[0115] If necessary, the evaluation and optimization process is repeated until a satisfactory coverage level is achieved.
[0116] Re-evaluation and verification: The optimized test cases are re-evaluated using the Bi-LSTM network to check whether all key demand points have been covered.
[0117] Verify whether the optimized test cases can effectively improve test coverage and ensure that no new defects are introduced.
[0118] Example 1, a method for generating software test cases based on a bidirectional long short-term memory algorithm, the specific steps are as follows: The following is a specific embodiment that describes how to use the Bi-LSTM network to generate test cases and perform coverage evaluation and optimization.
[0119] Example: Test case generation and optimization based on Bi-LSTM 1. Data Preprocessing Text Extraction: Extract functional requirement descriptions from the software project's requirement documents. Extract code comments and change logs from the code base. Extract user operation and system response records from log files.
[0120] Text cleaning: Remove extraneous formatting information, special characters, and whitespace. Standardize terminology and naming conventions to ensure consistency.
[0121] Word segmentation and vectorization: Use the word segmentation tool to segment the cleaned text. Use the Word2Vec model to convert the word segmentation results into a 100-dimensional vector representation.
[0122] 2. Network parameter settings Network structure: Input Layer: Word embedding layer, which inputs word vectors into the network; Hidden layer: 2 layers of Bi-LSTM, 128 units per layer; Output layer: A fully connected layer that outputs the predictions for the test case.
[0123] Parameter configuration: Dropout rate: 0.5; Optimizer: Adam, learning rate 0.001; Loss function: cross entropy loss Number of training rounds: 50 Batch size: 32 3. Test case generation module Feature Extraction: The preprocessed text data is input into the trained Bi-LSTM network. The output of the hidden layer is extracted as the feature of the text data.
[0124] Use case generation: Generate test cases using predefined templates based on the extracted features. Test cases include test objectives, input conditions, execution steps, and expected results. For example: "Test objective: Verify user login function. Input conditions: Correct username and password. Execution steps: Enter username and password, click Login. Expected result: User successfully logs into the system." 4. Coverage evaluation and optimization module Coverage Assessment: Map the generated test cases to determine the requirements they cover. Calculate the requirement coverage and identify uncovered requirements. For example, it is found that the requirement point "password strength verification" is not covered.
[0125] Use case optimization: Design new test cases or modify existing test steps for uncovered demand points. Update the test case library and use the Bi-LSTM network to re-evaluate the optimized test cases. For example, design a test case for "password strength verification", such as: "Test objective: Verify password strength. Input conditions: Password that does not meet strength requirements. Execution steps: Try to register with a weak password. Expected results: The system prompts that the password strength is insufficient." Add the new test case to the test case library and use the Bi-LSTM network to re-evaluate to confirm that the coverage is improved. In the several embodiments provided by the present invention, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely schematic. For example, the division of the modules, modules or units is only a logical function division. There may be other division methods in actual implementation, such as multiple units, modules or components can be combined or integrated into another device, or some features can be ignored or not executed.
[0126] The units may or may not be physically separated, and the components displayed as units may be one physical unit or multiple physical units, that is, they may be located in one place or distributed in multiple different places. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0127] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0128] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part, and / or installed from a removable medium. When the computer program is executed by the central processing unit (CPU), the above-mentioned functions defined in the method of the present invention are executed. It should be noted that the above-mentioned computer-readable medium of the present invention can be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium can be, for example, but not limited to, a system, device or device of an electrical, magnetic, optical, electromagnetic, infrared segment, or semiconductor, or any combination of the above.
[0129] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0130] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any changes or substitutions within the technical scope disclosed by the present invention should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.
Claims
1. A method for generating software test cases based on a bidirectional long short-term memory algorithm, characterized in that: The following steps are involved: Get the files to be processed; Preprocess the files to be processed to obtain preprocessed text data; The preprocessed text data is input into the trained Bi-LSTM network for feature extraction to obtain text features; Generate test cases based on text features.
2. The software test case generation method based on the bidirectional long short-term memory algorithm according to claim 1 is characterized in that: Preprocessing the file to be processed to obtain preprocessed text data specifically includes the following steps: Perform text cleaning on the files to be processed, remove irrelevant format information, special characters and blank characters, and obtain text-cleaned data; Perform word segmentation on the data after text cleaning to obtain the word segmentation results; The word segmentation results are vectorized to obtain preprocessed text data.
3. The software test case generation method based on the bidirectional long short-term memory algorithm according to claim 2 is characterized in that: The word segmentation results are vectorized to obtain preprocessed text data, which specifically includes the following steps: Use the Word2Vec model to convert the word segmentation results into vector representations, map each word into a vector space of fixed dimension, and represent each word as a 100-dimensional vector as preprocessed text data; The preprocessed text data is a sequence, in which each element represents a word or a tag.
4. The method for generating software test cases based on a bidirectional long short-term memory algorithm according to claim 3, characterized in that: The Bi-LSTM network includes an input layer, a hidden layer and an output layer; The text data input by the input layer is pre-processed text data; Each preprocessed text data is converted into a sequence, where each element represents a word or a token, which are the basic units of text data, and the basic units are words, phrases or specific code elements; The word embedding dimension of the input vector is: Each word or token is converted into a vector of dimension 100 through word embedding technique; the conversion captures the semantic information of the vocabulary; The sequence representation of the input vector is as follows: Each word in a text sequence is represented as a 100-dimensional vector, and the entire sequence thus forms a three-dimensional data structure, where the first dimension is the sequence length, the second dimension is the word embedding dimension, and the third dimension is the batch size.
5. The method for generating software test cases based on the bidirectional long short-term memory algorithm according to claim 4, characterized in that: The Bi-LSTM network includes two hidden layers, each of which is composed of 128 Bi-LSTM units; each Bi-LSTM unit is used to learn long-term dependencies in sequence data; The Bi-LSTM unit is set as: Input gate: responsible for controlling the input of new information into the cell state; Forget gate: responsible for deciding which information should be forgotten from the cell state; Output gate: responsible for controlling the output of cell state information to the hidden state; Cell state: carries information transmitted through the sequence; Activation function: In the input gate, forget gate, output gate and cell state, the tanh function is used as the activation function to introduce nonlinear characteristics; The tanh function is the hyperbolic tangent function: ; Where e is the base of the natural logarithm; the tanh function maps the input value to the interval (-1, 1) and has the ability to introduce nonlinear characteristics; Each hidden layer consists of a forward LSTM and a backward LSTM, which enables the network to capture the forward and backward dependencies of sequence data simultaneously; The function of the forward LSTM is to process sequence data, learn and encode the forward context information of each time step from the beginning to the end of the sequence; The output of the forward LSTM is: At each time step, the forward LSTM unit outputs the hidden state vector ; The function of backward LSTM is: to process sequence data, learn and encode the backward context information of each time step from the end to the beginning of the sequence; The output of the backward LSTM is: At each time step t, the backward LSTM unit outputs the hidden state vector ; Output concatenation: At each time step t, the hidden state vector of the forward LSTM and the hidden state vector of the backward LSTM Splice together to form a complete representation of this time step ; The splicing formula is: ; Where: is a vector of dimension 2n, where n is the dimension of the hidden state of each individual LSTM unit; After the output of each Bi-LSTM layer, a Dropout layer is added with a Dropout rate of 0.
5. Each neuron has a 50% probability of being dropped. This process is performed independently in each forward propagation and back propagation. In each forward propagation, the output of each neuron is will be multiplied by a random ,if If is 0, is 0, that is, the neuron is discarded; if is 1, then Remain unchanged, that is, the neurons are retained; this process is independent at each iteration, so different neurons are discarded at each iteration; ; Where: is the neuron output after applying Dropout; is a Bernoulli random variable, and for each neuron i, its value is 1 with probability , that is, the neuron is retained; the probability of being 0 is p, that is, the neuron is discarded; is the raw neuron output; is the Dropout rate.
6. The method for generating software test cases based on the bidirectional long short-term memory algorithm according to claim 5, characterized in that: The output layer is located at the top of the Bi-LSTM network and is responsible for converting the output of the hidden layer and mapping the output of the Bi-LSTM hidden layer to the final test case feature vector; the dimension of the output vector is 10, representing the feature vector of the generated test case; The activation function of the output layer uses the softmax function for classification tasks and the linear function for regression tasks: The softmax function formula is: ; Where: z is the linear combination of the fully connected layers; e is the base of the natural logarithm, and the softmax function outputs a probability distribution; each element represents the predicted probability of the corresponding category.
7. The method for generating software test cases based on a bidirectional long short-term memory algorithm according to claim 6, characterized in that: The parameter configuration of the Bi-LSTM network is: Optimizer: Use Adam optimizer for gradient descent with a learning rate of 0.001; Loss function: Use the cross entropy loss function for classification problems to measure the difference between the probability distribution predicted by the model and the true label; Number of training rounds: The number of training rounds is 50; the model will iterate the training data 50 times, and the model performance will be evaluated after each round of training to monitor the training progress and avoid overfitting; Batch size: The batch size is 32; In each training iteration, the model will use 32 samples to update the parameters.
8. The method for generating software test cases based on the bidirectional long short-term memory algorithm according to claim 7, characterized in that: The training process of the Bi-LSTM network is: Obtain historical data, and divide the historical data into a training set and a validation set; the ratio of the training set to the validation set is 8:2; Input the training data in the training set into the Bi-LSTM network; The output is computed through a forward pass through the network; the output of each time step is passed to the next time step until the entire sequence has been processed; Use the cross entropy loss function to calculate the error between the predicted result and the true label; Update the network weights according to the gradient of the loss function through the back-propagation algorithm, calculate the derivative of the loss function with respect to each weight, and use the derivative to adjust the weight; Select the optimal hyperparameter combination through cross-validation. Under each hyperparameter combination, train the model and evaluate its performance on the validation set. Compare the model performance under different hyperparameter combinations and select the hyperparameter combination with the best performance on the validation set as the selected hyperparameter combination. Retrain the model with the selected hyperparameter combination, using the training and validation sets to obtain the best model performance.
9. The method for generating software test cases based on the bidirectional long short-term memory algorithm according to claim 8, characterized in that: The following steps are also included: Perform coverage evaluation based on test cases and software requirements to obtain coverage; Optimize the corresponding test cases according to the coverage evaluation results to obtain the test case optimization results; The calculation formula of the coverage is: ; Where: T is the test case set; R is the software requirement set; C(T, R) is the correspondence between test cases and software requirements; C(T, R)_covered is the requirement set actually covered; |R| is the total number of elements in the requirement set; |C(T, R)_covered| is the total number of elements in the requirement set actually covered.
10. A software test case generation system based on a bidirectional long short-term memory algorithm, used to implement the software test case generation method based on a bidirectional long short-term memory algorithm as claimed in any one of claims 1 to 9, characterized in that: include: An acquisition module is used to obtain files to be processed; A preprocessing module is used to preprocess the files to be processed to obtain preprocessed text data; The feature extraction module is used to input the preprocessed text data into the trained Bi-LSTM network for feature extraction to obtain text features; The test case generation module is used to generate test cases based on text features.
Citation Information
Patent Citations
Test case automatic generation method based on pre-training language model
CN117539771A
Method and system for intelligently generating test case of railway centralized dispatching system
CN118467338A
Method for automated test case generation using natural language processing
IN202211027822A
Automated test case generation using computer vision
US20240143486A1
Test case set generation method, apparatus and device, and computer readable storage medium
WO2021253904A1
Cited By
Test case generation system construction method and test case generation method
CN120670326A
A test case generation system construction method and a test case generation method
CN120670326B