Test case verification method, computer readable storage medium and electronic equipment
By integrating the required document features in test cases and code blocks, cross-attention calculations are used to improve the accuracy and speed of test case verification, solving the problems of untimely verification and inaccurate results in the prior art.
Patent Information
- Application Number
- CN202510004013.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-02
- Publication Date
- 2025-04-11
AI Technical Summary
In the prior art, test cases are not checked in time and the results are inaccurate, and the correlation and heterogeneity issues between test cases and code blocks are not effectively considered.
By obtaining the representation matrix of test cases, code blocks, and requirements documents, cross-attention calculations are used to fuse the features of the requirements document into the test case and code block representation, and the similarity between test cases and code blocks is calculated to represent the adequacy of the test case.
It realizes faster and accurate test case verification, solves the heterogeneity problem between test cases and code blocks, and improves the matching accuracy of test cases and code blocks.
Smart Images

Figure CN119807070A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of software testing, and in particular, relates to a test case verification method, a computer-readable storage medium and an electronic device. Background Art
[0002] In the process of software testing, the adequacy of test cases is an important factor in ensuring the quality of testing. There are generally two ways to measure the adequacy of test cases: one is to use some code coverage statistics tools to obtain the code coverage of test cases after the test is executed; the other is to directly calculate the correlation and matching degree between test cases and the tested code before the test is executed. These two methods respectively express the adequacy of test cases by the code coverage of test cases and the correlation and matching degree between test cases and code.
[0003] In the related art, the code coverage statistics method can only calculate the code coverage after the test is executed, which has a time lag. Encoding the test cases and code blocks and then calculating their correlation does not take into account the background that the test cases and code blocks are both generated based on the requirements document, and ignores the correlation between the requirements document and the code blocks, resulting in inaccurate results. Furthermore, the test case is a structured natural language, while the tested code is a computer program language. If the two are encoded separately and then directly matched for correlation, the correlation is not high, which will also lead to inaccurate results.
[0004] It should be noted that the information disclosed in the above background technology section is only used to enhance the understanding of the background of the present application, and therefore may include information that does not constitute the prior art known to ordinary technicians in the field. Summary of the invention
[0005] The purpose of the present invention is to provide a test case verification method, a computer-readable storage medium and an electronic device, which are used to solve the problem of untimely test case verification or inaccurate verification results in the related art.
[0006] According to one aspect of an embodiment of the present application, a test case verification method is provided, the method comprising:
[0007] Obtaining a first characterization matrix of the test case, a second characterization matrix of the code block, and a third characterization matrix of the requirement document; the requirement document includes multiple requirement points, and the test case and the code block are written based on the requirement document;
[0008] Based on each word vector in the first representation matrix and the word vector of each demand point in the third representation matrix, a cross attention calculation is performed to obtain an enhanced test case representation corresponding to the test case;
[0009] Based on each word vector in the second representation matrix and the word vector of each demand point in the third representation matrix, a cross attention calculation is performed to obtain an enhanced code block representation corresponding to the code block;
[0010] The enhanced test case representation and the enhanced code block representation are cross-attention calculated to obtain the similarity between the test case and the code block; the similarity is used to represent the adequacy of the test case.
[0011] In some embodiments, a cross-attention calculation is performed based on each word vector in the first representation matrix and the word vector of each demand point in the third representation matrix to obtain an enhanced test case representation corresponding to the test case, including: cross-attention calculation is performed on each word vector in the first representation matrix and the word vector of each demand point in the third representation matrix to obtain a test case cross-attention matrix; the test case cross-attention matrix is used to represent the similarity of each word vector of the test case and the demand point; the test case cross-attention matrix is normalized by row to obtain a first attention distribution of the word vectors at each position in the test case on the corresponding demand point; the first attention distribution is matrix multiplied with the first representation matrix to obtain a first test case representation; the first test case representation includes information about the test case itself and also includes association information between the test case and the demand point; based on the first test case representation, the first representation matrix and the first preset linear layer, an enhanced test case representation corresponding to the test case is obtained.
[0012] In some embodiments, based on the first test case representation, the first representation matrix and the first preset linear layer, an enhanced test case representation corresponding to the test case is obtained, including: using the first preset linear layer to perform a linear transformation on the first test case representation to obtain a linear test case representation; superimposing the linear test case representation on the first representation matrix to obtain a first superimposed representation matrix corresponding to the number of demand points; aggregating the test case representations in the first superimposed representation matrix to obtain an enhanced test case representation; the enhanced test case representation integrates the associated features of the demand points.
[0013] In some embodiments, a cross-attention calculation is performed based on each word vector in the second representation matrix and the word vector of each demand point in the third representation matrix to obtain an enhanced code block representation corresponding to the code block, including: cross-attention calculation is performed on each code block in the second representation matrix and the word vector of each demand point in the third representation matrix to obtain a code block cross-attention matrix; the code block cross-attention matrix is used to represent the similarity of each word vector of the code block and the demand point; the code block cross-attention matrix is normalized by row to obtain a second attention distribution of the word vectors at each position in the code block on the corresponding demand point; the second attention distribution is matrix multiplied with the second representation matrix to obtain a first code block representation; the first code block representation includes information about the code block itself and also includes association information between the code block and the demand point; based on the first code block representation, the second representation matrix and the second preset linear layer, an enhanced code block representation corresponding to the code block is obtained.
[0014] In some embodiments, based on the first code block representation, the second representation matrix and the second preset linear layer, an enhanced code block representation corresponding to the code block is obtained, including: using the second preset linear layer to perform a linear transformation on the first code block representation to obtain a linear code block representation; superimposing the linear code block representation on the second representation matrix to obtain a second superimposed representation matrix corresponding to the number of demand points; aggregating the code block representations in the second superimposed representation matrix to obtain an enhanced code block representation; the enhanced code block representation incorporates the associated features of the demand points.
[0015] In some embodiments, the enhanced test case representation and the enhanced code block representation are cross-attention calculated to obtain the similarity between the test case and the code block, including: cross-attention calculated to obtain an enhanced cross-attention matrix; matrix multiplication of the enhanced cross-attention matrix with the enhanced test case representation and the enhanced code block representation to obtain the corresponding second test case representation and second code block representation; based on the second test case representation and the second code block representation, the similarity between the test case and the code block is obtained.
[0016] In some embodiments, based on the second test case representation and the second code block representation, the similarity between the test case and the code block is obtained, including: aggregating the second test case representation to obtain a test case representation vector; and aggregating the second code block representation to obtain a code block representation vector; calculating the vector dot product of the test case representation vector and the code block representation vector, and using the vector dot product as the similarity.
[0017] In some embodiments, obtaining a first representation matrix of a test case includes: obtaining a test case to be processed; inputting the test case into a preset encoder for word embedding representation to obtain a first representation matrix of the test case; the first representation matrix includes the length of the test case and the embedding dimension of the preset encoder.
[0018] According to one aspect of an embodiment of the present application, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, a verification method for a test case provided by any embodiment of the present application is implemented.
[0019] According to one aspect of an embodiment of the present application, an electronic device is provided, comprising: a processor; a memory for storing executable instructions of the processor; the processor executes the executable instructions to enable the electronic device to implement a verification method for a test case provided in any embodiment of the present application.
[0020] In the technical solution of the present application, a first representation matrix of a test case, a second representation matrix of a code block and a third representation matrix of a requirement document are obtained; the requirement document includes multiple requirement points, and the test case and the code block are written based on the requirement document; cross-attention calculation is performed based on each word vector of the first representation matrix and the word vector of each requirement point in the third representation matrix to obtain an enhanced test case representation corresponding to the test case; cross-attention calculation is performed based on each word vector of the second representation matrix and the word vector of each requirement point in the third representation matrix to obtain an enhanced code block representation corresponding to the code block; cross-attention calculation is performed on the enhanced test case representation and the enhanced code block representation to obtain the similarity between the test case and the code block; the similarity is used to represent the sufficiency of the test case; because the requirement document contains richer content than the test case and the code block, and the requirement document potentially connects the test case and the code block, the present application integrates the features of the requirement document into the test case and code block representation matrix through multiple cross-attention calculations, which can better represent the test case and the code block, and can solve the heterogeneity problem of the test case and the code block, thereby improving the matching accuracy of the test case and the code block.
[0021] It should be understood that the above general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] The drawings herein are incorporated into the specification and constitute a part of the specification, illustrate embodiments consistent with the present application, and together with the specification are used to explain the principles of the present application. Obviously, the drawings described below are only some embodiments of the present application, and for ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0023] Figure 1 The flowchart of the test case verification method provided in one embodiment of the present application is schematically shown.
[0024] Figure 2The flowchart of the test case verification method provided in one embodiment of the present application is schematically shown.
[0025] Figure 3 The flowchart of the test case verification method provided in one embodiment of the present application is schematically shown.
[0026] Figure 4 The flowchart of the test case verification method provided in one embodiment of the present application is schematically shown.
[0027] Figure 5 The flowchart of the test case verification method provided in one embodiment of the present application is schematically shown.
[0028] Figure 6 The flowchart of the test case verification method provided in one embodiment of the present application is schematically shown.
[0029] Figure 7 The structural block diagram of an electronic device provided by an embodiment of the present application is schematically shown.
[0030] Figure 8 The structure block diagram of a computer system for implementing an electronic device according to an embodiment of the present application is schematically shown. DETAILED DESCRIPTION
[0031] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in a variety of forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided so that this application will be more comprehensive and complete and fully convey the concept of the example embodiments to those skilled in the art.
[0032] In addition, the features, structures or characteristics described in the present application may be combined in one or more embodiments in any suitable manner. In the following description, many specific details are provided to provide a full understanding of the embodiments of the present application. However, those skilled in the art will appreciate that the technical scheme of the present application can be put into practice without one or more of the specific details, or other methods, components, devices, steps, etc. may be adopted. In other cases, known methods, devices, realizations or operations are not shown or described in detail to avoid blurring the various aspects of the present application.
[0033] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities may be implemented in software form, or in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.
[0034] The flowcharts shown in the accompanying drawings are only exemplary and do not necessarily include all the contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps can be decomposed, and some operations / steps can be combined or partially combined, so the actual execution order may change according to actual conditions.
[0035] A test case is a description of a test task for a specific software product, reflecting the test plan, method, technology and strategy. Its content includes test objectives, test environment, input data, test steps, expected results, test scripts, etc., which eventually form corresponding documents. Simply put, a test case is a set of test inputs, execution conditions and expected results compiled for a special goal, which is used to verify whether a specific software requirement is met. Test cases are used to test code blocks to determine whether the code blocks can run reliably. The code can be divided into multiple different code blocks based on the functions implemented, the content included, etc. After dividing the code into multiple code blocks, the tester can write corresponding test cases for each code block one by one, which shows that the test cases and code blocks are related.
[0036] In the related art, the execution status of the code during the operation of the system is obtained based on the instrumentation technology to calculate the sufficiency of the test case, which limits the sufficiency of the test case to only executing the test, and it usually takes a long time to execute a test, resulting in a long test case verification time. Alternatively, the test sufficiency is expressed by calculating the correlation between the test case and the code block, but the correlation between the test case and the code and the requirement document is not considered, and the test case is a structured natural language, while the code is a computer program language, that is, the test case and the code block are heterogeneous. The above factors all lead to the final calculated sufficiency is not accurate. Therefore, the present application provides a test case verification method, such as Figure 1 As shown, the method includes S110 to S140, and the specific process is as follows.
[0037] S110, obtaining a first characterization matrix of the test case, a second characterization matrix of the code block, and a third characterization matrix of the requirement document.
[0038] Specifically, a requirement document includes multiple requirement points. For example, a requirement document: This system implements the user login function and the user logout function, where the login function is specifically described as: ..., and the user logout function is specifically described as: .... Then the requirement document has two requirement points, requirement point 1 is the user login function: ..., and requirement point 2 is the user logout function: .... If the requirement document has n r demand points, then the third representation matrix can be expressed as in It represents the jth requirement point in the requirement document. Represents the length of the jth demand point. The length of a demand point can be the number of demand words. For example, a demand point in the demand document is: the interface color changes with the sunset time. After the word segmentation of this demand point, it can be: interface color, changes with the sunset time, a total of 3 words, then the length of this demand point is 3. Since the test case and code block are written based on the demand document, the first representation matrix and the second representation matrix can be represented based on the demand point of the demand document. The first representation matrix includes the length of the test case and the embedding dimension of the preset encoder. Specifically, the first representation matrix can be represented as Among them l t Represents the length of the test case, and d represents the embedding dimension of the preset encoder. The length of a test case refers to the number of words in the test case. For example, a simple test case: "Check the http status code returned by the interface" is segmented into: check, interface, returned, http and status code, a total of 5 words, so the length of the test case is 5. And assuming that the embedding dimension of the preset encoder is 10, then the dimension of the first representation matrix is 5×10. The second representation matrix also includes the length of the code block and the embedding dimension of the preset encoder. Specifically, the second representation matrix can be represented as Among them l c represents the length of the test case, and d represents the embedding dimension of the preset encoder. The length of a code block refers to the number of words in the code. For example, a code block is: "if(x>y){t=x;x=y;y=t;}if(x>z){t=z;z=x;x=t;}if(y>z){t=y;y=z;z=t;}"; assuming that if() and {} are used as the basis for dividing the code block, the above code block can be divided into: if(x>y), {t=x;x=y;y=t;}, if(x>z), {t=z;z=x;x=t;}, if(y>z) and {t=y;y=z;z=t;}, with a total of 6 words, then the length of the code block is 6. And assuming that the embedding dimension of the preset encoder is 10, then the dimension of the second representation matrix is 6×10.
[0039] In some embodiments, obtaining a first representation matrix of a test case includes: obtaining a test case to be processed; inputting the test case into a preset encoder for word embedding representation to obtain a first representation matrix of the test case; the first representation matrix includes the length of the test case and the embedding dimension of the preset encoder.
[0040] Specifically, word embedding is a representation of a type of word, which represents a single word as a real vector in a predefined vector space, thereby mapping each word to a vector. For example, a test case is input into a preset encoder with a dimension of 3, and the following words are obtained: check, interface, returned, http, and status code, a total of 5 words, so the length of the test case is 5. Then these words are mapped to the vector space, and the vector corresponding to "check" is (0.10.20.3), the vector corresponding to "interface" is (0.20.20.4), the vector corresponding to "returned" is (-0.4-0.5-0.2), the vector corresponding to "http" is (0.30.20.4), and the vector corresponding to "status code" is (0.5 0.10.3) (the above data is for illustration only). In this way, each word corresponds to a vector, and the vectors of all words are combined into a matrix to obtain the first representation matrix, which has a dimension of 5×3, that is, it includes 5 rows and 3 columns of elements.
[0041] In some embodiments, the specific process of obtaining the second representation matrix of the code block is similar to the above-mentioned process of obtaining the first representation matrix, and will not be described in detail here.
[0042] S120, performing cross-attention calculation based on each word vector in the first representation matrix and the word vector of each demand point in the third representation matrix to obtain an enhanced test case representation corresponding to the test case.
[0043] Specifically, the cross-attention calculation is to calculate the attention on two different sequences, which is used to process the semantic relationship between the two sequences. Two different sequences can be mixed or combined, and the obtained calculation result can simultaneously have the representation of the input sequence. In this embodiment, the word vectors in the first representation matrix and the word vectors of each demand point in the third representation matrix are cross-attention calculated to obtain the enhanced test case representation corresponding to the test case, which includes both the information of the test case itself and the association information between the test case and the demand document.
[0044] In some embodiments, cross attention calculation is performed based on each word vector in the first representation matrix and the word vector of each demand point in the third representation matrix to obtain an enhanced test case representation corresponding to the test case, including: Figure 2 The specific process of S1210 to S1240 shown is as follows.
[0045] S1210. Perform cross-attention calculation on each word vector in the first representation matrix and the word vector of each demand point in the third representation matrix to obtain a test case cross-attention matrix.
[0046] Specifically, each word vector in the first representation matrix and each word vector in the third representation matrix are cross-attention calculated, that is, each word vector in the first representation matrix and each word vector in the third representation matrix are dot-product calculated, and the dot-product result is the test case cross-attention matrix, which is used to represent the similarity between each word vector of the test case and the demand point. For example, each word vector in the first representation matrix and each word vector in the third representation matrix are cross-attention calculated, that is, the test case cross-attention matrix Or the test case cross attention matrix is expressed as Among them, M j The element in the mth row and nth column is the mth word vector and demand point R in the test case T. j The dot product result of the nth word vector in represents the similarity of the two word vectors. In this way, each word vector in the test case T and the corresponding demand point R can be calculated. j The similarity of each word vector of makes the test case cross attention matrix include not only the information of the test case itself, but also the association information between the test case and the demand point.
[0047] S1220. Normalize the test case cross-attention matrix row by row to obtain the first attention distribution of the word vector at each position in the test case at the corresponding demand point.
[0048] For example, the cross attention matrix M for the test case j Softmax normalization is performed row by row. Each row of the normalized result represents a word at the corresponding position in the test case T at the demand point R. j The first attention distribution on the first attention distribution can be expressed as s j ). It should be understood that the normalization of the test case cross-attention matrix in this embodiment is to scale the elements in the test case cross-attention matrix to a specific range or standard, so that the stability and comparability of the numerical values can be maintained in subsequent calculations, the convergence speed and accuracy of the algorithm can be improved, and certain problems in numerical calculations, such as floating-point overflow, can be reduced.
[0049] S1230. Perform matrix multiplication on the first attention distribution and the first representation matrix to obtain a first test case representation.
[0050] Specifically, the first attention distribution is matrix multiplied with the first representation matrix, and the representation of the test case can be superimposed on the first attention distribution, so that the data of the first attention distribution and the first representation matrix are compactly concentrated in the first test case representation. The process of calculating the first test case representation can be expressed as T j ′=softmax(M j ) j For example, a 3×2 first attention distribution matrix and a 2×3 first representation matrix can obtain a 3×3 first test case representation, which includes both the information of the test case itself and the association information between the test case and the demand point.
[0051] S1240. Obtain an enhanced test case representation corresponding to the test case based on the first test case representation, the first representation matrix, and the first preset linear layer.
[0052] Specifically, the first preset linear layer can be a linear layer with a residual connection (skip-connect) and an activation function. Residual connection refers to expressing the output as a linear superposition of an input and a nonlinear transformation of the input, which can solve problems such as gradient dissipation and gradient explosion caused by the increase in network depth. The activation function is a function added to an artificial neural network to help the network learn complex patterns in data. In a neuron, the input data is applied to another function after a series of weighted summations, and this function is the activation function here. The linear layer (Linear Layer) is also called a fully connected layer (Fully Connected Layer), and its function is to linearly transform and map the input features and output a new feature representation. In this embodiment, the first test case representation is linearly transformed by the first preset linear layer, and then the first representation matrix is superimposed, and the superimposed matrix is aggregated to obtain an enhanced test case representation.
[0053] In some embodiments, based on the first test case representation, the first representation matrix and the first preset linear layer, an enhanced test case representation corresponding to the test case is obtained, including: Figure 3 The specific process of S1241 to S1243 shown is as follows.
[0054] S1241. Use a first preset linear layer to perform a linear transformation on the first test case representation to obtain a linear test case representation.
[0055] Specifically, the first preset linear layer can perform a linear combination of the input first test case representation through a multiplication operation of a weight matrix, thereby extracting different combinations and representations of the input features; then the result of the linear combination is processed by a nonlinear activation function (such as a ReLU activation function) to increase the ability of the linear test case representation to express the test case features, so that the linear layer can learn a more complex feature representation. Exemplarily, the linear test case representation can be expressed as max 0,T j ′ W1+1), where T j ′W1+1 means T j ′ The linear transformation is performed, W1 is the weight of the first preset linear layer, b1 is the adjustment parameter of the linear layer, and the specific values of W1 and b1 can be determined through training; and max represents the maximum value.
[0056] S1242, superimpose the linear test case representation on the first representation matrix to obtain a first superimposed representation matrix corresponding to the number of demand points. ;
[0057] Specifically, the linear test case is characterized by max 0,T j ′ W1+1), the first characterization matrix is T, then the first superposition characterization matrix If the requirements document has n r demand points, then we can calculate n r indivual (j=1,2,……,n r ), the first superposition characterization matrix can also be expressed as
[0058] S1243. Aggregate the test case representations in the first superposition representation matrix to obtain an enhanced test case representation; the enhanced test case representation incorporates the associated features of the demand points.
[0059] Specifically, each element in the first superposition representation matrix By stacking the matrices, we get Then for T * Perform aggregation to obtain enhanced test case representation For example, pooling operation can be used to * Perform representation aggregation to summarize each test case representation that incorporates the associated features of the demand points to obtain enhanced test case representation It should be understood that the pooling operation aggregates and statistically processes different features to obtain a relatively lower dimension while avoiding overfitting. The pooling operation includes mean pooling and maximum pooling, etc. The specific process of the pooling operation is not repeated here.
[0060] S130, performing cross-attention calculation based on each word vector in the second representation matrix and the word vector of each demand point in the third representation matrix to obtain an enhanced code block representation corresponding to the code block.
[0061] Specifically, the cross-attention calculation is to calculate the attention on two different sequences, which is used to process the semantic relationship between the two sequences. The two different sequences can be mixed or combined, and the calculation result obtained can simultaneously have the representation of the input sequence. In this embodiment, the word vectors in the second representation matrix and the word vectors of each demand point in the third representation matrix are cross-attention calculated to obtain the enhanced code block representation corresponding to the code block, which includes both the information of the code block itself and the association information between the code block and the demand document.
[0062] In some embodiments, cross attention calculation is performed based on each word vector in the second representation matrix and the word vector of each demand point in the third representation matrix to obtain an enhanced code block representation corresponding to the code block, including: Figure 4 The specific process of S1310 to S1340 shown is as follows.
[0063] S1310. Perform cross-attention calculation on the word vectors of each code block in the second representation matrix and each demand point in the third representation matrix to obtain a code block cross-attention matrix.
[0064] Specifically, each word vector in the second representation matrix and each word vector in the third representation matrix are cross-attention calculated, that is, each word vector in the second representation matrix and each word vector in the third representation matrix are dot-product calculated, and the dot-product result is the code block cross-attention matrix, which is used to represent the similarity between each word vector of the code block and the demand point. For example, each word vector in the second representation matrix and each word vector in the third representation matrix are cross-attention calculated, that is, the code block cross-attention matrix M j = Or the code block cross attention matrix is expressed as Among them, M j The element in the mth row and nth column is the mth word vector and demand point R in the code block C. j The dot product result of the nth word vector in represents the similarity between the two word vectors. In this way, each word vector in the code block C and the corresponding demand point R can be calculated. j The similarity of each word vector of makes the code block cross attention matrix include not only the information of the code block itself, but also the association information between the code block and the demand point.
[0065] S1320. Normalize the code block cross-attention matrix by row to obtain the second attention distribution of the word vector at each position in the code block at the corresponding demand point.
[0066] Specifically, for example, the code block cross attention matrix M jSoftmax normalization is performed row by row. Each row of the normalized result represents a word at the corresponding position in the code block C at the demand point R. j The second attention distribution on the second attention distribution can be expressed as s(M j ). Similar to normalizing the test case cross-attention matrix by row, the normalization in this embodiment is to scale the elements in the code block cross-attention matrix to a specific range or standard, so that the stability and comparability of the numerical values can be maintained in subsequent calculations, the convergence speed and accuracy of the algorithm can be improved, and certain problems in numerical calculations, such as floating-point overflow, can be reduced.
[0067] S1330. Perform matrix multiplication on the second attention distribution and the second representation matrix to obtain a first code block representation.
[0068] Specifically, the second attention distribution is matrix multiplied with the second representation matrix, and the representation of the code block can be superimposed on the second attention distribution, so that the data of the second attention distribution and the second representation matrix are compactly concentrated in the first code block representation. The process of calculating the first code block representation can be expressed as C j ′ =softmax(M j ) j For example, a 3×2 second attention distribution matrix and a 2×3 second representation matrix can obtain a 3×3 first code block representation, which includes both the information of the code block itself and the association information between the code block and the demand point.
[0069] S1340. Obtain an enhanced code block representation corresponding to the code block based on the first code block representation, the second representation matrix, and the second preset linear layer.
[0070] Specifically, the second preset linear layer can be a linear layer with a residual connection (skip-connect) and an activation function. Residual connection refers to expressing the output as a linear superposition of an input and a nonlinear transformation of the input, which can solve problems such as gradient dissipation and gradient explosion caused by the increase in network depth. The activation function is a function added to an artificial neural network to help the network learn complex patterns in the data. In a neuron, the input data is applied to another function after a series of weighted summations, and this function is the activation function here. The linear layer (Linear Layer) is also called a fully connected layer (Fully Connected Layer), and its function is to linearly transform and map the input features and output a new feature representation. In this embodiment, the first code block representation is linearly transformed by the second preset linear layer, and then the second representation matrix is superimposed, and the superimposed matrix is aggregated to obtain an enhanced code block representation.
[0071] In some embodiments, based on the first code block representation, the second representation matrix and the second preset linear layer, an enhanced code block representation corresponding to the code block is obtained, including: Figure 5 The specific process of S1341 to S1343 shown is as follows.
[0072] S1341. Use a second preset linear layer to perform a linear transformation on the first code block representation to obtain a linear code block representation.
[0073] Specifically, the second preset linear layer can perform a linear combination of the input first code block representation through a multiplication operation of a weight matrix, thereby extracting different combinations and representations of the input features; then the result of the linear combination is processed by a nonlinear activation function (such as a ReLU activation function) to increase the ability of the linear code block representation to express the code block features, so that the linear layer can learn more complex feature representations. For example, the linear code block representation can be expressed as max 0,C j ′ W2+2), where T j ′ W2+2 means C j ′ The linear transformation is performed, W2 is the weight of the second preset linear layer, b2 is the adjustment parameter of the linear layer, and the specific values of W2 and b2 can be determined through training; and max represents the maximum value.
[0074] S1342. Superimpose the linear code block representation on the second representation matrix to obtain a second superimposed representation matrix corresponding to the number of demand points.
[0075] Specifically, the linear code block is represented as max 0,C j ′ W2+2), the second characterization matrix is C, then the second superposition characterization matrix If the requirements document has n r demand points, then we can calculate n r indivual (j=1,2,……,n r ), the second superposition characterization matrix can also be expressed as
[0076] S1343. Aggregate the code block representations in the second superposition representation matrix to obtain enhanced code block representations; the enhanced code block representations incorporate correlation features of the demand points.
[0077] Specifically, each element in the second superposition representation matrix By stacking the matrices, we get Then for C *Aggregate to get enhanced code block representation For example, pooling operation can be used to * Perform representation aggregation to summarize the representation of each code block that incorporates the associated features of the demand point to obtain an enhanced code block representation It should be understood that the pooling operation obtains a relatively lower dimension by performing statistical processing on different features while avoiding overfitting. The pooling operation may include mean pooling and maximum pooling. The specific process of the pooling operation will not be described in detail here.
[0078] S140, performing cross-attention calculation on the enhanced test case representation and the enhanced code block representation to obtain the similarity between the test case and the code block; the similarity is used to represent the adequacy of the test case.
[0079] Specifically, the enhanced test case representation integrates the associated information of the test case and the requirement document, and the enhanced code block representation integrates the associated information of the code block and the requirement document. However, the test case is a structured natural language, and the code is a computer programming language. In order to make the model better understand the correlation between the two, the enhanced test case representation and the enhanced code block representation are cross-attention calculated, so that the model adds the associated interaction information between the test case and the code block. The calculation result obtained integrates the representation of the test case, the code block and the requirement document. The cross-attention calculation result is more accurate and can be used as the similarity between the test case and the code block. The similarity represents the similarity between the corresponding word units of the test case and the code block. If the similarity is higher, it means that the test case covers the code block more, that is, the test adequacy of the test case is higher; conversely, it means that the test case covers the code block less, that is, the test adequacy of the test case is lower.
[0080] In the technical solution of the present application, a first representation matrix of a test case, a second representation matrix of a code block and a third representation matrix of a requirement document are obtained; the requirement document includes multiple requirement points, and the test case and the code block are written based on the requirement document; cross-attention calculation is performed based on each word vector of the first representation matrix and the word vector of each requirement point in the third representation matrix to obtain an enhanced test case representation corresponding to the test case; cross-attention calculation is performed based on each word vector of the second representation matrix and the word vector of each requirement point in the third representation matrix to obtain an enhanced code block representation corresponding to the code block; cross-attention calculation is performed on the enhanced test case representation and the enhanced code block representation to obtain the similarity between the test case and the code block; the similarity is used to represent the sufficiency of the test case; because the requirement document contains richer content than the test case and the code block, and the requirement document potentially connects the test case and the code block, the present application integrates the features of the requirement document into the test case and code block representation matrix through multiple cross-attention calculations, which can better represent the test case and the code block, and can solve the heterogeneity problem of the test case and the code block, thereby improving the matching accuracy of the test case and the code block.
[0081] In some embodiments, the enhanced test case representation and the enhanced code block representation are cross-attention calculated to obtain the similarity between the test case and the code block, including: Figure 6 The specific process of S1410 to S1430 shown is as follows.
[0082] S1410, performing cross attention calculation on the enhanced test case representation and the enhanced code block representation to obtain an enhanced cross attention matrix;
[0083] Specifically, the calculation process of the enhanced cross attention matrix can be expressed as in To enhance test case representation, To enhance the code block representation, the enhanced cross attention matrix can also be expressed as The elements in this matrix represent the similarity between the corresponding tokens of the test case and the code block. Cross-attention of the enhanced test case representation and the enhanced code block representation can generate interaction between the test case and the code, so that the model can better understand the correlation between the test case and the code, and solve the problem of low matching result accuracy caused by the heterogeneity of the test case and the code block.
[0084] S1420. Perform matrix multiplication on the enhanced cross-attention matrix, the enhanced test case representation, and the enhanced code block representation to obtain corresponding second test case representation and second code block representation.
[0085] Specifically, further calculating the matrix multiplication of the enhanced cross attention matrix and the enhanced test case representation, the representation of the enhanced test case can be superimposed on the enhanced cross attention matrix, so that the representations of the enhanced cross attention matrix and the enhanced test case representation are more compactly concentrated into the second test case representation, and the second test case representation can be expressed as And the matrix multiplication of the enhanced cross attention matrix and the enhanced code block representation is calculated. The enhanced code block representation can be superimposed on the enhanced cross attention matrix to make the representations of the enhanced cross attention matrix and the enhanced code block representation more compactly concentrated into the second code block representation. The second code block representation can be expressed as
[0086] S1430: Based on the second test case representation and the second code block representation, obtain the similarity between the test case and the code block.
[0087] Specifically, the second test case representation and the second code block representation have integrated the features of the test case, code block, and requirement document. However, the previous processes are all about calculating the matching representations between the word units of the test case, code block, and requirement document. The mean pooling method can also be used to aggregate the matching representations at the sentence level to condense the rich language features of the input sequence and the deep interaction information and matching features between sequences. The obtained similarity can be more accurate and can more comprehensively verify the adequacy of the test case.
[0088] In some embodiments, based on the second test case representation and the second code block representation, the similarity between the test case and the code block is obtained, including S1431 to S1433, and the specific process is as follows.
[0089] S1431. Aggregate the second test case representation to obtain a test case representation vector.
[0090] Specifically, the second test case representation is aggregated using a pooling operation to obtain a test case representation vector It should be understood that the pooling operation aggregates and statistically processes different features to obtain a relatively lower dimension while avoiding overfitting. The pooling operation includes mean pooling and maximum pooling, etc. The specific process of the pooling operation is not repeated here.
[0091] S1432. Aggregate the second code block representation to obtain a code block representation vector.
[0092] Specifically, the second code block representation is aggregated using a pooling operation to obtain a code block representation vector
[0093] S1433. Calculate the vector dot product of the test case representation vector and the code block representation vector, and use the vector dot product as the similarity.
[0094] Specifically, the vector dot product of the test case representation vector and the code block representation vector is calculated using the following formula: Where dot(·,·) represents the dot product calculation of two vectors, and the matching score s represents the matching degree between the test case and the code block, which is the final output of the verification model of the test case.
[0095] The electronic equipment of this application is introduced below, such as Figure 7 As shown, the present application provides an electronic device 700, which includes: a processor 710 and a memory 720, the memory 720 is used to store executable instructions of the processor; the processor 710 executes the executable instructions to enable the electronic device to implement the verification method of the test case provided by any embodiment of the present application.
[0096] Specifically, the verification method of the test case provided in the present application is stored in the memory 720 of the electronic device 700, and the processor 710 is used to execute to obtain the first representation matrix of the test case, the second representation matrix of the code block, and the third representation matrix of the requirement document; based on the word vectors of the first representation matrix and the word vectors of each requirement point in the third representation matrix, a cross-attention calculation is performed to obtain an enhanced test case representation corresponding to the test case; based on the word vectors of the second representation matrix and the word vectors of each requirement point in the third representation matrix, a cross-attention calculation is performed to obtain an enhanced code block representation corresponding to the code block; the enhanced test case representation and the enhanced code block representation are cross-attention calculated to obtain the similarity between the test case and the code block; in this way, through multiple cross-attention calculations, the features of the requirement document are integrated into the test case and the code block, which can better represent the test case and the code block, and can also solve the heterogeneity problem of the test case and the code block, thereby improving the matching accuracy of the test case and the code block.
[0097] It should be known that the specific implementation content of the electronic device in the present application has been explained in detail in the corresponding method embodiment and will not be repeated here.
[0098] Figure 8 The structure block diagram of a computer system for implementing an electronic device according to an embodiment of the present application is schematically shown.
[0099] It should be noted that Figure 8 The computer system 800 of the electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0100] like Figure 8As shown, the computer system 800 includes a processor 801, which can be a CPU (Central Processing Unit) or an MCU (Microcontroller Unit). The processor 801 can perform various appropriate actions and processes according to the program stored in the read-only memory 802 (Read-Only Memory, ROM) or the program loaded from the storage part 808 to the random access memory 803 (Random Access Memory, RAM). In the random access memory 803, various programs and data required for system operation are also stored. The processor 801, the read-only memory 802 and the random access memory 803 are connected to each other through a bus 804. The input / output interface 805 (Input / Output interface, i.e., I / O interface) is also connected to the bus 804.
[0101] The following components are connected to the input / output interface 805: an input section 806 including a keyboard, a mouse, etc.; an output section 807 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker; a storage section 808 including a hard disk, etc.; and a communication section 809 including a network interface card such as a local area network card, a modem, etc. The communication section 809 performs communication processing via a network such as the Internet. A drive 810 is also connected to the input / output interface 805 as needed. A removable medium 811, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 810 as needed so that a computer program read therefrom is installed into the storage section 808 as needed.
[0102] In particular, according to an embodiment of the present application, the processes described in the various method flow charts can be implemented as computer software programs. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program contains program code for executing the method shown in the flow chart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication section 809, and / or installed from a removable medium 811. When the computer program is executed by the processor 801, various functions defined in the system of the present application are executed.
[0103] It should be noted that the computer-readable medium shown in the embodiment of the present application may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, a system, device or device of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a flash memory, an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable storage medium may be any tangible medium containing or storing a program, which may be used by an instruction execution system, device or device or used in combination with it. In the present application, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, wherein a computer-readable program code is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer readable signal media may also be any computer readable medium other than computer readable storage media, which may send, propagate, or transmit programs for use by or in conjunction with an instruction execution system, apparatus, or device. The program code contained on the computer readable medium may be transmitted using any suitable medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above.
[0104] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the above-mentioned module, program segment or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0105] It should be noted that, although several modules or units of the equipment for action execution are mentioned in the above detailed description, this division is not mandatory. In fact, according to the embodiments of the present application, the features and functions of two or more modules or units described above can be embodied in one module or unit. On the contrary, the features and functions of one module or unit described above can be further divided into being embodied by multiple modules or units.
[0106] Through the description of the above implementation methods, it is easy for those skilled in the art to understand that the example implementation methods described here can be implemented by software, or by software combined with necessary hardware. Therefore, the technical solution according to the implementation method of the present application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, including several instructions to enable a computing device (which can be a personal computer, a server, a touch terminal, or a network device, etc.) to execute the implementation method according to the present application.
[0107] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the invention disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary technical means in the art that are not disclosed in the present application.
[0108] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.
Claims
1. A test case verification method, characterized in that: include: Obtaining a first characterization matrix of the test case, a second characterization matrix of the code block, and a third characterization matrix of the requirement document; The requirement document includes multiple requirement points, and the test case and the code block are written based on the requirement document; Perform cross-attention calculation based on each word vector in the first representation matrix and the word vector of each demand point in the third representation matrix to obtain an enhanced test case representation corresponding to the test case; Perform cross attention calculation based on each word vector in the second representation matrix and the word vector of each demand point in the third representation matrix to obtain an enhanced code block representation corresponding to the code block; Performing cross attention calculation on the enhanced test case representation and the enhanced code block representation to obtain the similarity between the test case and the code block; The similarity is used to represent the adequacy of the test case.
2. The test case verification method according to claim 1, characterized in that: The cross-attention calculation is performed based on each word vector of the first representation matrix and the word vector of each demand point in the third representation matrix to obtain an enhanced test case representation corresponding to the test case, including: Perform cross-attention calculation on each word vector of the first representation matrix and the word vector of each demand point in the third representation matrix to obtain a test case cross-attention matrix; the test case cross-attention matrix is used to represent the similarity between each word vector of the test case and the demand point; Normalizing the test case cross attention matrix row by row to obtain the first attention distribution of the word vector at each position in the test case at the corresponding demand point; Performing matrix multiplication on the first attention distribution and the first representation matrix to obtain a first test case representation; the first test case representation includes information about the test case itself and also includes association information between the test case and the demand point; Based on the first test case representation, the first representation matrix and the first preset linear layer, an enhanced test case representation corresponding to the test case is obtained.
3. The test case verification method according to claim 2, characterized in that: The obtaining, based on the first test case representation, the first representation matrix and the first preset linear layer, an enhanced test case representation corresponding to the test case includes: Using a first preset linear layer to perform a linear transformation on the first test case representation to obtain a linear test case representation; Superimposing the linear test case representation onto the first representation matrix to obtain a first superimposed representation matrix corresponding to the number of demand points; The test case representations in the first superposition representation matrix are aggregated to obtain enhanced test case representations; the enhanced test case representations incorporate correlation features of demand points.
4. The test case verification method according to claim 1, characterized in that: The cross-attention calculation is performed based on each word vector of the second representation matrix and the word vector of each demand point in the third representation matrix to obtain an enhanced code block representation corresponding to the code block, including: Perform cross-attention calculation on each code block in the second representation matrix and the word vector of each demand point in the third representation matrix to obtain a code block cross-attention matrix; the code block cross-attention matrix is used to represent the similarity between each word vector of the code block and the demand point; Normalizing the code block cross attention matrix row by row to obtain the second attention distribution of the word vector at each position in the code block at the corresponding demand point; Performing matrix multiplication on the second attention distribution and the second representation matrix to obtain a first code block representation; the first code block representation includes information about the code block itself and also includes association information between the code block and the demand point; Based on the first code block representation, the second representation matrix and the second preset linear layer, an enhanced code block representation corresponding to the code block is obtained.
5. The test case verification method according to claim 4, characterized in that: The obtaining, based on the first code block representation, the second representation matrix and the second preset linear layer, an enhanced code block representation corresponding to the code block includes: Using a second preset linear layer to perform a linear transformation on the first code block representation to obtain a linear code block representation; Superimposing the linear code block representation onto a second representation matrix to obtain a second superimposed representation matrix corresponding to the number of demand points; The code block representations in the second superposition representation matrix are aggregated to obtain an enhanced code block representation; the enhanced code block representation incorporates the associated features of the demand points.
6. The test case verification method according to claim 1, characterized in that: The performing cross attention calculation on the enhanced test case representation and the enhanced code block representation to obtain the similarity between the test case and the code block includes: Perform cross-attention calculation on the enhanced test case representation and the enhanced code block representation to obtain an enhanced cross-attention matrix; Perform matrix multiplication of the enhanced cross attention matrix with the enhanced test case representation and the enhanced code block representation to obtain corresponding second test case representation and second code block representation; Based on the second test case representation and the second code block representation, the similarity between the test case and the code block is obtained.
7. The test case verification method according to claim 6, characterized in that: The obtaining, based on the second test case representation and the second code block representation, the similarity between the test case and the code block includes: Aggregating the second test case representation to obtain a test case representation vector; and aggregating the second code block representation to obtain a code block representation vector; A vector dot product of the test case representation vector and the code block representation vector is calculated, and the vector dot product is used as the similarity.
8. The test case verification method according to claim 1, characterized in that: The step of obtaining a first characterization matrix of the test case includes: Get the test cases to be processed; The test case is input into a preset encoder for word embedding representation to obtain a first representation matrix of the test case; the first representation matrix includes the length of the test case and the embedding dimension of the preset encoder.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the test case verification method described in any one of claims 1 to 8 is implemented.
10. An electronic device, characterized in that: include: processor; A memory, configured to store executable instructions of the processor; The processor executes the executable instructions to enable the electronic device to implement the test case verification method as described in any one of claims 1 to 8.