Deep redundant code test case identification method and system based on multi-dimensional information fusion and contrast learning, storage medium and computer device
Patent Information
- Application Number
- CN202610323598.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2026-03-17
- Publication Date
- 2026-09-22
- Estimated Expiration
- 2046-03-17
AI Technical Summary
现有工作已经证明,最小化InfoNCE损失等同于最大化互信息的下限,而在互信息最大化中不考虑数据增强
[0067]与现有技术相比,本发明具有以下优点和有益效果:1、本发明通过构建序列语义捕捉网络、语法结构捕捉网络和数据流捕捉网络分别提取代码中的序列语义,结构以及数据流信息,并通过无监督聚类的方式提升冗余测试用例识别的准确性。
Smart Images

Figure CN122195842B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of redundant code test case identification technology, specifically to a deep redundant code test case identification method, system, storage medium, and computer equipment based on multi-dimensional information fusion and comparative learning. Background Technology
[0002] Software testing is a widely used verification mechanism used to detect errors in software releases. As software evolves, the size of test case sets also grows, making the execution of all test cases time-consuming, resource-intensive, and sometimes even infeasible. These test case sets often contain similar or redundant cases, making it unlikely to detect new errors, and if left unaddressed, they will be repeatedly executed across multiple versions, especially in continuous integration environments. This repeated execution leads to significant waste of time and resources, particularly in large industrial systems.
[0003] Despite the continuous development of automated testing technologies, testing still relies on manual processes in many industries. For example, in the gaming industry, developers face challenges when writing automated tests, as test cases often need to be manually executed to test game objectives. These test cases are often defined by QA engineers or developers from different departments, and the problem of redundant test cases becomes particularly prominent as systems evolve and test suites expand. Manually identifying similar or duplicate test cases to reduce redundancy is an expensive and time-consuming task. Because different test writers may use different terminology to specify test cases, even for similar test objectives, naive methods (such as finding exact-matching test cases) are insufficient to capture all similarities. Therefore, adopting systematic and automated strategies to eliminate redundant test cases and developing technologies that can automatically identify similar test cases becomes particularly important, preventing QA and development teams from needlessly performing repetitive testing tasks.
[0004] Code, as a special type of modal data with structure and semantics, possesses not only certain language sequence characteristics but also strict syntactic structures (such as functions, control flow, and nesting relationships) and complex data flow dependencies (such as the propagation path between variable definition and usage). Sequence semantic information reflects the semantic composition of code at the surface level, revealing the semantic similarity of different test cases at the language level; syntactic structure information reflects the organization of code at the syntactic level, helping to understand the control logic and functional boundaries of test cases; data flow information further characterizes the dependencies between variables, reflecting the propagation path of values during the execution of test cases. These three types of information, from different perspectives, together constitute the complete semantic space of code, playing a complementary and crucial role in judging potential redundant relationships between test cases. Therefore, how to effectively integrate the three-dimensional information of code sequence, structure, and data flow to construct a high-quality representation for cluster analysis has become an important research direction for improving the accuracy of redundant test case identification.
[0005] Clustering, as a data mining technique, can categorize data without labeling. Its purpose is to group similar instances into the same cluster and dissimilar instances into different clusters. The K-means algorithm is one of the most popular clustering algorithms, proposed as early as 1967. Since then, many clustering algorithms have been developed and used to group data from various business and non-business sectors. Today, clustering is widely applied in various fields. For example, in the process of bank digitalization, in order to solve the major threat of money laundering, the DBSCAN clustering algorithm is applied in AMLRAS (Anti-Money Laundering Regulatory Application System) to detect and report suspicious financial transactions. After testing on large-scale financial data, AMLRAS can successfully identify possible fraudulent transactions, thereby preventing money laundering. In the medical field, clustering algorithms simplify the detection process of eye diseases by segmenting retinal vessels. The multivariate m-Medoids classifier has been used to detect neurovascularization in retinal images. In urban planning and construction, K-means clustering based on ant colony clustering plays a decisive role in determining the stations of industrial towns and economic hubs along highways. In addition, the GFDBSCAN clustering algorithm [5] can determine the geographical location of banks, schools and other facilities in strategically located cities. It can be seen that clustering plays a huge role in many application scenarios today.
[0006] Traditional text clustering methods convert text into a high-dimensional representation, such as BOW or TF-IDF, based on numerical statistics. Then, clustering algorithms are applied to divide text fragments into homogeneous groups with respect to a given distance function. The basic process first obtains the text's feature representation through a feature extractor, then applies it to a clustering algorithm for clustering, and finally calculates the clustering loss using a clustering model to obtain the final category classification. With the development of technology, various traditional clustering algorithms have emerged, giving rise to many classic text clustering algorithms. Commonly used traditional text clustering methods include hierarchical clustering, partitioning clustering, model-based clustering, and grid-based clustering. These traditional clustering algorithms played a significant role for a period of time; however, due to the separation of the feature extraction and clustering processes, the two cannot provide feedback to each other. Therefore, the clustering effect largely depends on the quality of the initial text feature representation, greatly limiting the performance of text clustering algorithms.
[0007] Due to the tremendous success of deep learning in recent years, deep clustering methods have gradually emerged. Benefiting from the powerful representational capabilities of deep neural networks, deep clustering algorithms for text have shown great vitality. Deep clustering architectures that combine traditional text clustering algorithms with deep networks can achieve even better clustering results and are currently a hot research topic. Autoencoders are the earliest and most widely used deep networks for clustering tasks. Early work used autoencoders to encode text and calculated network loss by reconstructing text features to enhance text representation. Later research combined two-dimensional reduction methods to create auxiliary labels and used convolutional neural networks to learn text representations by reconstructing these auxiliary targets. With the success of graph neural networks on graph data, graph neural network-based deep clustering has also shown great vitality, adaptively constructing graphs according to the graph generation perspective and optimizing text representations through the reconstruction of graph structures. However, while the above-mentioned deep learning-based clustering algorithms have some effect in certain domains, most existing deep text clustering methods heavily rely on representations pre-trained in general domains, which may not be the most suitable solution for clustering specific target domains.
[0008] Contrastive learning is one of the most popular unsupervised representation learning techniques in recent years. Its basic idea is to bring positive instance pairs closer together and push negative instance pairs further apart. Extensive evidence suggests that representations obtained through contrastive learning are helpful for clustering tasks. Contrastive learning is explained by two properties: alignment of positive features and uniformity of feature distribution on the hypersphere. The alignment property encourages samples with similar features or semantic categories to approach each other in a low-dimensional space, which is crucial for clustering. This discriminative power has also been demonstrated in supervised methods. Existing work has shown that minimizing the InfoNCE loss is equivalent to maximizing the lower bound of mutual information, without considering data augmentation in maximizing mutual information. Recent research shows that augmentation acts as a "ladder" when connecting instances in the same category, bringing instances from the same cluster closer together, which is beneficial for distinguishing clusters in the space. Therefore, the idea of contrastive learning is consistent with the idea of clustering to some extent. By enhancing text representations through contrastive learning and feeding them back into the clustering process, it promotes the overall text clustering effect.
[0009] Based on the above, this invention proposes a deep redundant code test case identification method based on multi-dimensional information fusion and comparative learning. The aim is to fuse the sequence semantics, structure and data flow information of the code through comparative learning, and to improve the accuracy of redundant test case identification through unsupervised clustering. Summary of the Invention
[0010] In order to overcome the above-mentioned shortcomings and deficiencies of the prior art, the first objective of the present invention is to provide a method for identifying deep redundant code test cases based on multi-dimensional information fusion and comparative learning.
[0011] The second objective of this invention is to provide a deep redundant code test case identification system based on multi-dimensional information fusion and comparative learning.
[0012] A third objective of this invention is to provide a storage medium.
[0013] A fourth objective of this invention is to provide a computer device.
[0014] The objective of this invention is achieved through the following technical solution: This method for identifying deep redundant code test cases based on multi-dimensional information fusion and comparative learning is characterized by comprising the following steps:
[0015] S1. Construct a sequence semantic capture network to encode the sequence semantics of code test cases in order to obtain sequence semantic features. ;
[0016] S2. Construct a syntax structure capture network to extract the structure of code test cases and obtain syntax structure features. ;
[0017] S3. Construct a data flow capture network to perform data flow mining on code test cases to obtain data flow characteristics. ;
[0018] S4. Take the sequence semantic features, syntactic structure features and data flow features in the same code test case as positive samples, and take the sequence semantic features, syntactic structure features and data flow features in other code test cases as negative samples, and construct the contrastive loss through nfoNCE;
[0019] S5. Calculate the category to which each test case belongs using KL divergence to classify them and obtain the clustering loss; derive the category feature representation by maximizing the cosine distance between categories to obtain the category loss.
[0020] S6. Establish a recognition model based on sequence semantic capture network, syntax structure capture network and data flow capture network, and train and optimize the recognition model by combining clustering loss, category loss and contrast loss.
[0021] S7. Deploy the optimized recognition model to receive test cases from the code to be detected as input. The recognition model will group redundant test cases into the same category to identify the test cases of the code to be detected.
[0022] Preferably, the sequence semantic capture network construction process in step S1 is as follows:
[0023] S11. Improve the GraphCodeBERT code pre-training model by introducing a bias matrix specific to the function header on the basis of the original query, key and value matrix of its attention mechanism, so as to achieve explicit semantic emphasis on the function header region. The improved GraphCodeBERT serves as the Encoder of the sequence semantic capture network.
[0024] S12. Based on the Encoder, a complete sequence semantic capture network is obtained by connecting two linear MLP (Multilayer Perceptron) layers.
[0025] Preferably, the construction process of the syntax structure capture network in step S2 is as follows:
[0026] S21. Obtain test cases using the Abstract Syntax Tree tool library. An abstract syntax structure tree, which includes nodes and associated nodes edge ;
[0027] S22. Use a data flow graph parsing tool to parse the abstract syntax tree to obtain a data flow graph, which includes nodes. and associated nodes edge ;
[0028] S23. Based on the abstract syntax tree and data flow graph, a node association algorithm is proposed to associate two different nodes in the same test case. or node Assign weights to the relationships;
[0029] S24. Starting from the abstract syntax structure tree, obtain the initialization features of the nodes in the abstract syntax structure tree through the Encoder in S11. The weights between nodes in the abstract syntax tree are obtained through an association algorithm. Based on initialization features and weight A multi-layer graph neural network is constructed to learn the syntax structure, thereby obtaining a syntax structure capture network.
[0030] Preferably, the data stream capture network construction process in step S3 is as follows:
[0031] S31. Based on the data flow graph obtained in step S22, obtain the nodes in the data flow graph through the Encoder in S11. initialization features ;
[0032] S32. Obtain the weights between nodes in the data flow graph using an association algorithm. ;
[0033] S33, Based on initialization features With weight We construct a multi-layer graph neural network to learn data dependencies in order to obtain a data flow capture network.
[0034] Preferably, step S4 includes the following specific steps:
[0035] S41. In a mini-batch, for the same code test case This test case Sequence semantic features syntactic structural features and data flow characteristics Each other is considered a positive sample pair, and a positive sample pair is represented as... , , Negative sample pairs are when test cases... Compared to other test cases in this mini-batch The corresponding sequence semantic features syntactic structural features and data flow characteristics The combination of negative sample pairs is represented as... , , , , This completes the construction of positive and negative samples for comparative learning;
[0036] S42. Let the mini-batch containing M samples be... Its corresponding sequence semantic features are The grammatical structure features are The characteristics of the data stream are The initial contrast loss calculated using InfoNCE is:
[0037]
[0038] The final contrastive loss is calculated as the average loss of all M samples in the mini-batch:
[0039]
[0040] in, This refers to the cosine similarity function. This refers to the temperature parameter.
[0041] Preferably, step S5 includes the following specific steps:
[0042] S51. In a mini-batch, the semantic features of the sequence are... , syntactic structural features are and data flow characteristics Perform average pooling to obtain ,Will As input to the K-means algorithm, k categories are obtained. Cluster center ,in, Indicates a cluster, ;
[0043] S52, based on Using Student Distributed computing will test cases Assigned to the Categories probability and order Representing auxiliary probabilities, optimization and The KL divergence between the clusters is used to push the cluster assignment probabilities toward the target distribution, thus yielding the clustering loss:
[0044]
[0045] Where M represents the number of samples in the mini-batch, and k represents the number of cluster categories;
[0046] S53, Based on test cases Allocation probability , Will Hard assignment to cluster , in
[0047] S54, For each cluster The feature representation of a category is obtained by taking the average of the feature representations of all samples, and the cluster is filtered by a threshold to stabilize the clustering effect.
[0048] S55. By maximizing the cosine distance between different categories, we can extrapolate the categorical features to obtain the categorical loss:
[0049]
[0050] Where k represents the number of cluster categories, It refers to cosine similarity functions.
[0051] Preferably, step S6 includes the following specific steps:
[0052] S61. Integrate the sequence semantic capture network, the syntax structure capture network, and the data flow capture network into a recognition model;
[0053] S62. The recognition model is trained and optimized by combining clustering loss, category loss, and contrastive loss:
[0054]
[0055] in, It is a coefficient that balances the target loss.
[0056] A deep redundant code test case identification system based on multi-dimensional information fusion and comparative learning includes:
[0057] The sequence semantic encoding module is used to build a sequence semantic capture network. This network is then used to encode the sequence semantics of code test cases to obtain sequence semantic features. ;
[0058] The syntax structure encoding module is used to build a syntax structure capturing network. This network is then used to extract the structure of code test cases to obtain syntax structure features. ;
[0059] The data stream encoding module is used to build a data stream capture network. This network is then used to perform data stream mining on code test cases to obtain data stream characteristics. ;
[0060] The contrast loss module uses sequence semantic features, syntactic structure features, and data flow features from the same code test case as positive samples, and sequence semantic features, syntactic structure features, and data flow features from other code test cases as negative samples, and constructs the contrast loss through InfoNCE.
[0061] The clustering loss module is used to calculate the category to which each test case belongs using KL divergence, thereby dividing them and obtaining the clustering loss;
[0062] The category loss module is used to derive the category feature representation by maximizing the cosine distance between categories to obtain the category loss;
[0063] The joint training module is used to build a recognition model based on the sequence semantic capture network, the syntax structure capture network, and the data flow capture network, and to train and optimize the recognition model by combining clustering loss, category loss, and contrast loss.
[0064] The identification module is used to deploy the optimized identification model to receive test cases from the code to be detected as input. The identification model gathers redundant test cases into the same category, thereby identifying the test cases of the code to be detected.
[0065] The storage medium stores a program, which, when executed by a processor, achieves the first objective of the deep redundant code test case identification method based on multi-dimensional information fusion and comparative learning.
[0066] A computer device, including a processor and a memory for storing processor-executable programs, wherein when the processor executes the program stored in the memory, it achieves the deep redundant code test case identification method based on multi-dimensional information fusion and comparative learning as described in the first objective.
[0067] Compared with the prior art, the present invention has the following advantages and beneficial effects: 1. The present invention extracts the sequence semantics, structure and data flow information in the code by constructing a sequence semantics capture network, a syntax structure capture network and a data flow capture network, and improves the accuracy of redundant test case identification by unsupervised clustering. Attached Figure Description
[0068] Figure 1This is a flowchart of the deep redundant code test case identification method based on multi-dimensional information fusion and comparative learning of the present invention.
[0069] Figure 2 This is a model diagram of the deep redundant code test case identification method based on multi-dimensional information fusion and comparative learning of the present invention. Detailed Implementation
[0070] The present invention is further described below through specific embodiments, but the scope of protection of the present invention is not limited thereto.
[0071] A method for identifying deep redundant code test cases based on multidimensional information fusion and comparative learning, characterized by the following steps:
[0072] S1. Construct a sequence semantic capture network to encode the sequence semantics of code test cases in order to obtain sequence semantic features. ;
[0073] Code, as a sequence of data with strong semantic constraints, contains rich contextual information and semantic relationships. Variable names, function calls, control statements, etc., are all arranged in a fixed word order, constituting sequence information with semantic features. Unlike natural language, the sequence semantics of code are more deterministic and executable, making it valuable in identifying similar code or redundant test cases. Based on this, this invention proposes constructing a sequence semantic capture network to obtain the contextual semantic information of code.
[0074] The sequence semantic capture network construction process in step S1 is as follows:
[0075] S11. Improve the GraphCodeBERT code pre-training model by introducing a bias matrix specific to the function header on the basis of the original query, key and value matrix of its attention mechanism, so as to achieve explicit semantic emphasis on the function header region. The improved GraphCodeBERT serves as the Encoder of the sequence semantic capture network.
[0076] Specifically, to enhance the model's ability to focus on key information in the function header (such as function name, parameter list, etc.), this invention introduces a bias matrix specific to the function header, based on the attention mechanism of the GraphCodeBERT code pre-training model, which is built upon the original query, key, and value matrices. This design achieves explicit semantic emphasis on the function header region to obtain a sequence semantic capture network. This design effectively improves the model's ability to capture test intent and core logic in sequence semantic modeling, thereby more accurately distinguishing between redundant and non-redundant test cases. The improved attention mechanism is represented as follows:
[0077]
[0078]
[0079] Where Q represents the original query, K represents the key, V represents the value, and B represents the bias matrix. The dimension of the key vector is used to scale the dot product result. This represents the normalization function used to obtain attention weights. Indicates the first The query and the first Structural bias terms between bonds The preset enhancement coefficient, and These represent the position index of the query and the key, respectively.
[0080] S12. Based on the Encoder, a complete sequence semantic capture network is obtained by connecting two linear MLP layers. Specifically, the token at the cls position of the Encoder is taken as the output, and a complete sequence semantic capture network is obtained by connecting two linear MLP layers. This sequence semantic capture network is then used to capture sequence semantic features. .
[0081] S2. Construct a syntax structure capture network to extract the structure of code test cases and obtain syntax structure features. Because of its strict syntax rules and structural features, code is considered a special modality in many studies. Different codes exhibit structural dissimilarity, which is crucial for identifying and distinguishing the relationships between different test cases. Based on this, this invention proposes constructing a syntax structure capture network to obtain the syntax structure information of code.
[0082] The construction process of the syntax structure capture network in step S2 is as follows:
[0083] S21. For a test case The abstract syntax tree tool library is used to obtain the abstract syntax structure tree of the test cases. This abstract syntax structure tree includes nodes. and associated nodes edge ; among which nodes Includes the class name, method name, and variable name of the test cases. , and the side This indicates a node. The relationships between them, such as calls and inclusion. This abstract grammatical structure tree reveals the grammatical structure features of the test cases.
[0084] S22. Use a data flow graph parsing tool to parse the abstract syntax tree to obtain the data flow graph. This data flow diagram Including nodes and associated nodes edge ; among which nodes , And the side Represents the data flow between different nodes. ( This data flow diagram illustrates the data dependency characteristics of the test cases.
[0085] S23. Based on the abstract syntax tree and data flow graph, a node association algorithm is proposed to associate two different nodes in the same test case. or node Assign relation weights (i.e., assign weights to two different nodes in the abstract syntax tree). Or two different nodes in the data flow graph Assign weights to relationships and This paper proposes a node association algorithm to obtain an abstract syntactic structure tree for the same test case. and data flow diagram In other words, this association algorithm can separately analyze the nodes contained in both. and Assignment Relationship Weight and This reflects the relationships between different nodes in a tree or graph. Specifically, the association algorithm first statistically analyzes... and The total number of edges contained in it is denoted as . Then, statistics were compiled separately. Two different nodes and The number of edges existing in each of them is denoted as . Finally, divide both by [the factor]. This yields the normalized weight values. , This weight reflects the node The strength of associations from both syntactic structure and data dependency perspectives can be used to guide syntactic structure capture networks and data flow capture networks to more accurately learn the structural and data relationships between nodes, thereby improving the structural modeling and discrimination capabilities of redundant test cases. The "node association algorithm" is shown below:
[0086]
[0087] S24. Starting from the abstract syntax structure tree, obtain the initialization features of the nodes in the abstract syntax structure tree through the Encoder in S11. The weights between nodes in the abstract syntax tree are obtained through an association algorithm. Based on initialization features and weight A multi-layer graph neural network is constructed to learn grammatical structures, thereby obtaining a grammatical structure capture network. This grammatical structure capture network is then used to capture the structural features of test code. :
[0088]
[0089] in, This is the association weight matrix plus the identity matrix representation plus self-loops. This is the corresponding degree matrix. For the first The learnable weight matrix of the layer.
[0090] S3. Construct a data flow capture network to mine data flow characteristics of code test cases. Code not only possesses a clear syntactic structure but also contains complex data dependencies between variable definitions and usages. These dependencies reflect the propagation paths of numerical values and logic during program execution. Unlike natural language, data flow in code exhibits strong determinism and semantic consistency, and its propagation paths highly characterize the core logic of functional implementation within test cases. Therefore, mining data flow information in code is crucial for accurately identifying deep semantic relationships between redundant test cases.
[0091] The data stream capture network construction process in step S3 is as follows:
[0092] S31. Based on the data flow graph obtained in step S22, obtain the nodes in the data flow graph through the Encoder in S11. initialization features ;
[0093] S32. Obtain the weights between nodes in the data flow graph using an association algorithm. ;
[0094] S33, Based on weights and initialization features A multi-layer graph neural network is constructed to learn data dependencies, resulting in a data flow capture network. This data flow capture network is used to capture the data flow features of the test code. :
[0095] .
[0096] S4. Take the sequence semantic features, syntactic structure features and data flow features in the same code test case as positive samples, and take the sequence semantic features, syntactic structure features and data flow features in other code test cases as negative samples. Then, use the contrastive loss to fuse and optimize the positive and negative samples to obtain the contrastive loss.
[0097] Step S4 includes the following specific steps:
[0098] S41. In a mini-batch, for the same code test case This test case Sequence semantic features syntactic structural features and data flow characteristics Each other is considered a positive sample pair, and a positive sample pair is represented as... , , Negative sample pairs are when test cases... Compared to other test cases in this mini-batch The corresponding sequence semantic features syntactic structural features and data flow characteristics The combination of negative sample pairs is represented as... , , , , This completes the construction of positive and negative samples for contrastive learning. The basic idea of contrastive learning is to bring positive pairs closer together and push negative pairs further apart. The construction of positive and negative samples is crucial in this process, and different sample selection strategies have different effects on test case identification. This invention, considering the characteristics of code, proposes using sequence, structure, and data flow information to implement the positive and negative sample construction process. Within a mini-batch, for the same code test case... The feature representation of its positive sample pairs , , Negative sample pairs are representations of other samples in the mini-batch, thus completing the construction of positive and negative samples for contrastive learning;
[0099] S42. The purpose of constructing the contrastive loss is to improve the text feature representation during model training, thereby promoting the overall text clustering effect. This invention selects InfoNCE as the contrastive loss:
[0100] Let the mii-batch containing M patterns be Its corresponding sequence semantic features are The grammatical structure features are The characteristics of the data stream are The comparative loss is:
[0101]
[0102] The final contrastive loss is calculated as the average loss of all M samples in the mini-batch:
[0103]
[0104] in, This refers to the cosine similarity function. This refers to the temperature parameter.
[0105] The temperature parameter 𝜏 serves the following functions: The model prioritizes updates to challenging negative examples, penalizing them accordingly. The greater the difficulty, and thus the closer the example, the greater the penalty. This penalty acts as a repulsive force, pushing these negative examples away from the current sample during optimization. In other words, the closer the negative example, the greater the repulsive force exerted by the temperature hyperparameter, pushing it further away. A smaller temperature hyperparameter (φ) narrows the range of penalties allocated by InfoNCE, focusing more on a smaller, closer range of negative examples. Simultaneously, because the number of covered negative examples is reduced, each negative example experiences a greater repulsive force. In extreme cases, assuming the temperature coefficient approaches 0, InfoNCE may focus on the one or two closest, most challenging instances. Therefore, a smaller temperature hyperparameter tends to disperse locally dense structures on the hypersphere, resulting in a more uniform overall data distribution. However, if the temperature hyperparameter is too small, it may tend to push positive examples further away from the hypersphere, which is undesirable. Through experimentation, the parameters in this invention are... Set to 0.06.
[0106] S5. Calculate the category to which each information-fused test case belongs using KL divergence to classify them and obtain the clustering loss; derive the category feature representation by maximizing the cosine distance between categories to obtain the category loss; in information theory, KL divergence is used to measure the use of information based on... The distribution encoding is used to encode the source The number of extra bits required to average the samples of a distribution. In machine learning, it measures the similarity or closeness between two probability distributions. More broadly, divergence refers to a type of operation that maps a vector field in vector space to a scalar field; simply put, it takes a set of vectors as input and returns a scalar. In machine learning, the most commonly used divergence is the KL divergence. For an unknown distribution... Assuming an approximate distribution has already been used. We model it. In this invention, KL divergence is used to calculate the clustering loss.
[0107] Step S5 includes the following specific steps:
[0108] S51. In a mini-batch, the semantic features of the sequence are... , syntactic structural features are and data flow characteristics Perform average pooling to obtain ,Will As input to the K-means algorithm, k categories are obtained. Cluster center ,in, Indicates a cluster, ;
[0109] S52, based on Using Student Distributed computing will test cases Assigned to the Categories probability and order Representing auxiliary probabilities, optimization and The KL divergence between the clusters is used to push the cluster assignment probabilities toward the target distribution, thus yielding the clustering loss:
[0110]
[0111] Where M represents the number of samples in the mini-batch, and k represents the number of cluster categories;
[0112] Specifically, using Student Distribution calculation will sample Assigned to the Categories probability ,
[0113]
[0114] in represent The degrees of freedom of the distribution are set to 1 in this paper. And let... Denote the auxiliary probability to obtain the target distribution.
[0115]
[0116] in, This can be interpreted as an approximate soft cluster frequency within a mini-batch. This target distribution... First, by soft-assigning probability The soft assignment probability is sharpened by raising it to the quadratic and then normalized by the associated cluster frequency, thereby encouraging the model to learn from high-confidence cluster tasks while eliminating bias caused by imbalanced clusters.
[0117] optimization and The KL divergence between the clusters pushes the cluster assignment probabilities toward the target distribution, yielding the clustering loss:
[0118]
[0119] Where M is the number of samples in the mini-batch, and k is the number of clusters. Indicates the first One sample index, Indicates the first One cluster category index; and They represent the first The target distribution and predicted distribution vector of each sample Indicates sample Category The target probability, This represents the soft assignment probability calculated based on the current model. This represents the Kullback–Leibler divergence between the two. By minimizing this divergence, the predicted distribution gradually approaches the target distribution, thereby optimizing the clustering structure.
[0120] A key problem in clustering is the significant overlap in initial data representations between categories. This is often due to the low quality of the initial feature representations used for clustering, leading to errors in the representation of samples from different categories, which significantly impacts the clustering algorithm. Introducing a contrastive learning objective can address this issue to some extent. By promoting the separation of dissimilar samples and bringing similar samples closer together, it can differentiate the representations of samples from different categories. However, it is limited by instance-based contrastive learning. It separates the vector representations of data from different original instances regardless of their semantic similarity. This can lead to instances with the same semantics being assigned to different categories, while instances with different semantics may be assigned to the same category, blurring the boundaries between sample representations and affecting the final clustering result. To address this problem, this invention proposes a novel category loss that aims to improve clustering performance by introducing more distance between categories and obtaining clearer category boundaries.
[0121] S53, Based on test cases Allocation probability Test cases Hard assignment to cluster , in ;
[0122] S54, For each cluster The feature representation of a category is obtained by averaging the feature representations of all samples, and the clusters are filtered using a threshold to stabilize the clustering effect; specifically, for each cluster... The initial representation vector for that category is obtained by taking the average of the sample representations. Given that the initial category representations may be inaccurate, especially in the early iterations when clustering results are not very stable, this application applies a simple threshold. To obtain a filtered cluster .
[0123] S55. By maximizing the cosine distance between different categories, we can extrapolate the categorical features to obtain the categorical loss:
[0124]
[0125] Where k represents the number of cluster categories, It refers to cosine similarity functions.
[0126] Specifically, for each filtering cluster Derive the final representation vector To better separate clusters This invention proposes a loss function that derives class feature representations by maximizing the cosine distance between classes:
[0127]
[0128] Where k represents the number of cluster categories, This refers to the cosine similarity function. For class loss, its purpose is to facilitate the separation of representations between different classes; therefore, it also employs representation in its calculation. Perform the calculation.
[0129] S6. Establish a recognition model based on sequence semantic capture network, syntax structure capture network and data flow capture network, and train and optimize the recognition model by combining clustering loss, category loss and contrast loss.
[0130] Step S6 includes the following specific steps:
[0131] S61. Integrate the sequence semantic capture network, the syntax structure capture network, and the data flow capture network into a recognition model;
[0132] S62. The recognition model is trained and optimized by combining clustering loss, category loss, and contrastive loss:
[0133]
[0134] in, It is a coefficient that balances the target loss. In this embodiment...
[0135] As shown in Figure 2, this invention integrates the sequence semantic capture network, the grammatical structure capture network, and the data flow capture network into a unified recognition model using a "shared encoding base + three-branch feature extraction + fusion clustering head" approach. Specifically, for input test cases... First, the code sequence is input into the improved GraphCodeBERT encoder to obtain a token-level context representation, where (1) the cls position vector is projected through two layers of MLP to obtain the sequence semantic representation. (2) Simultaneously, the token representations output by the same encoder are aggregated into initial node features according to the node mapping rules obtained by parsing the abstract syntax tree and the data flow graph. These features are used for graph representation learning of the syntax structure branches and the data flow branches, i.e., respectively in the abstract syntax tree. With data flow diagram Above, a weighted adjacency matrix (node relationship weights) is generated by combining the node association algorithm. , Structural representation is obtained through multi-layer graph convolutional networks. With data flow representation (3) Subsequently, the three-branch outputs are aligned and aggregated in the fusion layer: during the training phase, the same sample is used for ( , , For each pair of positive samples, and their corresponding negative samples in the mini-batch, calculate the InfoNCE contrastive loss. The three representations are constrained to be consistent within a common semantic space; mean pooling is then performed on the three representations to obtain a fused representation. and with As input to the clustering head: first initialize the cluster centers using K-means, then calculate the soft assignments using the Student-t distribution. And construct the target distribution , minimize Obtain clustering loss The inter-class cosine separation loss is calculated based on the cluster mean. Ultimately, the parameters of the overall recognition model are determined by the joint objective. End-to-end backpropagation updates are implemented, where contrastive loss provides alignment constraints for the three branches and the shared encoder, while clustering and category losses provide structural constraints for the fused representation and category boundaries. This enables the overall construction and training optimization of a unified redundancy identification model from three capture networks. After training, the identification model is deployed, outputting the fused representation and cluster category of the test cases to be tested. Test cases clustered into the same category are identified as redundant test cases, thus achieving automatic identification of redundant code test cases.
[0136] In this example, the specific parameter settings are as follows: the hidden dimension of all methods is uniformly set to 512. The optimizer used is Adam, and a Bayesian optimization algorithm is used to automatically search for hyperparameters to obtain the optimal configuration for each baseline model, thereby maximizing model performance. In the final experiment, the learning rate is set to 0.00001, and the batch size is set to 16. Regarding the experimental environment, the server runs CentOS 7.6, equipped with a 32-core, 64-thread Intel Xeon CPU, one NVIDIA RTX 4090 graphics card (24GB VRAM), and 256GB of RAM. For the software environment, PyCharm is used as the main development tool, and model construction and training are both based on the PyTorch deep learning framework, with Python version 3.10 and CUDA version 11.8.
[0137] S7. Deploy the optimized recognition model to receive test cases from the code to be detected as input, and output the recognition results of redundant test cases. For the trained model, this invention encapsulates it as a callable module interface, supporting integrated deployment in a test case management system or continuous integration platform. This model can receive test cases from the code to be detected as input, automatically extracting sequence information, syntax structure information, and data flow information, automatically completing the entire process of feature extraction, multimodal fusion, and redundancy recognition, and outputting the redundancy relationship or similarity category between test cases. Deployment methods can include local deployment, server deployment, or containerized deployment, supporting integration with RESTful APIs or plugins, possessing good scalability and platform adaptability, and can be widely applied in various practical scenarios such as software testing, code review, and quality assessment to achieve efficient detection and intelligent optimization of redundant test cases.
[0138] This invention employs a deep redundant code test case identification method based on multi-dimensional information fusion and contrastive learning, and compares it with traditional or existing redundant test case identification methods such as TF-IDF+K-means, CodeBERT+K-means, GraphCodeBERT+K-means, AST-GCN, DFG-GCN, ATM, PtuM, and CBMC. TF-IDF, CodeBERT, and GraphCodeBERT are used to extract semantic representations of text or code, respectively, and then combined with the K-means clustering algorithm to complete test case identification. AST-GCN, DFG-GCN, ATM, PtuM, and CBMC are representative methods in the field of redundant test case identification. This experiment uses a dataset of 5000 data points and selects Precision, Recall, and F1-score as evaluation metrics. Higher values for these three metrics indicate better identification performance. The comparative experimental results are shown in the table below:
[0139]
[0140] As can be seen from the data in the table, when identifying redundant test cases, the data of the three indicators Precision, Recall and F1-score of this invention are all better than the existing identification methods. This fully demonstrates that the multi-dimensional information fusion and joint optimization strategy adopted by this deep redundant code test case identification method based on multi-dimensional information fusion and comparative learning has good effectiveness and superiority.
[0141] A deep redundant code test case identification system based on multi-dimensional information fusion and comparative learning includes:
[0142] The sequence semantic encoding module is used to build a sequence semantic capture network. This network is then used to encode the sequence semantics of code test cases to obtain sequence semantic features. ;
[0143] The syntax structure encoding module is used to build a syntax structure capturing network. This network is then used to extract the structure of code test cases to obtain syntax structure features. ;
[0144] The data stream encoding module is used to build a data stream capture network. This network is then used to perform data stream mining on code test cases to obtain data stream characteristics. ;
[0145] The contrast loss module uses sequence semantic features, syntactic structure features, and data flow features from the same code test case as positive samples, and sequence semantic features, syntactic structure features, and data flow features from other code test cases as negative samples, and constructs the contrast loss through InfoNCE.
[0146] The clustering loss module is used to calculate the category to which each test case belongs using KL divergence, thereby dividing them and obtaining the clustering loss;
[0147] The category loss module is used to derive the category feature representation by maximizing the cosine distance between categories to obtain the category loss;
[0148] The joint training module is used to build a recognition model based on the sequence semantic capture network, the syntax structure capture network, and the data flow capture network, and to train and optimize the recognition model by combining clustering loss, category loss, and contrast loss.
[0149] The identification module is used to deploy the optimized identification model to receive test cases from the code to be detected as input. The identification model gathers redundant test cases into the same category, thereby identifying the test cases of the code to be detected.
[0150] The storage medium stores a program, which, when executed by a processor, implements the aforementioned method for identifying deep redundant code test cases based on multidimensional information fusion and comparative learning.
[0151] A computer device, including a processor and a memory for storing processor-executable programs, wherein when the processor executes the program stored in the memory, it implements the above-described method for identifying deep redundant code test cases based on multidimensional information fusion and comparative learning.
[0152] Those skilled in the art will readily understand that the above description is merely an embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A method for identifying deep redundant code test cases based on multi-dimensional information fusion and comparative learning, characterized in that, Includes the following steps: S1. Construct a sequence semantic capture network to encode the sequence semantics of code test cases in order to obtain sequence semantic features. The sequence semantic capture network construction process in step S1 is as follows: S11. Improve the GraphCodeBERT code pre-training model by introducing a bias matrix specific to the function header on the basis of the original query, key and value matrix of its attention mechanism, so as to achieve explicit semantic emphasis on the function header region. The improved GraphCodeBERT serves as the Encoder of the sequence semantic capture network. S12. Based on the Encoder, a complete sequence semantic capture network is obtained by connecting two linear MLP layers; S2. Construct a syntax structure capture network to extract the structure of code test cases and obtain syntax structure features. The construction process of the syntax structure capture network in step S2 is as follows: S21. Use the Abstract Syntax Tree (AST) tool library to obtain the abstract syntax tree structure of the test cases. This abstract syntax tree structure includes nodes. and associated nodes edge ; S22. Use a data flow graph parsing tool to parse the abstract syntax tree to obtain the data flow graph. This data flow diagram Including nodes and associated nodes edge ; S23. Based on the abstract syntax tree and data flow graph, a node association algorithm is proposed to associate two different nodes in the same test case. or node Assign weights to the relationships; S24. Starting from the abstract syntax structure tree, obtain the initialization features of the nodes in the abstract syntax structure tree through the Encoder in S11. The weights between nodes in the abstract syntax tree are obtained through an association algorithm. Based on initialization features and weight A multi-layer graph neural network is constructed to learn the syntax structure, thereby obtaining a syntax structure capture network; S3. Construct a data flow capture network to perform data flow mining on code test cases to obtain data flow characteristics. The data stream capture network construction process in step S3 is as follows: S31. Based on the data flow graph obtained in step S22, obtain the nodes in the data flow graph through the Encoder in S11. initialization features ; S32. Obtain the weights between nodes in the data flow graph using an association algorithm. ; S33, Based on initialization features With weight We construct a multi-layer graph neural network to learn data dependencies in order to obtain a data flow capture network; S4. Take the sequence semantic features, syntactic structure features and data flow features in the same code test case as positive samples, and take the sequence semantic features, syntactic structure features and data flow features in other code test cases as negative samples, and construct the contrastive loss through InfoNCE; S5. Calculate the category to which each test case belongs using KL divergence to classify them and obtain the clustering loss; derive the category feature representation by maximizing the cosine distance between categories to obtain the category loss; S6. Establish a recognition model based on sequence semantic capture network, syntax structure capture network and data flow capture network, and train and optimize the recognition model by combining clustering loss, category loss and contrast loss. S7. Deploy the optimized recognition model to receive test cases from the code to be detected as input. The recognition model will group redundant test cases into the same category to identify the test cases of the code to be detected.
2. The method for identifying deep redundant code test cases based on multi-dimensional information fusion and comparative learning according to claim 1, characterized in that, Step S4 includes the following specific steps: S41. In a mini-batch, for the same code test case, the sequence semantic features in this test case... syntactic structural features and data flow characteristics Each other is considered a positive sample pair, and a positive sample pair is represented as... , , Negative sample pairs are those where the sequence semantic features of a test case match those of other test cases in the mini-batch. syntactic structural features and data flow characteristics The combination of negative sample pairs is represented as... , , , , This completes the construction of positive and negative samples for comparative learning; S42. Let the mini-batch containing M samples be... Its corresponding sequence semantic features are The grammatical structure features are The characteristics of the data stream are The initial contrast loss calculated using InfoNCE is: The final contrastive loss is calculated as the average loss of all M samples in the mini-batch: in, This refers to the cosine similarity function. This refers to the temperature parameter.
3. The method for identifying deep redundant code test cases based on multi-dimensional information fusion and comparative learning according to claim 1, characterized in that, Step S5 includes the following specific steps: S51. In a mini-batch, the semantic features of the sequence are... , syntactic structural features are and data flow characteristics Perform average pooling to obtain ,Will As input to the K-means algorithm, k categories are obtained. Cluster center ,in, Indicates a cluster, ; S52, based on Using Student Distributed computing assigns test cases to the first... Categories probability and order Representing auxiliary probabilities, optimization and The KL divergence between the clusters is used to push the cluster assignment probabilities toward the target distribution, thus yielding the clustering loss: Where M represents the number of samples in the mini-batch, and k represents the number of cluster categories; S53, Assignment Probability Based on Test Cases , Will Hard assignment to cluster , in ; S54, For each cluster The feature representation of a category is obtained by taking the average of the feature representations of all samples, and the cluster is filtered by a threshold to stabilize the clustering effect. S55. By maximizing the cosine distance between different categories, we can extrapolate the categorical features to obtain the categorical loss: Where k represents the number of cluster categories, It refers to cosine similarity functions.
4. The method for identifying deep redundant code test cases based on multi-dimensional information fusion and comparative learning according to claim 1, characterized in that, Step S6 includes the following specific steps: S61. Integrate the sequence semantic capture network, the syntax structure capture network, and the data flow capture network into a recognition model; S62. The recognition model is trained and optimized by combining clustering loss, category loss, and contrastive loss: in, It is a coefficient that balances the target loss.
5. A deep redundant code test case identification system based on multi-dimensional information fusion and comparative learning, characterized in that, The method for identifying deep redundant code test cases based on multidimensional information fusion and comparative learning as described in any one of claims 1-4 includes: The sequence semantic encoding module is used to build a sequence semantic capture network. This network is then used to encode the sequence semantics of code test cases to obtain sequence semantic features. ; The syntax structure encoding module is used to build a syntax structure capturing network. This network is then used to extract the structure of code test cases to obtain syntax structure features. ; The data stream encoding module is used to build a data stream capture network. This network is then used to perform data stream mining on code test cases to obtain data stream characteristics. ; The contrast loss module uses sequence semantic features, syntactic structure features, and data flow features from the same code test case as positive samples, and sequence semantic features, syntactic structure features, and data flow features from other code test cases as negative samples, and constructs the contrast loss through InfoNCE. The clustering loss module is used to calculate the category to which each test case belongs using KL divergence, thereby dividing them and obtaining the clustering loss; The category loss module is used to derive the category feature representation by maximizing the cosine distance between categories to obtain the category loss; The joint training module is used to build a recognition model based on the sequence semantic capture network, the syntax structure capture network, and the data flow capture network, and to train and optimize the recognition model by combining clustering loss, category loss, and contrast loss. The identification module is used to deploy the optimized identification model to receive test cases from the code to be detected as input. The identification model gathers redundant test cases into the same category, thereby identifying the test cases of the code to be detected.
6. A storage medium, characterized in that, The system stores a program that, when executed by a processor, implements the deep redundant code test case identification method based on multidimensional information fusion and comparative learning as described in any one of claims 1-4.
7. A computer device, comprising a processor and a memory for storing a processor-executable program, characterized in that, When the processor executes the program stored in the memory, it implements the deep redundant code test case identification method based on multi-dimensional information fusion and comparative learning as described in any one of claims 1-4.
Citation Information
Patent Citations
Code odor detection method based on deep semantics and complex structure
CN121979757A
Code autogeneration real-time review assistance system based on large language model
CN122387815A