Automatic generation method of test case and related device
By extracting the full code group of code calling paths of the target uncovered code from the test coverage report, and using the preset feature extraction model and the encoder decoder to generate test cases, the inefficient automatic generation of test cases in the prior art is solved. Problem, achieving high-precision and efficient test case generation.
Patent Information
- Application Number
- CN202411743771.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-30
- Publication Date
- 2025-02-21
AI Technical Summary
The existing technology is difficult to automatically generate test cases, which leads to inefficient testing personnel needing to manually generate test cases based on test coverage reports.
By extracting the full code group of the code call path of the target's uncovered code from the test coverage report, and using the preset feature extraction model to extract the feature vector, combining the preset encoder and decoder, a test case of the target's uncovered code is generated.
It realizes automatic generation of test cases, improves the generation accuracy and efficiency of test cases, and reduces manual intervention.
Smart Images

Figure CN119493736A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of software testing technology, and in particular to a method for automatically generating test cases and related devices. Background Art
[0002] After the software is developed, in order to avoid the risk of code defects causing reduced software stability, testers need to write corresponding test cases for different software functions and use the test cases to test the software code to find code defects and fix them. Since the software implements many functions, the test cases provided by the testers cannot cover all the software codes. At this time, the testers need to analyze the test process to find the uncovered code and regenerate test cases to test the uncovered code. However, the amount of software code is too large, and the efficiency of manually searching for uncovered code is low, which seriously affects the testing efficiency.
[0003] In order to solve the above problems, the prior art proposes to use a precision testing system to monitor the software testing process and automatically generate a test coverage report including uncovered code, which omits the step of manually searching for uncovered code and improves the testing efficiency to a certain extent. However, the existing precision testing system can only realize the automatic generation of test coverage reports, and the test cases for testing uncovered code still need to be manually generated by testers based on other data in the test coverage report. Therefore, how to realize the automatic generation of test cases has become a problem that needs to be solved urgently. Summary of the invention
[0004] In view of the above problems, the present application provides a method and a related device for automatically generating test cases to achieve the purpose of automatically generating test cases. The specific scheme is as follows:
[0005] The first aspect of the present application provides a method for automatically generating a test case, comprising:
[0006] Obtain a test coverage report and target uncovered code, and extract a full code group of a code call path of the target uncovered code from the test coverage report;
[0007] A preset feature extraction model is used to extract feature vectors of the target uncovered code and the full code group respectively, to obtain a call link feature vector and a call feature vector of the target uncovered code, wherein the call link feature vector represents the full call parameter features associated with the call of the target uncovered code in the code call path, and the call feature vector represents the full parameter features associated with the call of the target uncovered code; feature fusion is performed on the call link feature vector and the call feature vector to obtain a call information feature vector of the target uncovered code, wherein the call information feature vector represents the full call information associated with calling the target uncovered code;
[0008] Inputting the call information feature vector into a preset encoder so that the preset encoder outputs a weight coding set including a feature weight coding of each of the call information in the call information feature vector, wherein the feature weight coding carries a weight representing a degree of association between the call information and the call of the target uncovered code;
[0009] The weight coding set and the test case template are input into a preset decoder to obtain the test case of the target uncovered code.
[0010] In a possible implementation, inputting the call information feature vector into a preset encoder so that the preset encoder outputs a weight coding set including feature weight coding of each call information in the call information feature vector, includes:
[0011] The call information feature vector is input into the preset encoder, and the preset encoder includes a module layer, a weight generation network and an output layer, wherein the module is used to perform an encoding operation on each of the call information in the call information feature vector to obtain a feature code corresponding to each of the call information; the weight generation network is used to generate the weight corresponding to the call information based on the feature code; the output layer is used to perform a product operation on the weight corresponding to the call information and the feature code, and output the feature weight code corresponding to the call information;
[0012] The weight coding set of the feature weight coding of each of the call information output by the preset encoder is obtained.
[0013] In a possible implementation, inputting the weight coding set and the test case template into a preset decoder to obtain the test case of the target uncovered code includes:
[0014] Input the weight coding set and the test case template into a preset decoder, the preset decoder is used to perform nonlinear transformation on the test case template and the weight coding set, and generate the test case including the call information corresponding to each target feature weight coding in the weight coding set based on the transformation result, wherein the target feature weight coding is the feature weight coding whose weight is not less than a preset threshold;
[0015] The test case of the target uncovered code output by the preset decoder is obtained.
[0016] In a possible implementation, the training process of the preset encoder includes:
[0017] Extracting multiple historical covered codes and a first historical full code group of historical code call paths of each of the historical covered codes from multiple historical test coverage reports; extracting multiple historical uncovered codes and a second historical full code group of historical code call paths of each of the historical uncovered codes from the multiple historical test coverage reports;
[0018] For each of the historical coverage codes: using a preset feature extraction model, respectively extract feature vectors for the historical coverage code and the first historical full code group of the historical coverage code to obtain a first historical call link feature vector and a first historical call feature vector of the historical coverage code; perform feature fusion on the first historical call link feature vector and the first historical call feature vector to obtain a first historical call information feature vector of the historical coverage code;
[0019] For each of the historical uncovered codes: using a preset feature extraction model, respectively extract feature vectors for the historical uncovered code and the second historical full code group of the historical uncovered code to obtain a second historical call link feature vector and a second historical call feature vector for the historical uncovered code; perform feature fusion on the second historical call link feature vector and the second historical call feature vector to obtain a second historical call information feature vector for the historical uncovered code;
[0020] For the first historical call information feature vector of each of the historical coverage codes: extract each piece of first historical call information in the first historical call information feature vector, and assign a weight to each piece of the first historical call information;
[0021] For each of the second historical call information feature vectors of the historical uncovered codes: extracting each of the second historical call information in the second historical call information feature vector, and assigning a weight to each of the second historical call information;
[0022] Obtaining a first weight assignment information set corresponding to each of the historical covered codes and a second weight assignment information set corresponding to each of the historical uncovered codes;
[0023] The initial encoder is trained using a training set including the first historical call information feature vector of each of the historical covered codes and the second historical call information feature vector of each of the historical uncovered codes, and the initial encoder is adjusted based on the first weight assignment information set and the second weight assignment information set to obtain the preset encoder, wherein the input of the preset encoder is the call information feature vector, and the output is a weight coding set of the feature weight coding of each call information in the call information feature vector.
[0024] In a possible implementation, the preset feature extraction model includes a preset compiler and a preset graph convolutional neural network, and the preset feature extraction model is used to extract feature vectors from the target uncovered code and the full code group respectively to obtain a call link feature vector and a call feature vector of the target uncovered code, including:
[0025] Using the preset compiler to convert the target uncovered code into a first directed acyclic graph, and using the preset graph convolutional neural network to extract feature vectors from the first directed acyclic graph to obtain the call feature vector of the target uncovered code;
[0026] The preset compiler is used to convert the full code group into a second directed acyclic graph, and the preset graph convolutional neural network is used to extract feature vectors from the second directed acyclic graph to obtain the call link feature vector of the target uncovered code.
[0027] A second aspect of the present application provides a system for automatically generating test cases, comprising:
[0028] A first parameter extraction module is used to obtain a test coverage report and target uncovered code, and extract a full code group of a code call path of the target uncovered code from the test coverage report;
[0029] A second parameter extraction module is used to use a preset feature extraction model to extract feature vectors from the target uncovered code and the full code group respectively, to obtain a call link feature vector and a call feature vector of the target uncovered code, wherein the call link feature vector represents the full call parameter features associated with the call of the target uncovered code in the code call path, and the call feature vector represents the full parameter features associated with the call of the target uncovered code; feature fusion is performed on the call link feature vector and the call feature vector to obtain a call information feature vector of the target uncovered code, wherein the call information feature vector represents the full call information associated with calling the target uncovered code;
[0030] An encoding module, used for inputting the call information feature vector into a preset encoder, so that the preset encoder outputs a weight encoding set including a feature weight encoding of each of the call information in the call information feature vector, wherein the feature weight encoding carries a weight representing a degree of association between the call information and the call of the target uncovered code;
[0031] A decoding module is used to input the weight coding set and the test case template into a preset decoder to obtain the test case of the target uncovered code.
[0032] In a possible implementation, the encoding module is configured to:
[0033] The call information feature vector is input into the preset encoder, and the preset encoder includes a module layer, a weight generation network and an output layer, wherein the module is used to perform an encoding operation on each of the call information in the call information feature vector to obtain a feature code corresponding to each of the call information; the weight generation network is used to generate the weight corresponding to the call information based on the feature code; the output layer is used to perform a product operation on the weight corresponding to the call information and the feature code, and output the feature weight code corresponding to the call information;
[0034] The weight coding set of the feature weight coding of each of the call information output by the preset encoder is obtained.
[0035] In a possible implementation, the decoding module is configured to:
[0036] Input the weight coding set and the test case template into a preset decoder, the preset decoder is used to perform nonlinear transformation on the test case template and the weight coding set, and generate the test case including the call information corresponding to each target feature weight coding in the weight coding set based on the transformation result, wherein the target feature weight coding is the feature weight coding whose weight is not less than a preset threshold;
[0037] The test case of the target uncovered code output by the preset decoder is obtained.
[0038] In a possible implementation, the automatic test case generation system further includes an encoder training module, and the encoder training module is configured to:
[0039] Extracting multiple historical covered codes and a first historical full code group of historical code call paths of each of the historical covered codes from multiple historical test coverage reports; extracting multiple historical uncovered codes and a second historical full code group of historical code call paths of each of the historical uncovered codes from the multiple historical test coverage reports;
[0040] For each of the historical coverage codes: using a preset feature extraction model, respectively extract feature vectors for the historical coverage code and the first historical full code group of the historical coverage code to obtain a first historical call link feature vector and a first historical call feature vector of the historical coverage code; perform feature fusion on the first historical call link feature vector and the first historical call feature vector to obtain a first historical call information feature vector of the historical coverage code;
[0041] For each of the historical uncovered codes: using a preset feature extraction model, respectively extract feature vectors for the historical uncovered code and the second historical full code group of the historical uncovered code to obtain a second historical call link feature vector and a second historical call feature vector for the historical uncovered code; perform feature fusion on the second historical call link feature vector and the second historical call feature vector to obtain a second historical call information feature vector for the historical uncovered code;
[0042] For the first historical call information feature vector of each of the historical coverage codes: extract each piece of first historical call information in the first historical call information feature vector, and assign a weight to each piece of the first historical call information;
[0043] For each of the second historical call information feature vectors of the historical uncovered codes: extracting each of the second historical call information in the second historical call information feature vector, and assigning a weight to each of the second historical call information;
[0044] Obtaining a first weight assignment information set corresponding to each of the historical covered codes and a second weight assignment information set corresponding to each of the historical uncovered codes;
[0045] The initial encoder is trained using a training set including the first historical call information feature vector of each of the historical covered codes and the second historical call information feature vector of each of the historical uncovered codes, and the initial encoder is adjusted based on the first weight assignment information set and the second weight assignment information set to obtain the preset encoder, wherein the input of the preset encoder is the call information feature vector, and the output is a weight coding set of the feature weight coding of each call information in the call information feature vector.
[0046] In a possible implementation, when the second parameter extraction module extracts feature vectors from the target uncovered code and the full code group respectively using a preset feature extraction model to obtain a call link feature vector and a call feature vector of the target uncovered code, the second parameter extraction module is set to:
[0047] The preset feature extraction model includes a preset compiler and a preset graph convolutional neural network, the second parameter extraction module uses the preset compiler to convert the target uncovered code into a first directed acyclic graph, and uses the preset graph convolutional neural network to extract a feature vector from the first directed acyclic graph to obtain the call feature vector of the target uncovered code;
[0048] The second parameter extraction module uses the preset compiler to convert the full code group into a second directed acyclic graph, and uses the preset graph convolutional neural network to extract feature vectors from the second directed acyclic graph to obtain the call link feature vector of the target uncovered code.
[0049] The third aspect of the present application provides a computer program product, including computer-readable instructions. When the computer-readable instructions are executed on an electronic device, the electronic device implements the method for automatically generating test cases of the above-mentioned first aspect or any implementation method of the first aspect.
[0050] A fourth aspect of the present application provides an electronic device, comprising at least one processor and a memory connected to the processor, wherein:
[0051] The memory is used to store computer programs;
[0052] The processor is used to execute the computer program so that the electronic device can implement the method for automatically generating test cases of the above-mentioned first aspect or any implementation manner of the first aspect.
[0053] The fifth aspect of the present application provides a computer storage medium, which carries one or more computer programs. When the one or more computer programs are executed by an electronic device, the electronic device can automatically generate test cases according to the first aspect or any implementation method of the first aspect.
[0054] By means of the above technical scheme, the automatic generation method and related devices of test cases provided by the present application configure a full code group of the code call path of the target uncovered code to be extracted from the test coverage report, and configure a preset feature extraction model to extract feature vectors of the target uncovered code and the full code group respectively, to obtain a call path feature vector representing the full call parameter features associated with the call of the target uncovered code in the code call path, and a call feature vector representing the full parameter features associated with the target uncovered code being called, thereby realizing the extraction of the full parameter features associated with calling the target uncovered code. Subsequently, by configuring a preset encoder to output a weight coding set including the feature weight coding of each call information in the call information feature vector according to the input call information feature vector, and inputting the weight coding set and the test case template into the preset decoder, the test case of the target uncovered code is obtained, thereby realizing the automatic generation of test cases for uncovered code testing. At the same time, since the feature weight coding of the weight coding set carries the weight that characterizes the degree of association between the call information and the uncovered code of the call target, the preset decoder can select the call information with a high degree of association with the uncovered code of the call target based on the weight to generate test cases, thereby improving the generation accuracy of test cases. It can be seen that the present application realizes the automatic generation of test cases while improving the generation accuracy of test cases. BRIEF DESCRIPTION OF THE DRAWINGS
[0055] The above and other features, advantages and aspects of the embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. Throughout the accompanying drawings, the same or similar reference numerals represent the same or similar elements. It should be understood that the drawings are schematic and the originals and elements are not necessarily drawn to scale.
[0056] Figure 1 A flowchart of a method for automatically generating test cases provided in this application;
[0057] Figure 2 A schematic diagram of a code calling path provided for this application;
[0058] Figure 3 A schematic diagram of the structure of an existing Transformer encoder provided for this application;
[0059] Figure 4 A schematic diagram of the structure of a preset encoder provided in this application;
[0060] Figure 5 A flowchart of a method for automatically generating test cases provided in this application;
[0061] Figure 6A schematic diagram of the structure of a fully automatic software testing system for automatically generating cases provided in this application;
[0062] Figure 7 A flowchart of an automatic software testing method provided for this application;
[0063] Figure 8 A block diagram of a test case automatic generation system provided in this application;
[0064] Fig. 9 A schematic diagram of the structure of an electronic device provided in this application. DETAILED DESCRIPTION
[0065] The following describes the embodiments of the present application in conjunction with the drawings in the embodiments of the present application. The terms used in the implementation method section of the present application are only used to explain the specific embodiments of the present application, and are not intended to limit the present application.
[0066] The embodiments of the present application are described below in conjunction with the accompanying drawings. Those skilled in the art will appreciate that, with the development of technology and the emergence of new scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.
[0067] The terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and need not be used to describe a specific order or sequential order. It should be understood that the terms used in this way can be interchangeable under appropriate circumstances, which is only to describe the distinction mode adopted by the objects of the same attributes when describing in the embodiments of the present application. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, so that the process, method, system, product or equipment comprising a series of units need not be limited to those units, but may include other units that are not clearly listed or inherent to these processes, methods, products or equipment.
[0068] The first aspect of the present application provides a method for automatically generating test cases, such as Figure 1 As shown, the automatic generation method of the test case includes:
[0069] S101, obtaining a test coverage report and target uncovered code, and extracting a full code group of a code call path of the target uncovered code from the test coverage report.
[0070] It should be noted that in actual application scenarios, the above code call path is in the full code of the tested software, and all node codes of the target uncovered code can be called. In order to facilitate the understanding of the above code call path, a possible implementation of this application is specially described here:
[0071] like Figure 2The following is a schematic diagram of a code calling path. C is the target uncovered code. Figure 2 It can be seen that there are three code calling paths for the target uncovered code C. The first one is A, A1, A3, C, the second one is A, A2, B2, C, and the third one is B, B1, B2, C.
[0072] It should be noted that, in actual application scenarios, the above full code group includes the call-related code of each path node of the code call path. The types of the above call-related code include but are not limited to: method call, interface input parameters, parameter restriction conditions, etc.
[0073] It should be noted that, in actual application scenarios, the implementation method of extracting the full code group of the code call path of the target uncovered code from the test coverage report can be: traversing the first-level code whose output interface in the test coverage report is the input interface of the target uncovered code, and then traversing the second-level code whose output interface in the test coverage report is the input interface of the first-level code, and so on, until the input interface of the N-level code found is the starting entry of the software, the traversal is terminated, and the above-mentioned code call path is determined according to the traversal order, and the above-mentioned full code group is extracted from the code at each level.
[0074] S102. Use a preset feature extraction model to extract feature vectors for the target uncovered code and the full code group respectively, and obtain a call link feature vector and a call feature vector of the target uncovered code. The call link feature vector represents the full call parameter features associated with the call of the target uncovered code in the code call path, and the call feature vector represents the full parameter features associated with the target uncovered code being called. Perform feature fusion on the call link feature vector and the call feature vector to obtain a call information feature vector of the target uncovered code. The call information feature vector represents the full call information associated with calling the target uncovered code.
[0075] It should be noted that in actual application scenarios, since the above-mentioned target uncovered code and full code group store the associated information required when calling the target uncovered code, such as dependencies, grammatical structures, function call patterns, etc. For subsequent encoders, it is impossible to extract the above information based on the target uncovered code and full code group in code form. Therefore, the present application configures a full code group that extracts the code call path of the target uncovered code from the test coverage report, and configures a preset feature extraction model to extract feature vectors for the target uncovered code and the full code group respectively, to obtain a call path feature vector that characterizes the full call parameter features associated with the call of the target uncovered code in the code call path, and a call feature vector that characterizes the full parameter features associated with the target uncovered code being called, thereby realizing the extraction of full parameter features associated with calling the target uncovered code.
[0076] S103, input the call information feature vector into a preset encoder, so that the preset encoder outputs a weight coding set including feature weight coding of each call information in the call information feature vector, wherein the feature weight coding carries a weight representing the degree of association between the call information and the uncovered code of the call target.
[0077] It should be noted that, in actual application scenarios, since the above-mentioned information feature vector is used to represent the full amount of call information associated with the uncovered code of the call target, not all call information can be used to generate test cases. For example, if the call information is "parameter restriction condition", but the value of the information is empty, that is, no restriction condition is set for the parameter of the call target uncovered code in the code. Obviously, the degree of association between the call information and the call target uncovered code is low. At this time, if the "parameter restriction condition" is still used as the call information for generating test cases, invalid instructions will exist in the test case, and even the test will fail. Therefore, the present application configures a preset encoder to output a weight coding set including the feature weight coding of each call information in the call information feature vector according to the call information feature vector, thereby using weights to represent the degree of association between the call information and the call target uncovered code, so that the preset decoder can select the call information with a higher degree of association with the call target uncovered code based on the weight to generate test cases, thereby improving the generation accuracy of test cases.
[0078] S104: Input the weight coding set and the test case template into a preset decoder to obtain the test case of the target uncovered code.
[0079] The present application extracts the full code group of the code call path of the target uncovered code from the test coverage report by configuring, and configures the preset feature extraction model to extract feature vectors of the target uncovered code and the full code group respectively, and obtains the call path feature vector that characterizes the full call parameter features associated with the call of the target uncovered code in the code call path, and the call feature vector that characterizes the full parameter features associated with the target uncovered code, thereby realizing the extraction of the full parameter features associated with the call target uncovered code. Subsequently, by configuring the preset encoder to output a weight coding set including the feature weight coding of each call information in the call information feature vector according to the input call information feature vector, and inputting the weight coding set and the test case template into the preset decoder, the test case of the target uncovered code is obtained, and the automatic generation of test cases for the uncovered code test is realized. At the same time, because the feature weight coding of the weight coding set carries the weight that characterizes the degree of association between the call information and the call target uncovered code, the preset decoder can select the call information with a higher degree of association with the call target uncovered code based on the weight to generate the test case, thereby improving the generation accuracy of the test case. It can be seen that the present application realizes the automatic generation of test cases while improving the generation accuracy of test cases.
[0080] In a possible implementation, the call information feature vector is input into a preset encoder, so that the preset encoder outputs a weight coding set including feature weight coding of each call information in the call information feature vector, including:
[0081] Input the call information feature vector into a preset encoder, which includes a module layer, a weight generation network and an output layer. The module is used to encode each call information in the call information feature vector to obtain the feature code corresponding to each call information; the weight generation network is used to generate the weight corresponding to the call information based on the feature code; the output layer is used to perform a product operation on the weight corresponding to the call information and the feature code, and output the feature weight code corresponding to the call information;
[0082] A weight coding set including feature weight coding of each call information output by a preset encoder is obtained.
[0083] It should be noted that, in actual application scenarios, the preset encoder can be an encoder constructed by configuring the weight generation network on the basis of the existing Transformer encoder. The weight generation network includes a feedforward neural network (FNN) and a multi-layer perceptron (MLP) that receives the output of the feedforward neural network. Figure 3As shown in the figure: the position encoding layer sends the feature vector added by the position information condition to the multi-head self-attention layer and the residual connection and normalization layer, the multi-head self-attention layer sends the captured dependency to the residual connection and normalization layer, the residual connection and normalization layer further extracts features and maintains gradients according to the dependency and the features added by the position information condition, and sends the extracted features to the feedforward neural network and another residual connection and normalization layer respectively, the feedforward neural network sends the features after nonlinear transformation to another residual connection and normalization layer, further extracts features and maintains gradients. The last residual connection and normalization layer outputs feature encoding through the output layer. However, since the existing Transformer encoder will perform indiscriminate feature extraction on all input features, the existing Transformer encoder cannot identify the degree of correlation between the call information and the uncovered code of the call target, so that the feature encoding output by the existing Transformer encoder contains call information with a low degree of correlation with the uncovered code of the call target. If test cases are generated based on such feature encoding, irrelevant test codes will exist in the test cases, resulting in reduced test case generation. The present application further processes the feature encoding by configuring the above-mentioned weight generation network to analyze the degree of association between the call information and the uncovered code of the call target from the feature encoding to obtain the weight, and configures the above-mentioned output layer to perform a product operation on the weight corresponding to the call information and the feature encoding, and outputs the feature weight encoding corresponding to the call information, thereby realizing the distinction between call information with different degrees of association with the uncovered code of the call target, thereby improving the accuracy of the test cases generated subsequently. The structural diagram of the above-mentioned preset encoder is shown in FIG. Figure 4 shown.
[0084] In a possible implementation, the weight coding set and the test case template are input into a preset decoder to obtain a test case of the target uncovered code, including:
[0085] The weight coding set and the test case template are input into a preset decoder, and the preset decoder is used to perform nonlinear transformation on the test case template and the weight coding set, and generate a test case including call information corresponding to each target feature weight coding in the weight coding set based on the transformation result, wherein the target feature weight coding is a feature weight coding with a weight not less than a preset threshold;
[0086] Get test cases for target uncovered code output by the preset decoder.
[0087] It should be noted that in actual application scenarios, the above-mentioned preset decoder is an existing Transformer decoder. The above-mentioned preset decoder is used to perform nonlinear transformation on the test case template and the weight coding set, and generate a test case including the call information corresponding to each target feature weight coding in the weight coding set based on the transformation result. The implementation method is similar to the decoding process of the existing Transformer decoder: the test case template is used as the query (query), the feature weight coding is used as the key (key) and value (value), the test case template and the feature weight coding are input into the attention layer to obtain the above-mentioned test case.
[0088] In a possible implementation, the training process of the preset encoder includes:
[0089] Extracting multiple historical covered codes and a first historical full code group of historical code call paths of each historical covered code from multiple historical test coverage reports; extracting multiple historical uncovered codes and a second historical full code group of historical code call paths of each historical uncovered code from multiple historical test coverage reports;
[0090] For each historical coverage code: use a preset feature extraction model to extract feature vectors of the historical coverage code and the first historical full code group of the historical coverage code respectively, and obtain the first historical call link feature vector and the first historical call feature vector of the historical coverage code; perform feature fusion on the first historical call link feature vector and the first historical call feature vector to obtain the first historical call information feature vector of the historical coverage code;
[0091] For each historical uncovered code: use a preset feature extraction model to extract feature vectors for the historical uncovered code and the second historical full code group of the historical uncovered code, respectively, to obtain the second historical call link feature vector and the second historical call feature vector of the historical uncovered code; perform feature fusion on the second historical call link feature vector and the second historical call feature vector, to obtain the second historical call information feature vector of the historical uncovered code;
[0092] For the first historical call information feature vector of each historical coverage code: extract each first historical call information in the first historical call information feature vector, and assign a weight to each first historical call information;
[0093] For the second historical call information feature vector of each historical uncovered code: extract each second historical call information in the second historical call information feature vector, and assign a weight to each second historical call information;
[0094] Obtain a first weight assignment information set corresponding to each historical covered code, and a second weight assignment information set corresponding to each historical uncovered code;
[0095] An initial encoder is trained using a training set including a first historical call information feature vector of each historical covered code and a second historical call information feature vector of each historical uncovered code, and the initial encoder is adjusted based on the first weight assignment information set and the second weight assignment information set to obtain a preset encoder, wherein the input of the preset encoder is a call information feature vector, and the output is a weight coding set of feature weight coding of each call information in the call information feature vector.
[0096] In a possible implementation, the preset feature extraction model includes a preset compiler and a preset graph convolutional neural network. The preset feature extraction model is used to extract feature vectors of the target uncovered code and the full code group, respectively, to obtain a call link feature vector and a call feature vector of the target uncovered code, including:
[0097] Using a preset compiler to convert the target uncovered code into a first directed acyclic graph, and using a preset graph convolutional neural network to extract feature vectors from the first directed acyclic graph to obtain a call feature vector of the target uncovered code;
[0098] The preset compiler is used to convert the full code group into a second directed acyclic graph, and the preset graph convolutional neural network is used to extract feature vectors of the second directed acyclic graph to obtain the call link feature vector of the target uncovered code.
[0099] It should be noted that in actual application scenarios, due to the complex dependencies and function call relationships in the code, if the preset encoder is used directly for encoding, the accuracy and efficiency are low, and the preset encoder cannot directly recognize the code. Therefore, this application configures the preset feature extraction model including the preset compiler and the preset graph convolutional neural network, and uses the preset compiler to generate a directed acyclic graph of the corresponding code, thereby realizing the combing of complex dependencies, function call relationships and related parameters in the code, and then uses the preset graph convolutional neural network to extract feature vectors from the directed acyclic graph, and obtains the call link feature vector and call feature vector that can be recognized by the preset encoder, thereby improving the generation accuracy and efficiency of feature vectors.
[0100] In order to facilitate the understanding of the method for automatically generating test cases provided by the first aspect of the present application and any possible implementation thereof, a possible implementation of the present application is specifically described here:
[0101] like Figure 5 The figure is a flow chart of a method for automatically generating test cases provided in the present application.
[0102] Obtain the target uncovered code and the full code group of the target uncovered code, convert the target uncovered code into a first directed acyclic graph, convert the full code group into a second directed acyclic graph, extract the call feature vector from the first directed acyclic graph, and extract the call link feature vector from the second directed acyclic graph. Convolve and concatenate the call feature vector and the call link feature vector to obtain a call information feature vector. Input the call information feature vector into the preset Transformer encoder to obtain a weight coding set. Finally, input the weight coding set and the test case template into the preset decoder to obtain the test case of the target uncovered code.
[0103] It should be noted that in actual application scenarios, based on the automatic generation method of test cases provided in the first aspect of the present application, the existing precision testing system is improved and integrated to provide a fully automatic software testing system for automatically generating cases. The structural diagram of the fully automatic software testing system is as follows: Figure 6 The system shown includes: a pipeline of the system under test, a collection plug-in, a test data storage container (Pod) of the system under test, a business module, a collection module, a case generation module, a memory (NAS) and a database. Among them, the pipeline of the system under test, the test data storage container (Pod) of the system under test, the collection plug-in, the business module and the collection module are existing functional modules in the existing precision test system. The above-mentioned case generation module is a functional module for executing a method for automatically generating test cases provided in the first aspect of the present application.
[0104] The above-mentioned pipeline of the system under test is deployed in the test data storage container of the system under test, and is used to execute the test cases in the test data storage container of the system under test in sequence. The test data storage container of the system under test is used to store test data and test cases. The above-mentioned acquisition plug-in is used to extract pipeline information, source code and difference code from the pipeline of the system under test, and send the collected data to the above-mentioned business module. The above-mentioned acquisition module is used to extract test data from the test data storage container of the system under test, and store the executable file (Executable File, EXEC) generated based on the test data in the memory. The above-mentioned business module is used to generate a test coverage report based on the source code, difference code (stored in the form of class files) and the executable file in the memory, and send the test coverage report and source code to the memory. The above-mentioned case generation module is used to load the test coverage report from the memory, and generate test cases based on a method for automatically generating test cases provided in the first aspect of the present application, and send the test cases to the test data storage container of the system under test to trigger the pipeline of the system under test to execute the test cases. The above-mentioned database is used to back up the data received and received by the business module.
[0105] It should be noted that in actual application scenarios, the above Figure 6The fully automatic software testing system for automatically generating cases shown can be used to perform an automatic software testing method, which has realized automatic case generation, i.e., automatic software testing. The specific operation steps of the above automatic software testing method can be:
[0106] like Figure 7 As shown, it is a flow chart of an automatic software testing method, and the specific operation steps are as follows:
[0107] Step S701, start the test, and trigger step S702.
[0108] Step S702, lock the test data storage container of the system under test, control the pipeline of the system under test to sequentially execute each test case in the test data storage container of the system under test, and trigger step S703.
[0109] In a possible implementation, the above-mentioned locking of the test data storage container of the system under test is to prohibit adding test cases to the test data storage container of the system under test, so as to avoid omission. In this process, the test data storage container of the system under test can store test data normally.
[0110] Step S703, determine whether the pipeline of the system under test has completed the execution of all test cases. If yes, then trigger step S704, if not, then trigger step S703.
[0111] Step S704, controlling the acquisition module to generate a test coverage report, and triggering step S705.
[0112] Step S705, determine whether there is uncovered code in the test coverage report. If yes, step S706 is triggered, if no, step S708 is triggered.
[0113] Step S706: Control the case generation module to generate at least one test case based on the test coverage report, triggering step S707.
[0114] Step S707, unlocking the test data storage container of the system under test, and storing the test cases generated by the case generation module in the test data storage container of the system under test, and triggering step S702.
[0115] Step S708, end the test.
[0116] The second aspect of the present application provides a system for automatically generating test cases, such as Figure 8 As shown, the automatic generation system of the test case includes:
[0117] The first parameter extraction module 801 is used to obtain a test coverage report and target uncovered code, and extract a full code group of a code call path of the target uncovered code from the test coverage report;
[0118] The second parameter extraction module 802 is used to extract feature vectors from the target uncovered code and the full code group respectively by using a preset feature extraction model, and obtain a call link feature vector and a call feature vector of the target uncovered code, wherein the call link feature vector represents the full call parameter features associated with the call of the target uncovered code in the code call path, and the call feature vector represents the full parameter features associated with the target uncovered code being called; feature fusion is performed on the call link feature vector and the call feature vector to obtain a call information feature vector of the target uncovered code, and the call information feature vector represents the full call information associated with calling the target uncovered code;
[0119] An encoding module 803 is used to input the call information feature vector into a preset encoder so that the preset encoder outputs a weight encoding set including a feature weight encoding of each call information in the call information feature vector, wherein the feature weight encoding carries a weight representing the degree of association between the call information and the uncovered code of the call target;
[0120] The decoding module 804 is used to input the weight coding set and the test case template into a preset decoder to obtain the test case of the target uncovered code.
[0121] In a possible implementation, the encoding module 803 is configured to:
[0122] Input the call information feature vector into a preset encoder, which includes a module layer, a weight generation network and an output layer. The module is used to encode each call information in the call information feature vector to obtain the feature code corresponding to each call information; the weight generation network is used to generate the weight corresponding to the call information based on the feature code; the output layer is used to perform a product operation on the weight corresponding to the call information and the feature code, and output the feature weight code corresponding to the call information;
[0123] A weight coding set including feature weight coding of each call information output by a preset encoder is obtained.
[0124] In a possible implementation, the decoding module 804 is configured to:
[0125] The weight coding set and the test case template are input into a preset decoder, and the preset decoder is used to perform nonlinear transformation on the test case template and the weight coding set, and generate a test case including call information corresponding to each target feature weight coding in the weight coding set based on the transformation result, wherein the target feature weight coding is a feature weight coding with a weight not less than a preset threshold;
[0126] Get test cases for target uncovered code output by the preset decoder.
[0127] In one possible implementation, the above Figure 8 The automatic generation system of the test case shown also includes an encoder training module, which is set to:
[0128] Extracting multiple historical covered codes and a first historical full code group of historical code call paths of each historical covered code from multiple historical test coverage reports; extracting multiple historical uncovered codes and a second historical full code group of historical code call paths of each historical uncovered code from multiple historical test coverage reports;
[0129] For each historical coverage code: use a preset feature extraction model to extract feature vectors of the historical coverage code and the first historical full code group of the historical coverage code respectively, and obtain the first historical call link feature vector and the first historical call feature vector of the historical coverage code; perform feature fusion on the first historical call link feature vector and the first historical call feature vector to obtain the first historical call information feature vector of the historical coverage code;
[0130] For each historical uncovered code: use a preset feature extraction model to extract feature vectors for the historical uncovered code and the second historical full code group of the historical uncovered code, respectively, to obtain the second historical call link feature vector and the second historical call feature vector of the historical uncovered code; perform feature fusion on the second historical call link feature vector and the second historical call feature vector, to obtain the second historical call information feature vector of the historical uncovered code;
[0131] For the first historical call information feature vector of each historical coverage code: extract each first historical call information in the first historical call information feature vector, and assign a weight to each first historical call information;
[0132] For the second historical call information feature vector of each historical uncovered code: extract each second historical call information in the second historical call information feature vector, and assign a weight to each second historical call information;
[0133] Obtain a first weight assignment information set corresponding to each historical covered code, and a second weight assignment information set corresponding to each historical uncovered code;
[0134] An initial encoder is trained using a training set including a first historical call information feature vector of each historical covered code and a second historical call information feature vector of each historical uncovered code, and the initial encoder is adjusted based on the first weight assignment information set and the second weight assignment information set to obtain a preset encoder, wherein the input of the preset encoder is a call information feature vector, and the output is a weight coding set of feature weight coding of each call information in the call information feature vector.
[0135] In a possible implementation, the second parameter extraction module 802 is set to:
[0136] The preset feature extraction model includes a preset compiler and a preset graph convolutional neural network. The second parameter extraction module uses the preset compiler to convert the target uncovered code into a first directed acyclic graph, and uses the preset graph convolutional neural network to extract a feature vector of the first directed acyclic graph to obtain a call feature vector of the target uncovered code.
[0137] The second parameter extraction module uses a preset compiler to convert the full code group into a second directed acyclic graph, and uses a preset graph convolutional neural network to extract feature vectors from the second directed acyclic graph to obtain the call link feature vector of the target uncovered code.
[0138] A third aspect of the present application provides a computer program product, including computer-readable instructions. When the computer-readable instructions are executed on an electronic device, the electronic device implements the method for automatically generating test cases of the above-mentioned first aspect or any implementation method of the first aspect.
[0139] A fourth aspect of the present application provides an electronic device, comprising at least one processor and a memory connected to the processor, wherein:
[0140] The memory is used to store computer programs;
[0141] The processor is used to execute a computer program so that the electronic device can implement the method for automatically generating test cases of the above-mentioned first aspect or any implementation manner of the first aspect.
[0142] The fifth aspect of the present application provides a computer storage medium, which carries one or more computer programs. When the one or more computer programs are executed by an electronic device, the electronic device can automatically generate test cases according to the first aspect or any implementation method of the first aspect.
[0143] A structural schematic diagram of an electronic device provided in the fourth aspect of the present application is as follows Fig. 9 The electronic devices in the embodiments of the present application may include but are not limited to fixed terminals such as mobile phones, notebook computers, PDAs (personal digital assistants), PADs (tablet computers), desktop computers, and the like. Fig. 9 The electronic device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0144] like Fig. 9As shown, the electronic device may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 901, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 902 or a program loaded from a storage device 908 into a random access memory (RAM) 903. When the electronic device is powered on, various programs and data required for the operation of the electronic device are also stored in the RAM 903. The processing device 901, the ROM 902, and the RAM 903 are connected to each other via a bus 904. An input / output (I / O) interface 905 is also connected to the bus 904.
[0145] Typically, the following devices may be connected to the I / O interface 905: an input device 906 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 907 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 908 including, for example, a memory card, a hard disk, etc.; and a communication device 909. The communication device 909 may allow the electronic device to communicate with other devices wirelessly or by wire to exchange data. Although Fig. 9 An electronic device having various devices is shown, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.
[0146] It should also be noted that the device embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed over multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. In addition, in the drawings of the device embodiments provided by the present application, the connection relationship between the modules indicates that there is a communication connection between them, which may be specifically implemented as one or more communication buses or signal lines.
[0147] Through the description of the above implementation mode, the technicians in the field can clearly understand that the present application can be implemented by means of software plus necessary general hardware, and of course, it can also be implemented by special hardware including special integrated circuits, special CPUs, special memories, special components, etc. In general, all functions completed by computer programs can be easily implemented by corresponding hardware, and the specific hardware structure used to implement the same function can also be various, such as analog circuits, digital circuits or special circuits. However, for the present application, software program implementation is a better implementation mode in more cases. Based on such an understanding, the technical solution of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a readable storage medium, such as a computer floppy disk, a U disk, a mobile hard disk, a ROM, a RAM, a disk or an optical disk, etc., including a number of instructions to enable a computer device (which can be a personal computer, a training device, or a network device, etc.) to execute the methods described in each embodiment of the present application.
[0148] In the above embodiments, all or part of the embodiments may be implemented by software, hardware, firmware or any combination thereof. When implemented by software, all or part of the embodiments may be implemented in the form of a computer program product.
[0149] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from a website site, a computer, a training device, or a data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, training device, or data center. The computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a training device, a data center, etc. that includes one or more available media integrations. The available medium may be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive (SSD)), etc.
Claims
1. A method for automatically generating test cases, characterized in that: include: Obtain a test coverage report and target uncovered code, and extract a full code group of a code call path of the target uncovered code from the test coverage report; A preset feature extraction model is used to extract feature vectors of the target uncovered code and the full code group respectively, to obtain a call link feature vector and a call feature vector of the target uncovered code, wherein the call link feature vector represents the full call parameter features associated with the call of the target uncovered code in the code call path, and the call feature vector represents the full parameter features associated with the call of the target uncovered code; Performing feature fusion on the call link feature vector and the call feature vector to obtain a call information feature vector of the target uncovered code, wherein the call information feature vector represents a full amount of call information associated with calling the target uncovered code; Inputting the call information feature vector into a preset encoder so that the preset encoder outputs a weight coding set including a feature weight coding of each of the call information in the call information feature vector, wherein the feature weight coding carries a weight representing a degree of association between the call information and the call of the target uncovered code; The weight coding set and the test case template are input into a preset decoder to obtain the test case of the target uncovered code.
2. The method for automatically generating test cases according to claim 1, characterized in that: The step of inputting the call information feature vector into a preset encoder so that the preset encoder outputs a weight coding set including feature weight coding of each call information in the call information feature vector, comprises: The call information feature vector is input into the preset encoder, and the preset encoder includes a module layer, a weight generation network and an output layer, wherein the module is used to perform an encoding operation on each of the call information in the call information feature vector to obtain a feature code corresponding to each of the call information; the weight generation network is used to generate the weight corresponding to the call information based on the feature code; the output layer is used to perform a product operation on the weight corresponding to the call information and the feature code, and output the feature weight code corresponding to the call information; The weight coding set of the feature weight coding of each of the call information output by the preset encoder is obtained.
3. The method for automatically generating test cases according to claim 2, characterized in that: The step of inputting the weight coding set and the test case template into a preset decoder to obtain the test case of the target uncovered code comprises: Input the weight coding set and the test case template into a preset decoder, the preset decoder is used to perform nonlinear transformation on the test case template and the weight coding set, and generate the test case including the call information corresponding to each target feature weight coding in the weight coding set based on the transformation result, wherein the target feature weight coding is the feature weight coding whose weight is not less than a preset threshold; The test case of the target uncovered code output by the preset decoder is obtained.
4. The method for automatically generating test cases according to claim 1, characterized in that: The training process of the preset encoder includes: Extracting multiple historical covered codes and a first historical full code group of historical code call paths of each of the historical covered codes from multiple historical test coverage reports; extracting multiple historical uncovered codes and a second historical full code group of historical code call paths of each of the historical uncovered codes from the multiple historical test coverage reports; For each of the historical coverage codes: using a preset feature extraction model, respectively extract feature vectors for the historical coverage code and the first historical full code group of the historical coverage code to obtain a first historical call link feature vector and a first historical call feature vector of the historical coverage code; perform feature fusion on the first historical call link feature vector and the first historical call feature vector to obtain a first historical call information feature vector of the historical coverage code; For each of the historical uncovered codes: using a preset feature extraction model, respectively extract feature vectors for the historical uncovered code and the second historical full code group of the historical uncovered code to obtain a second historical call link feature vector and a second historical call feature vector for the historical uncovered code; perform feature fusion on the second historical call link feature vector and the second historical call feature vector to obtain a second historical call information feature vector for the historical uncovered code; For the first historical call information feature vector of each of the historical coverage codes: extract each piece of first historical call information in the first historical call information feature vector, and assign a weight to each piece of the first historical call information; For each of the second historical call information feature vectors of the historical uncovered codes: extracting each of the second historical call information in the second historical call information feature vector, and assigning a weight to each of the second historical call information; Obtaining a first weight assignment information set corresponding to each of the historical covered codes and a second weight assignment information set corresponding to each of the historical uncovered codes; The initial encoder is trained using a training set including the first historical call information feature vector of each of the historical covered codes and the second historical call information feature vector of each of the historical uncovered codes, and the initial encoder is adjusted based on the first weight assignment information set and the second weight assignment information set to obtain the preset encoder, wherein the input of the preset encoder is the call information feature vector, and the output is a weight coding set of the feature weight coding of each call information in the call information feature vector.
5. The method for automatically generating test cases according to claim 1, characterized in that: The preset feature extraction model includes a preset compiler and a preset graph convolutional neural network. The preset feature extraction model is used to extract feature vectors from the target uncovered code and the full code group respectively to obtain a call link feature vector and a call feature vector of the target uncovered code, including: Using the preset compiler to convert the target uncovered code into a first directed acyclic graph, and using the preset graph convolutional neural network to extract feature vectors from the first directed acyclic graph to obtain the call feature vector of the target uncovered code; The preset compiler is used to convert the full code group into a second directed acyclic graph, and the preset graph convolutional neural network is used to extract feature vectors from the second directed acyclic graph to obtain the call link feature vector of the target uncovered code.
6. A system for automatically generating test cases, characterized in that: include: A first parameter extraction module is used to obtain a test coverage report and target uncovered code, and extract a full code group of a code call path of the target uncovered code from the test coverage report; A second parameter extraction module is used to extract feature vectors from the target uncovered code and the full code group respectively by using a preset feature extraction model to obtain a call link feature vector and a call feature vector of the target uncovered code, wherein the call link feature vector represents the full call parameter features associated with the call of the target uncovered code in the code call path, and the call feature vector represents the full parameter features associated with the call of the target uncovered code in the code call path; Performing feature fusion on the call link feature vector and the call feature vector to obtain a call information feature vector of the target uncovered code, wherein the call information feature vector represents a full amount of call information associated with calling the target uncovered code; An encoding module, used for inputting the call information feature vector into a preset encoder, so that the preset encoder outputs a weight encoding set including a feature weight encoding of each of the call information in the call information feature vector, wherein the feature weight encoding carries a weight representing a degree of association between the call information and the call of the target uncovered code; A decoding module is used to input the weight coding set and the test case template into a preset decoder to obtain the test case of the target uncovered code.
7. The method for automatically generating test cases according to claim 6, characterized in that: The encoding module is configured as follows: Inputting the call information feature vector into the preset encoder, the preset encoder includes a module layer, a weight generation network and an output layer, the module is used to perform an encoding operation on each of the call information in the call information feature vector to obtain a feature code corresponding to each of the call information; The weight generation network is used to generate the weight corresponding to the call information based on the feature code; the output layer is used to perform a product operation on the weight corresponding to the call information and the feature code, and output the feature weight code corresponding to the call information; The weight coding set of the feature weight coding of each of the call information output by the preset encoder is obtained.
8. A computer program product, characterized in that The method comprises computer-readable instructions, which, when executed on an electronic device, enable the electronic device to implement the method for automatically generating test cases as claimed in any one of claims 1 to 5.
9. An electronic device, characterized in that: The method comprises at least one processor and a memory connected to the processor, wherein: The memory is used to store computer programs; The processor is used to execute the computer program so that the electronic device can implement the automatic generation method of test cases as described in any one of claims 1 to 5.
10. A computer storage medium, characterized in that: The storage medium carries one or more computer programs, and when the one or more computer programs are executed by an electronic device, the electronic device can implement the automatic generation method of test cases as described in any one of claims 1 to 5.
Citation Information
Cited By
Test case generation method and device, electronic equipment and readable storage medium
CN120705056A