Test case automatic generation method and device, equipment and storage medium

By constructing a multidimensional feature vector mapping model using convolutional neural networks and bidirectional attention mechanisms, hardware test cases are automatically generated. This solves the problems of time-consuming and labor-intensive writing of traditional hardware test cases and low coverage, achieving efficient and accurate test case generation.

CN121597573APending Publication Date: 2026-03-03FIBERHOME TELECOMMUNICATION TECHNOLOGIES CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511742428.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-11-25
Publication Date
2026-03-03

AI Technical Summary

Technical Problem

Traditional hardware test case writing relies on manual labor, which is time-consuming, error-prone, inefficient, has insufficient coverage, and produces unreliable test cases, making it difficult to cope with complex and ever-changing testing requirements.

Method used

A multidimensional feature vector mapping model is constructed using convolutional neural networks and bidirectional attention mechanisms. Through data preprocessing and training with a weighted cross-entropy loss function, test cases are automatically generated, and parameters are optimized using historical data.

Benefits of technology

It reduces the amount of manual coding work, improves testing efficiency and coverage, reduces human error, and generates test cases that better meet testing requirements.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121597573A_ABST
    Figure CN121597573A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of system testing, and discloses a test case automatic generation method and device, equipment and a storage medium. The method comprises the following steps: performing data preprocessing on a test demand text and a test case text to obtain a test demand feature vector; constructing an initial multi-dimensional feature vector mapping model based on a convolutional neural network and a bidirectional attention mechanism; training the initial multi-dimensional feature vector mapping model through a weighted cross entropy loss function to obtain a multi-dimensional feature vector mapping model; inputting the test demand feature vector into a multi-dimensional feature vector mapping model to obtain an initial test case feature vector; and based on the initial test case feature vector, optimizing parameters of a historical case to obtain a test case meeting test requirements. By means of the method and device, the technical problems that in the prior art, the problems existing in traditional hardware test case writing cannot be solved, and complex and changeable test requirements are difficult to meet are solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of system testing technology, and in particular to a method, apparatus, device and storage medium for automatically generating test cases. Background Technology

[0002] In the field of system testing, writing test cases is a tedious and time-consuming task. Traditional hardware test case writing also suffers from the following problems: High reliance on manual labor: Testers need to analyze test requirements documents line by line and manually write test steps, which is time-consuming and prone to errors. Low testing efficiency: The inability to automatically identify similarities between different testing requirements leads to the repeated development of similar test cases, resulting in a large workload for manual writing and low testing efficiency. Insufficient coverage: Lack of a systematic approach to ensure test cases cover all dimensions of test requirements; The generated test cases have a high error rate: different testers may generate different test methods for the same test requirements, resulting in incomparable quality of the generated test cases and a high error rate.

[0003] In recent years, with the development of artificial intelligence and machine learning technologies, although research attempts to use these technologies to automatically generate test cases have gradually increased, most existing technologies rely on specific rules or templates, resulting in poor flexibility and adaptability of the generated test cases. This not only fails to solve the problems existing in traditional hardware test case writing, but also makes it difficult to cope with complex and ever-changing testing needs.

[0004] Therefore, there is an urgent need for a test case generation solution that can solve the problems of traditional hardware test case writing and cope with complex and ever-changing test requirements. Summary of the Invention

[0005] This application provides a method, apparatus, device, and storage medium for automatically generating test cases, which can solve the technical problems in the prior art that not only cannot solve the problems existing in the writing of traditional hardware test cases, but also have difficulty in dealing with complex and ever-changing test requirements.

[0006] To achieve the above objectives, this application provides the following technical solution: A method for automatically generating test cases, the method comprising: Data preprocessing is performed on the test requirement text and test case text to obtain the test requirement feature vector; An initial multidimensional feature vector mapping model is constructed based on convolutional neural networks and bidirectional attention mechanisms; The initial multidimensional feature vector mapping model is trained using a weighted cross-entropy loss function to obtain a multidimensional feature vector mapping model. The test requirement feature vector is input into the multidimensional feature vector mapping model to obtain the initial test case feature vector output by the multidimensional feature vector mapping model. Based on the initial test case feature vector, the parameters of the historical test cases are optimized to obtain test cases that meet the testing requirements.

[0007] Based on the same inventive concept, embodiments of this application also provide a test case automatic generation device, the device comprising: The data preprocessing module is configured to preprocess the test requirement text and test case text to obtain test requirement feature vectors. The model building module is configured to build an initial multidimensional feature vector mapping model based on a convolutional neural network and a bidirectional attention mechanism. The model training module is configured to train the initial multidimensional feature vector mapping model using a weighted cross-entropy loss function to obtain a multidimensional feature vector mapping model. The test case generation module is configured to input the test requirement feature vector into the multidimensional feature vector mapping model to obtain the initial test case feature vector output by the multidimensional feature vector mapping model; based on the initial test case feature vector, the parameters of historical test cases are optimized to obtain test cases that meet the test requirements.

[0008] Based on the same inventive concept, this application also provides an electronic device, including: a memory and a processor; the processor is used to read and execute a computer program stored in the memory to implement the steps of the aforementioned automatic test case generation method.

[0009] Based on the same inventive concept, embodiments of this application also provide a computer storage medium storing computer-executable instructions, which, when executed, implement the steps of the aforementioned test case automatic generation method.

[0010] The technical effects and advantages of this application are as follows: Automatic test case generation reduces the workload of manual writing and significantly improves testing efficiency; By analyzing historical data, we can cover more test scenarios and improve test coverage. Based on historical data and multidimensional feature vector mapping models, test cases are generated by prediction, which reduces the reliance on test engineers, lowers labor costs and human error, improves the accuracy of generated test cases, and makes the generated test cases more in line with test requirements. This application solves the technical problems in the prior art, which not only cannot solve the problems of writing traditional hardware test cases, but also cannot cope with complex and ever-changing test requirements.

[0011] Other features and advantages of this application will be set forth in the description which follows, and will be apparent in part from the description, or may be learned by practicing the application. The objectives and other advantages of this application may be realized and obtained by means of the structures pointed out in the description, claims and drawings. Attached Figure Description

[0012] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0013] Figure 1 A flowchart illustrating the method provided in the embodiments of this application; Figure 2 A schematic diagram of the local feature matrix extracted by a convolutional neural network; Figure 3 for Figure 1 A detailed flowchart of step S50; Figure 4 This is a schematic diagram of the functional modules of an embodiment of the test case automatic generation device of this application; Figure 5 This is a schematic diagram of the structure of an electronic device according to an embodiment of this application. Detailed Implementation

[0014] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0015] To address the shortcomings of existing technologies, refer to Figure 1 This application discloses a method for automatically generating test cases, including: Step S10: Perform data preprocessing on the test requirement text and test case text to obtain the test requirement feature vector; Further, in one embodiment, step S10 includes: Step S101: Convert the unstructured description in the test requirement text into a semantic vector; In this embodiment, six feature attributes are defined for the test requirement feature vector: test object, test object type, test signal sender, test signal receiver, test content, and test pass criteria. The test cases adopt a structured data model in JSON format.

[0016] Taking the I2C channel of the external EEPROM chip on the backplate as an example, the six characteristic attributes required for the test are as follows: Test object: I2C bus; Test object type: Bus; Test signal transmitter: CPU; Test signal receiver: EEPROM chip; Test content: The CPU reads and writes the 0xa register of the EEPROM chip at a rate of 100K; The test pass standard is: 100 read and write operations with identical data.

[0017] Unstructured descriptions in test requirements are transformed into semantic vectors to capture implicit technical details and logical relationships. Taking the unstructured description "The test content is the CPU reading and writing the 0xa register of the EEPROM chip at a rate of 100K" as an example, the implementation process is as follows: 1. Feature Text Cleaning: Remove punctuation and special characters, standardize abbreviations (e.g., replace "khz" with "KHz"), and perform word segmentation to obtain the segmented text. For example: Input: "CPU reads and writes register 0xa at a rate of 100K". Output: ["CPU", "100K", "speed", "read / write", "0xa", "register"]; 2. Use BERT to perform vector encoding on the segmented text.

[0018] A pre-trained BERT-based, multilingual-cased model (supporting mixed Chinese and English) is used to encode word vectors in the segmented text. The segmented text is input into a 3-layer Transformer encoding layer (HeadProjection + LayerNorm) of the BERT model, which outputs a high-resolution word vector (768 dimensions) for each word. The semantic similarity between the segmented texts is determined by the cosine similarity between the dynamic semantic vectors of the BERT model (the high-resolution word vector (768 dimensions) for each word).

[0019] 3. Dynamic parameter extraction.

[0020] By leveraging BERT's Named Entity Recognition (NER) capabilities, key dynamic parameters (such as "100K" and "0xa") can be extracted from the test requirements. For example, in training samples, data is read and written to address 0xa. The extracted key dynamic parameters are preserved in a semantically symbolic form (such as reg_addr:0xa) to facilitate the subsequent generation of test step parameters by the mapping model.

[0021] Step S102: Convert the non-standardized expressions in the test requirement text into feature indexes; In this embodiment, non-standardized expressions in the test requirement text are converted into unified feature indexes to resolve terminological ambiguities in the test requirements. Technical implementation steps: 1. Construct a multi-level dictionary tree.

[0022] The test requirement characteristics (such as test object and test object type) are abstracted into a tree-like classification structure.

[0023] Multilevel dictionary tree:

[0024] 2. Dynamic dictionary matching algorithm.

[0025] This application's embodiment uses the longest matching method, sequentially matching terms in the test requirement text, prioritizing the longest path. For example: Input: "FM24C256E Register Test"; Match: Subclass["FM24C256E"] Parent class ["EEPROM chip"] Final mapping result (storage device) EEPROM chip FM24C256E).

[0026] 3. Self-learning dictionary update After generating new test cases, this system will automatically categorize the newly emerging terms into the dictionary tree; After the above operations, a fixed feature index is output, which is the final mapping result.

[0027] Step S103: Based on the semantic vector and the feature index, obtain the test requirement feature vector.

[0028] Further, in one embodiment, step S103 includes: Substituting the semantic vector and the feature index into a preset formula, the initial test requirement feature vector is obtained; The initial test requirement feature vector is normalized to obtain the test requirement feature vector; The preset formula is as follows:

[0029] In the formula, x represents the initial test requirement feature vector, and p represents the feature index. Represents a semantic vector. The weights of the semantic vectors are represented.

[0030] In this embodiment, the standardized test requirement feature attributes are synthesized into a final test requirement feature vector. Technical implementation steps: 1. Feature Dimension Division: The six features of the test requirements are divided into fixed structured features and variable structured features. The fixed structured features are as follows: Test object dictionary index values ​​(discrete integers, discrete feature codes); Test signal transmitter / receiver Dictionary index value; The variable structured features are as follows: Test content BERT dynamic semantic vectors (768 dimensions); Test pass standard BERT dynamic semantic vector (768 dimensions).

[0031] 2. Vector synthesis strategy: A weighted concatenation strategy is used to generate the final feature vector. Specifically: Substitute the semantic vector and feature index into the preset formula The initial test requirement feature vector is obtained, and then normalized to eliminate dimensionality differences, resulting in the final test requirement feature vector. In the formula, x represents the initial test requirement feature vector, and p represents the feature index. Represents a semantic vector. The weights of the semantic vectors are represented.

[0032] The initial test requirement feature vector is normalized to obtain the test requirement feature vector. The specific algorithm is as follows: assuming a given initial test requirement feature vector... Its minimum value is The maximum value is For each element The following normalization can be performed: In the formula, This represents the first feature vector in the test requirement. One element, This represents the first feature vector in the initial test requirements. One element, This represents the minimum value in the initial test requirement feature vector. This represents the maximum value in the initial test requirement feature vector.

[0033] Step S20: Construct an initial multidimensional feature vector mapping model based on a convolutional neural network and a bidirectional attention mechanism; In this embodiment, a convolutional neural network (CNN) and a bidirectional attention mechanism are combined to obtain an initial multidimensional feature vector mapping model. By integrating the local features of the CNN with the global dependencies of the bidirectional attention mechanism, the overall mapping effect is greatly improved. The role of the CNN is to capture local adjacent features (such as CPU features) in testing requirements. EEPROM). The role of the bidirectional attention mechanism: to establish long-distance dependencies (such as mapping rules between "test content" and "test method"). CNN's local perception enhances microstructural features, while the attention mechanism is responsible for cross-dimensional logical connections, such as the overall mapping between the test content "requires reading register 0x0a" and the test method "writes to 0xaa and reads back, writes to 0x55 and reads back." The complementary feature processing of both avoids the shortcomings of CNN in modeling long-distance dependencies, while also avoiding the overfitting risk of the attention mechanism.

[0034] Specifically, in one embodiment, the convolutional neural network (CNN) structure is designed as follows: (1) Convolution kernel configuration: Kernel dimension: 1D convolution (single-dimensional convolution) is used to process the input feature vector channel by channel.

[0035] The specific parameters are as follows: Input channels: Number of input feature dimensions K=6; Output channels: set to 128, the optimal combination needs to be verified through experiments; Kernel window size: Set to 3 to capture third-order adjacency relationships, such as "test object". Sending end (Test content combination) Stride: Set to 1 to ensure coverage of all adjacent combinations; Padding: Use "same" padding to keep the feature length unchanged.

[0036] Design goal: To extract the combination relationship of three consecutive features (such as the combination of test object type + sender + receiver) using a convolution kernel with a window size of 3.

[0037] (2) Hierarchical expansion: Multi-layer convolution: Set up two convolutional layers (CNN-1 and CNN-2). CNN-1 extracts low-order combined features, and CNN-2 extracts high-order combined features.

[0038] Channel expansion: CNN-1: Extracts basic features of third-order adjacency combinations (such as bus + CPU + EEPROM), outputting 128-dimensional features. CNN-2: Further extracts higher-order features of cross-layer combinations (such as the complex dependencies between bus-CPU-EEPROM and EEPROM-register read / write), expanding to 256-dimensional features, strengthening the representation of key substructures.

[0039] The feature extraction process of a convolutional neural network (CNN) is as follows: (1) Local adjacency feature extraction: Taking the input feature sequence F=[f1, f2, ..., f6] as an example, CNN-1 processes it by sliding convolutional kernels with a window size of 3: First window: [f1, f2, f3] (test object type + sender + receiver), extract the third-order combination pattern; The second window: [f2, f3, f4], captures the association between the signal terminal combination and the test method; The third window: [f3, f4, f5], extracts the relationship between hardware connection rules and test content; The fourth window: [f4, f5, f6], extracts the relationship between the test content and the test pass criteria; Slide the convolution kernel with a window size of 3 until the sliding window covers all adjacent combinations.

[0040] Each window learns its corresponding latent layer weights through a convolutional kernel: , =1, 2, ..., 4; In the formula, Indicates the convolutional order. The feature vector after convolution of several windows (128 dimensions). The Conv() function is used to calculate the convolution or polynomial multiplication of two vectors. =[ , +1, +2] indicates the window size. Represents the convolution kernel weight matrix. This indicates the bias term.

[0041] (2) Feature fusion: Multiple window features of CNN-1 The concatenation results in G, which is then input into CNN-2 for feature fusion, thereby further extracting higher-order combinations and obtaining the local feature matrix extracted by CNN. CNN-2 learns cross-window feature dependencies (such as the overall correspondence between hardware topology and test content) through a larger window. After feature fusion, the CNN extracts a local feature matrix. like Figure 2 As shown, Figure 2 Each row in the table represents a feature of a local combination, where, This represents the response value of the first local combination on the features extracted by the first convolutional kernel of the CNN. This represents the response value of the first local combination on the features extracted by the second convolutional kernel of the CNN. This represents the response value of the first local combination on the features extracted by the 256th convolutional kernel of the CNN. This represents the response value of the second local combination on the features extracted by the first convolutional kernel of the CNN. This represents the response value of the Lth local combination on the features extracted by the 256th convolutional kernel of the CNN.

[0042] Furthermore, in one embodiment, the bidirectional attention mechanism is designed as follows: It extends the attention mechanism of traditional Transformer by using a two-layer Transformer decoder and a dynamically adjustable regularization term to model the implicit dependency of non-adjacent parts.

[0043] A two-layer Transformer decoder is used to model the model separately: The first layer decoder, Query direction, models the relationship between test content (Q) and test method (M) through an attention mechanism; Input: Local adjacency features in HCNN related to the "test content"; Output: Matched test method features, reinforcing the mapping features between test content and methods.

[0044] The second layer decoder, Key direction: establishes a mapping between the test pass criteria (K) and dynamic parameters (e.g., "test frequency adjustment based on the number of failures"). Input: Features in HCNN related to the "test criteria"; Output: Generates an adjustable dynamic parameter configuration.

[0045] Furthermore, the bidirectional attention weight calculation formula designed through the embodiments of this application is as follows:

[0046] In the formula, Q represents the feature vector matrix of the test content, K represents the feature vector matrix of the test pass standard, V represents the parameter feature vector matrix of the test method, Attention(Q,K,V) represents the formula for calculating the bidirectional attention weights, softmax() represents the nonlinear normalization function, and T represents the matrix transpose. This represents the vector dimension of the test standard eigenvector matrix K. This represents the regularization term.

[0047] Compared to traditional attention mechanisms, the embodiments of this application introduce regularization terms. By adjusting the regularization term The value controls the concentration or smoothness of attention weights, enhancing the model's ability to capture key features (test methods, signal combinations, etc.) in hardware testing requirements, thereby improving the accuracy and coverage of test case generation.

[0048] The experimental values ​​of are shown in Table 1.

[0049] Table 1

[0050] Step S30: Train the initial multidimensional feature vector mapping model using the weighted cross-entropy loss function to obtain the multidimensional feature vector mapping model; Further, in one embodiment, step S30 includes: Based on the prediction accuracy of each feature, the weights of each test requirement feature vector are dynamically adjusted using the weight adjustment formula to obtain the weights of the weighted cross-entropy loss function. Based on the weights of the weighted cross-entropy loss function, the initial multidimensional feature vector mapping model is trained using the weighted cross-entropy loss function to obtain the multidimensional feature vector mapping model. The weight adjustment formula is as follows:

[0051] In the formula, This represents the weight of the i-th test requirement feature vector in the (t+1)-th iteration. This represents the weight of the i-th test requirement feature vector in the t-th iteration. Let represent the weight of any test requirement feature vector among the j test requirement feature vectors in the t-th iteration. This represents the prediction accuracy of the i-th test requirement feature vector after the t-th iteration. The weighted cross-entropy loss function is as follows:

[0052] In the formula, Total Loss represents the loss value of the input feature vector samples. This represents the weight of the i-th test requirement feature vector. This represents the cross-entropy value of the i-th test requirement feature vector;

[0053] In the formula, This represents the total number of categories in the feature vector of the i-th test requirement. Let represent the one-hot encoding of the true label of the i-th test requirement feature vector, and k represent the k-th class of the i-th test requirement feature vector. Let represent the probability distribution predicted by the model for the i-th test requirement feature vector, and log() is the logarithmic function.

[0054] In this embodiment, an initial multidimensional feature vector mapping model is trained using a weighted cross-entropy loss function to obtain a multidimensional feature vector mapping model. During training, the weights of features in the weighted cross-entropy loss function are dynamically adjusted according to the prediction accuracy of each feature using a weight adjustment formula, achieving autonomous optimization of feature weights. This increases the weights of features with high errors, guiding the initial multidimensional feature vector mapping model to prioritize the optimization of key features, thereby obtaining a multidimensional feature vector mapping model.

[0055] The initial multidimensional feature vector mapping model is trained using a weighted cross-entropy loss function, thereby enhancing its ability to learn key feature attributes. For a single task (such as test method classification), the cross-entropy loss is defined as:

[0056] In the formula, This represents the total number of categories in the feature vector of the i-th test requirement. Let represent the one-hot encoding of the true label of the i-th test requirement feature vector, and k represent the k-th class of the i-th test requirement feature vector. Let represent the probability distribution predicted by the model for the i-th test requirement feature vector, and log() is the logarithmic function.

[0057] Extend the ordinary cross-entropy to a weighted cross-entropy form:

[0058] In the formula, Total Loss represents the loss value of the input feature vector samples. This represents the weight of the i-th test requirement feature vector. This represents the cross-entropy value of the i-th test requirement feature vector.

[0059] During the training of the initial multidimensional feature vector mapping model using the weighted cross-entropy loss function, the weights of the features in the weighted cross-entropy loss function need to be adjusted using the weight adjustment formula to make the value of the weighted cross-entropy loss function as small as possible.

[0060] Specifically, the weight adjustment formula is as follows:

[0061] In the formula, This represents the weight of the i-th test requirement feature vector in the (t+1)-th iteration. This represents the weight of the i-th test requirement feature vector in the t-th iteration. This represents the weight of any test requirement feature vector in the t-th iteration among the j test requirement feature vectors (j=1…6). Let represent the prediction accuracy of the i-th test requirement feature vector after the t-th iteration.

[0062] It should be noted that the prediction accuracy of the test requirement feature vector is calculated by comparing the actual prediction results of the current training batch with the standard values ​​of the features during the model's iterative training process. First, standard values ​​for the features are set, and initial weights are determined based on the importance of the features and the distribution of historical data. Through model training and prediction, the prediction accuracy of the features is calculated. Then, the weights are dynamically adjusted, and a weighted loss function is calculated.

[0063] Step S40: Input the test requirement feature vector into the multidimensional feature vector mapping model to obtain the initial test case feature vector output by the multidimensional feature vector mapping model; In this embodiment, after the new test requirements are processed by the data preprocessing module, a standardized test requirement feature vector is generated. The generated test requirement feature vector is then input into the multidimensional feature vector mapping model to obtain the initial test case feature vector output by the multidimensional feature vector mapping model.

[0064] Step S50: Based on the initial test case feature vector, optimize the parameters of the historical test cases to obtain test cases that meet the testing requirements.

[0065] Furthermore, in one embodiment, reference is made to Figure 3 , Figure 3 for Figure 1 A detailed flowchart of step S50. (See attached diagram.) Figure 3 As shown, step S50 includes: Step S501: Based on the cosine similarity formula, calculate the cosine similarity between the feature vector of the initial test case and the feature vector of each historical test case. Step S502: Select the N historical test case feature vectors with the highest cosine similarity to the initial test case feature vector as candidate test cases; Step S503: Based on the difference between the initial test case feature vector and the parameters of each candidate test case, the differential evolution algorithm is used to optimize and adjust the parameters of each candidate test case, and the candidate test case with the smallest difference after parameter optimization and adjustment is taken as the target candidate test case. Step S504: Use regular expressions and hierarchical dictionary matching to detect whether the tag parameters in the target candidate use cases conform to preset rules; Step S505: If the preset rules are met, the target candidate test case is used as the test case that meets the test requirements.

[0066] In this embodiment, the initial test case feature vectors output by the multidimensional feature vector mapping model provide a scientific basis for the fine-tuning and optimization of the test case generation module. Therefore, it is necessary to first select the historical data with the highest similarity, and then use the differential evolution algorithm to continuously optimize the adjusted historical test case feature vectors until they infinitely approach the theoretical optimal value predicted by the model (the initial test case feature vectors). This preserves the reliability of historical experience while making the new test cases more optimized and accurate than the historical ones.

[0067] Specifically, similarity calculation, parameter optimization, and compliance verification are performed on the feature vectors of the initial test cases to obtain test cases that meet the testing requirements.

[0068] Feature similarity calculation: Feature similarity is calculated using cosine similarity.

[0069] Based on the cosine similarity formula, given the feature vector of the initial test cases... and historical test case feature vectors Calculate the feature vector of the initial test cases. Feature vectors of historical test cases Cosine similarity between cosine similarity Defined as: .

[0070] Calculate the feature vectors of the initial test cases respectively. Cosine similarity between the feature vectors of each historical test case and the feature vectors of the test cases Multiple cosine similarity values ​​were obtained.

[0071] The cosine similarity calculation results are used as the ranking criterion. Historical test cases corresponding to the cosine similarity scores are sorted from highest to lowest. A Top-N matching mechanism is then used to select historical test cases with high matching scores as candidate test cases. Specifically, a similarity threshold is set. (like =0.75), only retain similarity ≥ Historical test cases. From those with a matching degree ≥ Select the top N (e.g., N=10) test cases from the historical test cases as candidate test cases.

[0072] Parameter optimization: Adjustable parameters (such as read / write counts, register addresses, etc.) are extracted from candidate test cases to construct a parameter space. Based on the difference between the initial test case feature vector and the adjustable parameters in the parameter space, a differential evolution algorithm (DE) is used to adjust the difference, aiming to minimize it. Attributes with higher weights are adjusted first. New parameter combinations are generated according to the DE mutation strategy (e.g., DE / rand / 1), and the adjustable parameter combination with the smallest difference is retained. This process ensures that the adjusted test case feature vector infinitely approximates the initial test case features. The candidate test case with the smallest difference after parameter optimization is selected as the target candidate test case.

[0073] To ensure that the target candidate use cases conform to the physical characteristics constraints of the hardware device, a compliance verification is required. Specifically: First, a rule base of constraint conditions conforming to the requirements of the hardware device under test is obtained, based on its physical characteristics; that is, preset rules are acquired. Then, rule matching is performed. For example, the preset rules are as follows: Bus characteristics: such as I²C maximum speed 800kHz, SPI maximum speed 32MHz; Port protocol: such as whether the sending / receiving end allows a certain protocol (e.g., CPU→EEPROM supports I²C); Dynamic parameter validity: For example, register addresses can only be in the range 0x00. Within the range of 0xFF; In one embodiment, rule matching is performed, specifically: by hierarchical dictionary matching, it is determined whether the test objects in the target candidate test cases can be matched and confirmed with the test objects in the constraint rule base; and by using regular expressions, it is determined whether the dynamic parameters in the target candidate test cases meet the parameter requirements in the constraint rule base. If the test object in the target candidate test case can be matched and confirmed with the test object in the constraint rule base, and the dynamic parameters in the target candidate test case meet the parameter requirements in the constraint rule base, then the marker parameters in the target candidate test case are determined to conform to the preset rules, and the target candidate test case is used as the test case that meets the test requirements.

[0074] If the test object in the target candidate test case cannot be matched with the test object in the constraint rule base, and / or the dynamic parameters in the target candidate test case do not meet the parameter requirements in the constraint rule base, then the marking parameters in the target candidate test case do not conform to the preset rules, the target candidate test case is marked as "unavailable" and returned to the manual review queue.

[0075] In this embodiment, the test requirement text and test case text are preprocessed to obtain a test requirement feature vector. An initial multidimensional feature vector mapping model is constructed based on a convolutional neural network and a bidirectional attention mechanism. The initial multidimensional feature vector mapping model is trained using a weighted cross-entropy loss function to obtain a multidimensional feature vector mapping model. The test requirement feature vector is input into the multidimensional feature vector mapping model to obtain the initial test case feature vector output by the multidimensional feature vector mapping model. Based on the initial test case feature vector, the parameters of historical test cases are optimized to obtain test cases that meet the test requirements. Through this embodiment, test cases are automatically generated, reducing the workload of manual writing and significantly improving testing efficiency. By analyzing historical data, more test scenarios can be covered, improving test coverage. Predicting and generating test cases based on historical data and the multidimensional feature vector mapping model reduces reliance on test engineers, lowers labor costs and human error, and improves the accuracy of generated test cases, making the generated test cases more in line with test requirements. This solves the technical problems of existing technologies, which not only cannot solve the problems of traditional hardware test case writing but also struggle to cope with complex and ever-changing test requirements.

[0076] Based on the same inventive concept, this application also provides an automatic test case generation device.

[0077] In one embodiment, reference is made to Figure 4 , Figure 4 This is a functional module diagram of an embodiment of the test case automatic generation device of this application. Figure 4 As shown, the test case automatic generation device includes: Data preprocessing module 10 is configured to preprocess test requirement text and test case text to obtain test requirement feature vectors; Model building module 20 is configured to build an initial multidimensional feature vector mapping model based on a convolutional neural network and a bidirectional attention mechanism; The model training module 30 is configured to train the initial multidimensional feature vector mapping model using a weighted cross-entropy loss function to obtain a multidimensional feature vector mapping model. The test case generation module 40 is configured to input the test requirement feature vector into the multidimensional feature vector mapping model to obtain the initial test case feature vector output by the multidimensional feature vector mapping model; based on the initial test case feature vector, the parameters of historical test cases are optimized to obtain test cases that meet the test requirements.

[0078] Optionally, in one embodiment, the data preprocessing module 10 is configured to: Convert unstructured descriptions in test requirement texts into semantic vectors; Convert non-standardized expressions in test requirement texts into feature indexes; Based on the semantic vector and the feature index, the test requirement feature vector is obtained.

[0079] Optionally, in one embodiment, the data preprocessing module 10 is configured to: Substituting the semantic vector and the feature index into a preset formula, the initial test requirement feature vector is obtained; The initial test requirement feature vector is normalized to obtain the test requirement feature vector; The preset formula is as follows:

[0080] In the formula, x represents the initial test requirement feature vector, and p represents the feature index. Represents a semantic vector. The weights of the semantic vectors are represented.

[0081] Optionally, in one embodiment, the bidirectional attention mechanism includes: a two-layer Transformer decoder and a regularization term; The formula for calculating the bidirectional attention weights is as follows:

[0082] In the formula, Q represents the test content feature vector matrix, K represents the test standard feature vector matrix, V represents the test method feature vector matrix, Attention(Q,K,V) represents the formula for calculating the bidirectional attention weights, softmax() represents the non-linear normalization function, and T represents the matrix transpose. This represents the vector dimension of the test standard eigenvector matrix K. This represents the regularization term.

[0083] Optionally, in one embodiment, the model training module 30 is configured to: Based on the prediction accuracy of each feature, the weights of each test requirement feature vector are dynamically adjusted using the weight adjustment formula to obtain the weights of the weighted cross-entropy loss function. Based on the weights of the weighted cross-entropy loss function, the initial multidimensional feature vector mapping model is trained using the weighted cross-entropy loss function to obtain the multidimensional feature vector mapping model. The weight adjustment formula is as follows:

[0084] In the formula, This represents the weight of the i-th test requirement feature vector in the (t+1)-th iteration. This represents the weight of the i-th test requirement feature vector in the t-th iteration. Let represent the weight of any test requirement feature vector among the j test requirement feature vectors in the t-th iteration. This represents the prediction accuracy of the i-th test requirement feature vector after the t-th iteration. The weighted cross-entropy loss function is as follows:

[0085] In the formula, Total Loss represents the loss value of the input feature vector samples. This represents the weight of the i-th test requirement feature vector. This represents the cross-entropy value of the i-th test requirement feature vector;

[0086] In the formula, This represents the total number of categories in the feature vector of the i-th test requirement. Let represent the one-hot encoding of the true label of the i-th test requirement feature vector, and k represent the k-th class of the i-th test requirement feature vector. Let represent the probability distribution predicted by the model for the i-th test requirement feature vector, and log() is the logarithmic function.

[0087] Optionally, in one embodiment, the test case generation module 40 is configured to: Based on the cosine similarity formula, the cosine similarity between the feature vector of the initial test case and the feature vector of each historical test case is calculated respectively. N historical test case feature vectors with the highest cosine similarity to the initial test case feature vector are selected as candidate test cases; Based on the difference between the initial test case feature vector and the parameters of each candidate test case, the differential evolution algorithm is used to optimize and adjust the parameters of each candidate test case, and the candidate test case with the smallest difference after parameter optimization and adjustment is taken as the target candidate test case. Using regular expressions and hierarchical dictionary matching, we detect whether the marked parameters in the target candidate use cases conform to preset rules; If the preset rules are met, the target candidate test case will be used as the test case that meets the testing requirements.

[0088] Optionally, in one embodiment, the test case generation module 40 is configured to: By using hierarchical dictionary matching, it is determined whether the test objects in the target candidate test cases can be matched with the test objects in the constraint rule base. Use regular expressions to determine whether the dynamic parameters in the target candidate use case meet the parameter requirements in the constraint rule base; If a match can be confirmed and the parameter requirements are met, then the marking parameters in the target candidate use case are determined to conform to the preset rules. If a match cannot be found and / or the parameter requirements are not met, then the marker parameters in the target candidate use case are determined to be inconsistent with the preset rules.

[0089] The functions of each module in the above-mentioned automatic test case generation device correspond to the steps in the above-mentioned automatic test case generation method embodiment, and their functions and implementation processes will not be described in detail here.

[0090] Based on the same inventive concept, embodiments of this application also provide an electronic device, the structure of which is as follows: Figure 5 As shown, it includes: a memory and a processor, wherein the processor is used to read and execute the computer program stored in the memory to implement the aforementioned method for automatically generating test cases.

[0091] Based on the same inventive concept, this application also provides a computer storage medium storing computer-executable instructions, which, when executed, implement the aforementioned method for automatically generating test cases.

[0092] Finally, it should be noted that while some processes described in the embodiments of this application include multiple operations or steps that appear in a specific order, it should be understood that these operations or steps may not be executed in the order they appear in the embodiments of this application, or may be executed in parallel. The sequence number of the operation is only used to distinguish different operations, and the sequence number itself does not represent any execution order. In addition, these processes may include more or fewer operations, and these operations or steps may be executed sequentially or in parallel, and these operations or steps may be combined.

[0093] The above description is merely a preferred embodiment of this application and is not intended to limit this application. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art can still modify the technical solutions described in the foregoing embodiments or make equivalent substitutions for some of the technical features. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.

Claims

1. A method for automatically generating test cases, characterized in that, The method includes: Data preprocessing is performed on the test requirement text and test case text to obtain the test requirement feature vector; An initial multidimensional feature vector mapping model is constructed based on convolutional neural networks and bidirectional attention mechanisms; The initial multidimensional feature vector mapping model is trained using a weighted cross-entropy loss function to obtain a multidimensional feature vector mapping model. The test requirement feature vector is input into the multidimensional feature vector mapping model to obtain the initial test case feature vector output by the multidimensional feature vector mapping model. Based on the initial test case feature vector, the parameters of the historical test cases are optimized to obtain test cases that meet the testing requirements.

2. The test case automatic generation method according to claim 1, characterized in that, The data preprocessing of the test requirement text and test case text to obtain the test requirement feature vector includes: Convert unstructured descriptions in test requirement texts into semantic vectors; Convert non-standardized expressions in test requirement texts into feature indexes; Based on the semantic vector and the feature index, the test requirement feature vector is obtained.

3. The test case automatic generation method according to claim 2, characterized in that, The process of obtaining the test requirement feature vector based on the semantic vector and the feature index includes: Substituting the semantic vector and the feature index into a preset formula, the initial test requirement feature vector is obtained; The initial test requirement feature vector is normalized to obtain the test requirement feature vector; The preset formula is as follows: In the formula, x represents the initial test requirement feature vector, and p represents the feature index. Represents a semantic vector. The weights of the semantic vectors are represented.

4. The test case automatic generation method according to claim 1, characterized in that, The bidirectional attention mechanism includes: two layers of Transformer decoders and regularization terms; The formula for calculating the bidirectional attention weights is as follows: In the formula, Q represents the test content feature vector matrix, K represents the test standard feature vector matrix, V represents the test method feature vector matrix, Attention(Q,K,V) represents the formula for calculating the bidirectional attention weights, softmax() represents the non-linear normalization function, and T represents the matrix transpose. This represents the vector dimension of the test standard eigenvector matrix K. This represents the regularization term.

5. The test case automatic generation method according to claim 1, characterized in that, The step of training the initial multidimensional feature vector mapping model using a weighted cross-entropy loss function to obtain the multidimensional feature vector mapping model includes: Based on the prediction accuracy of each feature, the weights of each test requirement feature vector are dynamically adjusted using the weight adjustment formula to obtain the weights of the weighted cross-entropy loss function. Based on the weights of the weighted cross-entropy loss function, the initial multidimensional feature vector mapping model is trained using the weighted cross-entropy loss function to obtain the multidimensional feature vector mapping model. The weight adjustment formula is as follows: In the formula, This represents the weight of the i-th test requirement feature vector in the (t+1)-th iteration. This represents the weight of the i-th test requirement feature vector in the t-th iteration. Let represent the weight of any test requirement feature vector among the j test requirement feature vectors in the t-th iteration. This represents the prediction accuracy of the i-th test requirement feature vector after the t-th iteration. The weighted cross-entropy loss function is as follows: In the formula, Total Loss represents the loss value of the input feature vector samples. This represents the weight of the i-th test requirement feature vector. This represents the cross-entropy value of the i-th test requirement feature vector; In the formula, This represents the total number of categories in the feature vector of the i-th test requirement. Let represent the one-hot encoding of the true label of the i-th test requirement feature vector, and k represent the k-th class of the i-th test requirement feature vector. Let represent the probability distribution predicted by the model for the i-th test requirement feature vector, and log() is the logarithmic function.

6. The test case automatic generation method according to claim 1, characterized in that, The step of optimizing the parameters of historical test cases based on the initial test case feature vector to obtain test cases that meet the testing requirements includes: Based on the cosine similarity formula, the cosine similarity between the feature vector of the initial test case and the feature vector of each historical test case is calculated respectively. N historical test case feature vectors with the highest cosine similarity to the initial test case feature vector are selected as candidate test cases; Based on the difference between the initial test case feature vector and the parameters of each candidate test case, the differential evolution algorithm is used to optimize and adjust the parameters of each candidate test case, and the candidate test case with the smallest difference after parameter optimization and adjustment is taken as the target candidate test case. Using regular expressions and hierarchical dictionary matching, we detect whether the marked parameters in the target candidate use cases conform to preset rules; If the preset rules are met, the target candidate test case will be used as the test case that meets the testing requirements.

7. The test case automatic generation method according to claim 6, characterized in that, The step of using regular expressions and hierarchical dictionary matching to detect whether the marked parameters in the target candidate use cases conform to preset rules includes: By using hierarchical dictionary matching, it is determined whether the test objects in the target candidate test cases can be matched with the test objects in the constraint rule base. Use regular expressions to determine whether the dynamic parameters in the target candidate use case meet the parameter requirements in the constraint rule base; If a match can be confirmed and the parameter requirements are met, then the marking parameters in the target candidate use case are determined to conform to the preset rules. If a match cannot be found and / or the parameter requirements are not met, then the marker parameters in the target candidate use case are determined to be inconsistent with the preset rules.

8. A test case automatic generation device, characterized in that, The device includes: The data preprocessing module is configured to preprocess the test requirement text and test case text to obtain test requirement feature vectors. The model building module is configured to build an initial multidimensional feature vector mapping model based on a convolutional neural network and a bidirectional attention mechanism. The model training module is configured to train the initial multidimensional feature vector mapping model using a weighted cross-entropy loss function to obtain a multidimensional feature vector mapping model. The test case generation module is configured to input the test requirement feature vector into the multidimensional feature vector mapping model to obtain the initial test case feature vector output by the multidimensional feature vector mapping model; based on the initial test case feature vector, the parameters of historical test cases are optimized to obtain test cases that meet the test requirements.

9. An electronic device, characterized in that, include: Memory, processor; The processor is configured to read and execute the computer program stored in the memory to implement the steps of the test case automatic generation method according to any one of claims 1-7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when executed, implement the steps of the test case automatic generation method according to any one of claims 1-7.