Knowledge graph-based test case generation method and device, equipment and medium
By building a knowledge graph of interface test cases, combining low-order and multi-hop neighborhood information, we generate embedded vectors and automatically generate interface test cases, solving the problems of inefficiency and inaccurate recommendations in traditional manual writing and automatic recommendation methods, and achieving more efficient and accurate interface test cases generation.
Patent Information
- Application Number
- CN202411731376.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-28
- Publication Date
- 2025-05-06
AI Technical Summary
The traditional manual writing of interface test cases is inefficient and prone to errors. Automatic recommendation generation of interface test cases also faces problems such as unclear interface definition, incomplete parameter range, and ignoring multi-hop connectivity paths and introducing noise in the knowledge graph, resulting in inaccurate and incomplete recommendation results.
By building a knowledge graph for interface test cases, combining low-order neighbors and multi-hop neighbors, generating embedding vectors for aggregating neighboring entities, and adjusting the embedding vectors using the cross entropy loss function to generate prediction models to automatically generate interface test cases.
It realizes automated recommendation of interface test cases, improves test coverage and accuracy, reduces noise, and can extract and recommend test cases more accurately.
Smart Images

Figure CN119938508A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a test case generation method, device, equipment and medium based on a knowledge graph. Background Art
[0002] With the rapid development of software development, interface testing plays an increasingly important role in software quality assurance. The writing of interface test cases is one of the key steps to ensure the correctness and stability of software interfaces. However, the traditional method of manually writing interface test cases is inefficient and prone to errors. For example, the traditional manual writing of interface test cases requires testers to have an in-depth understanding of interface functions and parameters, and write detailed test steps and data. This process is cumbersome and prone to omissions or errors.
[0003] In addition, in the traditional manual writing of interface test cases, testers can only write part of the test cases based on their own experience and understanding, and cannot fully cover all possible situations. In order to solve the defects of the method of manually writing interface test cases, a method that can automatically recommend and generate interface test cases is currently improved. This method can improve the test coverage, avoid errors and human interference caused by manually generating test cases, and ensure the accuracy and consistency of test cases.
[0004] However, there are also some challenges in automatically recommending and generating interface test cases. For example, the interface definition and parameter range are not clear or the parameter range is not comprehensive, which may result in the automatically generated test cases not covering all situations. Or, for example, the current automatic recommendation method based on knowledge graph only focuses on the direct connection between entities in the knowledge graph, ignores other nodes with related relationships, and lacks multi-hop connected path constraints, which makes the recommendation results inaccurate and incomplete; if the neighborhood of entity information in the knowledge graph is expanded, it will inevitably introduce noise, which will have a certain degree of impact on the accuracy of the recommendation. Summary of the invention
[0005] In view of this, the present invention provides a test case generation method, device, equipment and medium based on knowledge graph to solve the above problems. This recommendation method uses knowledge graph to propagate and extract potential features of interface test cases. When extracting neighborhood information, it combines low-order neighborhood and multi-hop neighborhood, so as to ensure the divergence of recommendation effect and extract neighborhood information more accurately while reducing noise.
[0006] In a first aspect, the present invention provides a method for generating test cases based on a knowledge graph, the method comprising:
[0007] Constructing a knowledge graph corresponding to the interface test case, wherein the knowledge graph is a heterogeneous graph with each interface test case as an entity, and the edge of each interface test case represents the mutual connection between multiple entities;
[0008] Using a preset relationship scoring function, the knowledge graph is converted into a low-order neighborhood matrix and a high-order neighborhood matrix;
[0009] Fusing the low-order neighborhood matrix and the high-order neighborhood matrix according to preset weights to obtain an embedding vector for aggregating adjacent entities;
[0010] Using a cross entropy loss function to adjust and aggregate the embedding vectors to generate a prediction model;
[0011] The interface request information is input into the prediction model, an interface test case is generated after model prediction, and the interface test case is fed back.
[0012] The method provided in this embodiment uses the knowledge graph to propagate and extract the potential features of the interface test cases. When extracting neighborhood information, by combining the low-order neighborhood and the multi-hop neighborhood, it can not only ensure the divergence of the recommendation effect, but also extract the neighborhood information more accurately while reducing noise.
[0013] At the same time, by introducing edge weight regularization, additional supervision signals are provided for learning edge scoring functions, which can help the recommendation system gain better generalization capabilities. This method can more effectively cover complex business logic and special scenarios in interface testing.
[0014] In combination with the first aspect, in a possible implementation, before constructing the knowledge graph corresponding to the interface test case, it also includes: defining an interface of a data collector, wherein the interface of the data collector defines the method and specification of data collection; and using the interface of the data collector to collect input and output parameters and test case information.
[0015] The constructing of the knowledge graph corresponding to the interface test case includes: constructing the knowledge graph corresponding to the interface test case according to the input and output parameters and the test case information.
[0016] In combination with the first aspect, in another possible implementation, the knowledge graph corresponding to the interface test case is constructed based on the input and output parameters and the test case information, including: cleaning and data preprocessing the input and output parameters and the test case information; and constructing the knowledge graph based on the input and output parameters and test case information after data preprocessing.
[0017] In combination with the first aspect, in yet another possible implementation, the input and output parameters include at least one interface.
[0018] The method of converting the knowledge graph into a specific adjacency matrix by using a preset relationship scoring function includes:
[0019] Determine the relationship between entities according to the knowledge graph, where the entities are the test cases constituting the knowledge graph;
[0020] Calculating the preset relationship scoring function according to the relationship and the at least one interface;
[0021] The preset relationship scoring function is used to convert the knowledge graph into the low-order neighborhood matrix and the high-order neighborhood matrix.
[0022] In combination with the first aspect, in another possible implementation, the using the preset relationship scoring function to convert the knowledge graph into the low-order neighborhood matrix and the high-order neighborhood matrix includes: obtaining the order, the central entity, the entity to be sampled, and the relationship between the central entity and the entity to be sampled in the knowledge graph;
[0023] According to the preset relationship scoring function, the order, the central entity, the entity to be sampled, and the relationship between the central entity and the entity to be sampled in the knowledge graph, the low-order sampling threshold and the high-order sampling threshold are calculated respectively to generate the low-order neighborhood matrix and the high-order neighborhood matrix.
[0024] In combination with the first aspect, in another possible implementation, the low-order neighborhood matrix and the high-order neighborhood matrix are generated according to the preset relationship scoring function, the order, the central entity, the entity to be sampled, and the relationship between the central entity and the entity to be sampled in the knowledge graph, respectively, through a low-order sampling threshold and a high-order sampling threshold calculation, including:
[0025] The preset relationship scoring function, the order, the central entity, the entity to be sampled, and the relationship are subjected to a low-order sampling threshold algorithm to generate a low-order neighborhood representation vector; and subjected to a high-order sampling threshold algorithm to generate a high-order neighborhood representation vector;
[0026] Wherein, the low-order sampling threshold algorithm is expressed as:
[0027]
[0028] The high-order sampling threshold algorithm is expressed as:
[0029]
[0030] Among them, s u (r v,e ) is the preset relationship scoring function, v is the central entity, e is the entity to be sampled, r v,eis the relationship between the central entity v and the entity to be sampled e in the knowledge graph, k is the order, α is the ratio of the sampling order of the low-order neighborhood matrix to the high-order neighborhood matrix, and Af u is the low-order neighborhood representation vector, corresponding to the low-order neighborhood matrix, As u is a high-order neighborhood representation vector, corresponding to a high-order neighborhood matrix.
[0031] In combination with the first aspect, in another possible implementation, fusing the low-order neighborhood matrix and the high-order neighborhood matrix according to a preset weight to obtain an embedding vector for aggregating adjacent entities includes:
[0032] The preset weight is set according to the scale factor, and the representation vector of the aggregated adjacent entities is obtained by calculating according to the preset weight according to the weight relationship formula; the weight relationship formula is:
[0033] A u =βAf u +(1-β)As u
[0034] Among them, β is the proportional factor, and its value range is β∈[0,1], A u is the representation vector of aggregated adjacent entities;
[0035] Use multiple feed-forward layers to update the representation vector A by aggregating the representations of neighboring entities u , and obtain the embedding vector, where the expression of the embedding vector is:
[0036]
[0037] Among them, H l is the entity hidden representation matrix of the lth layer, H l+1 is the entity embedding vector of the l+1th layer, D u is a diagonal matrix, For standardization A u , W l is a layer-specific trainable weight matrix, σ is a nonlinear activation function, L is the number of layers, and l ranges from 0 to L-1.
[0038] In a second aspect, the present invention provides a test case generation device based on a knowledge graph, the device comprising:
[0039] A construction module is used to construct a knowledge graph corresponding to the interface test case, wherein the knowledge graph is a heterogeneous graph with each interface test case as an entity, and the edge of each interface test case represents the mutual connection between multiple entities;
[0040] A processing module, used to convert the knowledge graph into a low-order neighborhood matrix and a high-order neighborhood matrix using a preset relationship scoring function;
[0041] A fusion module, used to fuse the low-order neighborhood matrix and the high-order neighborhood matrix according to a preset weight to obtain an embedding vector for aggregating adjacent entities;
[0042] The generation module is used to adjust and aggregate the embedded vectors using the cross entropy loss function to generate a prediction model;
[0043] The prediction module is used to input the interface request information into the prediction model, generate interface test cases after model prediction, and feed back the interface test cases.
[0044] In a third aspect, the present invention provides a computer device, comprising: a memory and a processor, the memory and the processor are communicatively connected to each other, computer instructions are stored in the memory, and the processor executes the test case generation method based on the knowledge graph of the above-mentioned first aspect or any corresponding embodiment thereof by executing the computer instructions.
[0045] In a fourth aspect, the present invention provides a computer-readable storage medium having computer instructions stored thereon, the computer instructions being used to enable a computer to execute the knowledge graph-based test case generation method of the above-mentioned first aspect or any corresponding embodiment thereof.
[0046] In addition, the present invention provides a computer program product, including computer instructions, which are used to enable a computer to execute the knowledge graph-based test case generation method of the above-mentioned first aspect or any corresponding embodiment.
[0047] The test case generation method, device, equipment and medium based on the knowledge graph provided by the embodiments of the present invention convert the knowledge graph into a low-order neighborhood matrix and a high-order neighborhood matrix, and fuse the two neighborhood matrices to generate an embedding vector for aggregating adjacent entities. Finally, the embedding vector is adjusted and aggregated using the cross entropy loss function to generate a prediction model. The prediction model can automatically generate interface test cases, realize automatic recommendation of interface test cases, help testers select suitable test cases more quickly, and improve testing efficiency.
[0048] In addition, the method provided in this embodiment comprehensively and accurately obtains the relationship between entities by integrating the dual neighborhood of the knowledge graph, ensures the divergence of the recommendation effect, and solves the problem that the test cases cannot be fully covered. At the same time, it can also reduce noise and recommend test cases more accurately, thereby improving the coverage of test cases. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0050] Figure 1 It is a flowchart of a method for generating test cases based on a knowledge graph according to an embodiment of the present invention;
[0051] Figure 2 is a flowchart of another test case generation method based on knowledge graph according to an embodiment of the present invention;
[0052] Figure 3 is a schematic diagram of another dual neighborhood according to an embodiment of the present invention;
[0053] Figure 4 is a schematic diagram of a test case generation method based on a knowledge graph according to an embodiment of the present invention;
[0054] Figure 5 This is a structural block diagram of a test case recommendation method based on a knowledge graph according to an embodiment of the present invention;
[0055] Figure 6 is a structural block diagram of a test case generation device based on a knowledge graph according to an embodiment of the present invention;
[0056] Figure 7 It is a schematic diagram of the hardware structure of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0057] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0058] In the description of the present invention, it should be noted that, unless otherwise clearly specified and limited, the terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be indirectly connected through an intermediate medium, or it can be the internal communication of two components. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0059] Furthermore, the terms “first” and “second” are used for descriptive purposes only and should not be understood as indicating or implying relative importance.
[0060] First, the technical scenarios and related technical terms of the technical solution of the present invention are introduced.
[0061] The technical solution of the present invention is applied to the recommendation system. The recommendation system is theoretically an information filtering system. It predicts the user's preference for an item through some user attributes, such as habits, preferences, historical interaction records, personalized needs, and the characteristics and audience groups of the item, and helps the user select one or more items that suit him or her, so that the user can quickly filter out items that are not of interest, thereby improving user satisfaction. The significance of the recommendation system is that it can provide users with the most appropriate choices or recommendations without requiring users to explicitly input what they want, like a search engine.
[0062] At present, the knowledge graph (KG) is introduced as auxiliary information to improve the performance of the recommendation system. The knowledge graph is a structured knowledge base that represents various relationships as attributes of items. If the items have common attributes, they are connected, which is very effective in representing the correlation between items.
[0063] The purpose of knowledge graph embedding is to preserve structural information, i.e., the relationships between entities, and represent it in some vector space to facilitate the representation of information. The main work of knowledge graph embedding is to generate continuous vector representations of entities and relationships, and apply relational reasoning to knowledge graph embedding.
[0064] At present, recommendation methods for knowledge graphs often only focus on the direct connections between entities in the knowledge graph, without using multiple connected paths, which limits the divergence of recommendation performance. At the same time, if the neighborhood of entity information in the knowledge graph is expanded, noise will inevitably be introduced, which will have a certain degree of impact on the accuracy of the recommendation.
[0065] In view of the above problems, an embodiment of the present invention proposes an interface test case generation method based on knowledge graph dual neighborhood, or also called interface test case recommendation method. This method uses knowledge graph to propagate and extract potential features of interface test cases. When extracting neighborhood information, by combining low-order neighborhood and multi-hop neighborhood, it can not only ensure the divergence of recommendation effect, but also extract neighborhood information more accurately while reducing noise.
[0066] At the same time, by introducing edge weight regularization, additional supervision signals are provided for learning edge scoring functions, which can help the recommendation system gain better generalization capabilities. This method can more effectively cover complex business logic and special scenarios in interface testing.
[0067] The technical features involved in the different embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other.
[0068] An embodiment of the present invention provides an embodiment of a test case generation method / recommendation method based on a knowledge graph. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in an order different from that shown here.
[0069] In this embodiment, a test case generation method based on knowledge graph is provided, which can be used for the above-mentioned server or terminal device, such as PC, tablet computer, etc. Figure 1 is a flowchart of a method for generating test cases based on a knowledge graph according to an embodiment of the present invention. Figure 1 As shown, the process includes:
[0070] Step S101, construct a knowledge graph corresponding to the interface test case.
[0071] Among them, the knowledge graph is a heterogeneous graph with each interface test case as an entity, and the edges of each interface test case represent the mutual connection between multiple entities.
[0072] This step is used to construct the collected data, such as input and output parameters and test case information, into a knowledge graph related to the interface test case. Optionally, the knowledge graph is represented by the letter "G".
[0073] Before this step 101, it also includes: cleaning and data preprocessing of input and output parameters and test case information; removing redundant data or erroneous data, and then constructing a knowledge graph based on the input and output parameters and test case information after data preprocessing.
[0074] It should be understood that the above-mentioned cleaning and data preprocessing process includes but is not limited to: deduplication, correction or deletion of data that do not conform to preset rules, such as input parameters that may contain non-existent interface information. In addition, it also includes unified formatting of data / parameters, such as mainly converting interface request and response data into a unified data structure for subsequent analysis and modeling.
[0075] In addition, a knowledge graph model is constructed based on the collected data. In the modeling process, it is necessary to define the schema of entities, attributes, and relationships, and map the data to the corresponding schema. This step takes the interface test case as an entity, the interface request and response as an attribute, and the usage relationship between the interface and the test case as a relationship, and uses graph database technology to construct the corresponding knowledge graph.
[0076] Step S102, using a preset relationship scoring function, converts the knowledge graph into a low-order neighborhood matrix and a high-order neighborhood matrix.
[0077] The main purpose of this step is to obtain the target test cases corresponding to the interface test requirements based on the pre-established knowledge graph. In addition, the knowledge graph is converted into a dual neighborhood matrix, i.e., a low-order neighborhood matrix and a high-order neighborhood matrix, through a preset relationship scoring function.
[0078] Among them, high-order neighborhood refers to the set of other entities that an entity can reach through multiple relationship jumps in the knowledge graph. Specifically, high-order neighborhood includes not only first-order neighbors directly connected to the entity (that is, entities directly connected through one edge), but also neighbor entities that can be reached farther away through multiple edges (that is, multiple hops). Low-order neighborhood usually refers to neighbor entities directly connected to the entity, that is, first-order neighbors. These entities are directly connected to the central entity only through one edge.
[0079] Step S103: The low-order neighborhood matrix and the high-order neighborhood matrix are fused according to preset weights to obtain an embedding vector for aggregating adjacent entities.
[0080] In this embodiment, the low-order neighborhood matrix and the high-order neighborhood matrix are fused according to the preset weights to obtain a dual neighborhood matrix, such as Figure 3 As shown, an embedding vector for aggregating adjacent entities is obtained, and the embedding vector is used to generate interface test cases based on the embedding method.
[0081] Step S104, using the cross entropy loss function to adjust and aggregate the embedded vectors to generate a prediction model.
[0082] Step S105, input the interface request information into the prediction model, generate interface test cases after model prediction, and feed back the interface test cases.
[0083] After the prediction module is generated in the above step S104, the interface request information is input into the prediction model, and after prediction by the model, an interface test case can be automatically generated.
[0084] For example, assume that the interface request information includes API description information, such as interface address: API / books; request method: GET, parameters: ID library unique identifier and book title. The prediction goal or test goal is to verify whether the API / books interface can correctly handle different request parameters and return the correct response. The response includes: returning a list of book information when successful, with a status code of 200. Returning error information when an error occurs, with a status code of 400 or 500.
[0085] After step S105, the output test case is as follows:
[0086] -Test case 1: Get all books.
[0087] Input: No parameters;
[0088] Expected Output: Returns a list of all books with a status code of 200.
[0089] -Test case 2: Get a specific book by ID.
[0090] Input: ID = 123;
[0091] Expected output: Returns the book information with ID 123 and status code 200.
[0092] -Test case 3: Searching for books by title.
[0093] Input: title = java;
[0094] Expected Output: Returns a list of books whose titles contain "java" with a status code of 200.
[0095] - Test case 4: Invalid ID.
[0096] Input: ID = abc;
[0097] Expected output: Returns error information with status code 400.
[0098] The method provided in this embodiment uses the knowledge graph to propagate and extract the potential features of the interface test cases. When extracting neighborhood information, by combining the low-order neighborhood and the multi-hop neighborhood, it can not only ensure the divergence of the recommendation effect, but also extract the neighborhood information more accurately while reducing noise.
[0099] At the same time, by introducing edge weight regularization, additional supervision signals are provided for learning edge scoring functions, which can help the recommendation system gain better generalization capabilities. This method can more effectively cover complex business logic and special scenarios in interface testing.
[0100] The method provided by the embodiment of the present invention is described in detail below with reference to the formula.
[0101] In this embodiment, if Figure 2 As shown, before the above step S101, constructing the knowledge graph corresponding to the interface test case, it also includes:
[0102] Step S100 - 1 , defining the interface of the data collector, where the interface of the data collector defines the method and specification of data collection.
[0103] Specifically, key data is extracted from the interface test, such as the key input including: input parameters, output parameters and interface use case information.
[0104] Step S100-2: collect input and output parameters and test case information using the interface of the data collector. Through the definition of the interface, different types of data collectors can be implemented, and collectors can be flexibly replaced and expanded.
[0105] Step S101 specifically includes:
[0106] Step S101-1, construct a knowledge graph corresponding to the interface test case based on input and output parameters and test case information.
[0107] The data collector may be an annotation-based collector, which identifies the parameters to be collected by adding annotations in the interface test case.
[0108] For the collection of interface test case information, a collector based on code analysis can be used to extract key information of the test case by statically analyzing the code of the interface test case.
[0109] Then, provide data storage and management functions. The data collected by the data acquisition module needs to be stored and managed for subsequent analysis and use. The data collector uses a file system to store data and provides a query interface based on the file path.
[0110] In a specific implementation, the input and output parameters include at least one interface. The step S102, using a preset relationship scoring function to convert the knowledge graph into a specific adjacency matrix, specifically includes:
[0111] First, the relationship between each entity is determined according to the knowledge graph, where the entity is each test case that constitutes the knowledge graph; then, a preset relationship scoring function is calculated according to the relationship and at least one interface; finally, the knowledge graph is converted into a low-order neighborhood matrix (such as Afu) and a high-order neighborhood matrix (such as ASu) using the preset relationship scoring function.
[0112] Further, see Figure 4 As shown, the method provided in this embodiment is based on a knowledge graph generation algorithm that integrates dual neighborhoods. First, the knowledge graph determines the sampling domain according to the scoring function, generates the corresponding dual neighborhood according to the sampling domain, fuses the dual neighborhood, and converts it into embedding vector 1, which is then aggregated with embedding vector 2, and finally predicted.
[0113] In the generation method based on knowledge graph, some parameters are defined first, for example: U = {u1,u2,...,u M} represents a set of m test case interfaces, u1, u2, ..., u m Represents each interface. V={v1,v2,...,v N} represents a set of n test cases, where v1, v2, ..., v n Represents different test cases. In addition, the interaction matrix Y∈R is defined M×N is defined by the implicit feedback of the interface. In this matrix, y uv =1 indicates that there is interaction between interface u and test case v. If there is no interaction or relationship between the two, then y uv =0.
[0114] In addition, there is a knowledge graph G = (ε, R), in which ε and R represent a set of entities and a set of relations. Given Y and G, the task is to predict whether u is relevant to the uninteracted test case v. Thus, a prediction function y is learned uv =F(u,v|θ(u,G)), θ is the model parameter of F.
[0115] In the above step S102, the knowledge graph G is converted into a personalized weighted graph, and the preset relationship scoring function s is used. u (r) is expressed as:
[0116] s u (r) = g(u,r)(1)
[0117] Among them, the preset relationship scoring function s u (r) represents the importance of u to relation r, where u and r are the eigenvectors of interfaces u and r respectively, and g is a differentiable function similar to the inner product. Given u, the preset relation scoring function s u(r), the knowledge graph G can be converted into a specific adjacency matrix.
[0118] In the above step S102, the knowledge graph is converted into a low-order neighborhood matrix (Afu) and a high-order neighborhood matrix (ASu) using a preset relationship scoring function (Su(r)), specifically including:
[0119] Obtain the order, central entity, entity to be sampled, and the relationship between the central entity and the entity to be sampled in the knowledge graph; according to the preset relationship scoring function, the order, central entity, entity to be sampled, the relationship between the central entity and the entity to be sampled in the knowledge graph, respectively calculate through the low-order sampling threshold and the high-order sampling threshold to generate a low-order neighborhood matrix and a high-order neighborhood matrix.
[0120] Furthermore, the generation process is as follows:
[0121] The preset relationship scoring function, order, central entity, entity to be sampled, and relationship are subjected to a low-order sampling threshold algorithm to generate a low-order neighborhood representation vector; and a high-order sampling threshold algorithm to generate a high-order neighborhood representation vector;
[0122] The low-order sampling threshold algorithm is expressed by the following equation (2):
[0123]
[0124] The high-order sampling threshold algorithm is expressed by the following relationship (3):
[0125]
[0126] Among them, s u (r v,e ) is the preset relationship scoring function, v is the central entity, e is the entity to be sampled, r v,e is the relationship between the central entity v and the entity to be sampled e in the knowledge graph, k is the order, α is the ratio of the sampling order of the low-order neighborhood matrix to the high-order neighborhood matrix, or also called the ratio of the two-neighborhood sampling order. The sampling order ratio can be pre-set, such as α = 2, 4, 6, 8, etc., and α is also the ratio of the number of sampled neighbors. Af u is the low-order neighborhood representation vector, corresponding to the low-order neighborhood matrix, As u is a high-order neighborhood representation vector, corresponding to a high-order neighborhood matrix.
[0127] Optionally, if there is no dependency relationship between the above central entity v and the entity to be sampled e, then
[0128] In this embodiment, the above step S103, according to the preset weights, fuses the low-order neighborhood matrix and the high-order neighborhood matrix to obtain an embedding vector for aggregating adjacent entities, specifically including:
[0129] The preset weight is set according to the scale factor, and the representation vector of the aggregated adjacent entities is obtained by calculating according to the weight relationship formula based on the preset weight. The weight relationship formula (4) is expressed as:
[0130] A u =βAf u +(1-β)As u (4)
[0131] Among them, β is the scaling factor, and the value range is β∈[0,1]. As the scaling factor of the two neighborhoods, A u is the representation vector of aggregated adjacent entities.
[0132] like Figure 3 As shown, the above two neighborhood fusions, that is, the low-order neighborhood matrix and the high-order neighborhood matrix are fused to generate a dual neighborhood matrix. For the low-order neighborhood, the central node is the central entity v, and the surrounding nodes numbered 1 to 4 are the entities to be sampled e. The lines between them represent the relationship r, h = 1 represents the first order, and h = 2 represents the second order. In the high-order neighborhood, the central node is associated with two neighboring nodes, namely nodes 1 and 2. Nodes 1 and 2 are also associated with two neighboring nodes 1 to 2 respectively. After the two-neighbor fusion, a dual neighborhood matrix is obtained.
[0133] make Represents the original features of the entity. Where d0 represents the dimension of the original entity features. Then, multiple feed-forward layers are used to update the entity representation matrix by aggregating the representations of neighboring entities.
[0134] Specifically, the above uses multiple feed-forward layers to update the representation vector A by aggregating the representations of adjacent entities. u , we get the embedding vector, and the layered forward propagation can be expressed (or the representation of the above embedding vector) as shown in the following relation (5):
[0135]
[0136] Among them, H l is the entity hidden representation matrix of the lth layer, and ensures that the entity representation matrix H l Stable, H l+1 is the entity embedding vector of the l+1th layer, and H0=E,D u is a diagonal matrix, For standardization A u , W lis a layer-specific trainable weight matrix, σ is a nonlinear activation function, L is the number of layers, and l ranges from 0 to L-1. is a layer-specific trainable weight matrix.
[0137] In the above step S104, the embedding vector H is quantified using the cross entropy loss function. l+1 Perform adjustments and aggregation to generate a predictive model Specifically include:
[0138] First calculate the probability of u participating in v:
[0139] Among them, v u is the final representation vector of the test case v, and f is a differentiable prediction function, such as an inner product function or a multilayer perceptron.
[0140] Generally, the label function l u (v) = y uv , is usually constrained to take specific values, if u participates in test case v, then l u (v)=1, otherwise l u (v) = 0. But in fact, the vector entities in the knowledge graph are correlated. In this embodiment, the thermodynamic energy function is selected to solve this problem, that is, when the energy value reaches the minimum, the system reaches a stable state. Formula (6) is expressed as:
[0141]
[0142] Assume a single test case v, do not label it, and then use the remaining labeled items and unlabeled item entities to predict the label of the item. Among them, the true relevance label of the test case v and the predicted label The difference between them is used as a supervisory signal to adjust the edge weights. It can be expressed as follows through the following relation (7):
[0143]
[0144] Among them, J is the cross entropy loss function. Through the above regularization, the edge weight matrix can reproduce each retained formal relevance label while also satisfying the smoothness of the relevance label.
[0145] Finally, model optimization. By combining knowledge-aware graph neural network and edge weight regularization, we can get the loss function, which is expressed by equation (8):
[0146]
[0147] in, is L2 regularization, and λ and γ are balancing hyperparameters. In equation (8), the first term corresponds to the part where the graph neural network simultaneously learns the transformation matrix W and the edge weight A, and the second term R(A) corresponds to the part that adjusts the edge weight, which can be regarded as adding constraints to the edge weight A. Therefore, R(A) is the regularization of A, which can help the graph neural network learn the edge weight. At the same time, the first term can be regarded as feature propagation on the knowledge graph, and the second term can be regarded as label propagation on the knowledge graph. A recommendation system is actually a mapping from project features to interface and test case interaction labels.
[0148] The test case generation method based on knowledge graph provided by the embodiment of the present invention converts the knowledge graph into a low-order neighborhood matrix and a high-order neighborhood matrix, and fuses the two neighborhood matrices to generate an embedding vector for aggregating adjacent entities. Finally, the embedding vector is adjusted and aggregated using the cross entropy loss function to generate a prediction model. The prediction model can be used to automatically generate interface test cases, thereby realizing automatic recommendation of interface test cases, helping testers to select suitable test cases more quickly and improving testing efficiency.
[0149] In addition, the method provided in this embodiment comprehensively and accurately obtains the relationship between entities by integrating the dual neighborhood of the knowledge graph, ensures the divergence of the recommendation effect, and solves the problem that the test cases cannot be fully covered. At the same time, it can also reduce noise and recommend test cases more accurately, thereby improving the coverage of test cases.
[0150] In summary, the method of this embodiment provides test case recommendations and sorting for testers by constructing a knowledge graph of interface test cases and integrating the dual neighborhoods of the knowledge graph, which has the beneficial effects of improving test efficiency, increasing test coverage, and reducing test costs.
[0151] In another embodiment, the above method of this embodiment can also be executed by multiple modules, such as Figure 5 As shown, the execution process includes two parts: application of the recommendation module and presentation of the recommendation results.
[0152] In the application stage of the recommendation module, first, the Spring backend framework is used to implement data processing interaction, so as to obtain test results, test reports and other information. Secondly, the Vue front-end framework is used to implement the result display interface. Finally, the Highcharts data visualization tool is used to implement chart display, making the test results more intuitive and easy to understand.
[0153] In the presentation stage of the recommended results, first of all, the result presentation needs to display the execution results, test coverage, test time and other information of the test cases. Detailed information such as test reports and test logs should be displayed so that testers can troubleshoot and analyze problems. Secondly, the result presentation needs to support user interaction. Testers can view detailed information or perform operations by clicking on an element in a chart or list. Finally, the result presentation also supports user-defined configuration. Testers can choose which information to display and how to display it. Finally, in order to solve the problem of large data volume, Redis cache technology is used to implement data caching, and Websocket is used to implement asynchronous loading.
[0154] Specifically, the above method flow can use the following modules: data collection module, knowledge graph construction module, recommendation module and application module. The method steps of each module specifically include the following:
[0155] Step 1: The data acquisition module defines the data acquisition device, including the method and specification of data acquisition. This step corresponds to step S100-1 of the above embodiment.
[0156] Step 2: The data collection module adds annotations to the code of the interface test case to identify the parameters that need to be collected, and extracts key information of the test case by statically analyzing the interface test case. This step corresponds to step S100-2 of the above embodiment.
[0157] Step 3: The data acquisition module uses a file system to store and manage data.
[0158] Step 4: The knowledge graph construction module cleans and preprocesses the collected data, mainly converting the interface request and response data into a unified data structure.
[0159] Step 5: The knowledge graph construction module constructs a knowledge graph model based on the collected data: taking interfaces and use cases as entities, interface requests and responses as attributes, and the usage relationship between interfaces and use cases as relationships, and using graph database technology to construct the corresponding knowledge graph. This step corresponds to step S101 of the above embodiment.
[0160] Step 6: The knowledge graph construction module loads the data into the knowledge graph and optimizes it. This step is optional.
[0161] Step 7: The recommendation module determines the sampling domain according to the knowledge graph according to a specific relationship scoring function. This step corresponds to step S102 of the above embodiment.
[0162] Step 8: The recommendation module generates a corresponding dual neighborhood according to the sampling domain. This step corresponds to step S102 of the above embodiment.
[0163] Step 9: The recommendation module fuses the dual neighborhoods and converts them into an embedding vector. This step corresponds to step S103 of the above embodiment.
[0164] Step 10: The recommendation module and the interface vector are aggregated and predicted to generate a prediction result. This step corresponds to step S104 of the above embodiment.
[0165] Step 11: The application module uses the Spring backend framework to implement data processing interaction and obtain test results, test reports and other information.
[0166] Step 12: The application module uses the Vue front-end framework to implement the result display interface.
[0167] Step 13: The application module uses Highcharts data visualization tool to implement chart display, making the test results more intuitive and easy to understand.
[0168] In this embodiment, a test case generation device based on a knowledge graph is also provided, which is used to implement the above-mentioned embodiments and preferred implementation modes, and the descriptions that have been made will not be repeated. As used below, the term "module" can implement a combination of software and / or hardware for a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.
[0169] This embodiment provides a test case generation device based on knowledge graph, such as Figure 6 As shown, the device includes: a construction module 610, a processing module 620, a fusion module 630, a generation module 640 and a prediction module 650. In addition, the device may also include other more or fewer modules, such as a storage module, a transceiver module, etc., which is not limited in this embodiment.
[0170] Among them, the construction module 610 is used to construct a knowledge graph corresponding to the interface test case. The knowledge graph is a heterogeneous graph with each interface test case as an entity, and the edges of each interface test case represent the mutual connection between multiple entities.
[0171] The processing module 620 is used to convert the knowledge graph into a low-order neighborhood matrix and a high-order neighborhood matrix using a preset relationship scoring function.
[0172] The fusion module 630 is used to fuse the low-order neighborhood matrix and the high-order neighborhood matrix according to preset weights to obtain an embedding vector for aggregating adjacent entities.
[0173] The generation module 640 is used to adjust and aggregate the embedded vectors using the cross entropy loss function to generate a prediction model.
[0174] The prediction module 650 is used to input the interface request information into the prediction model, generate interface test cases after model prediction, and feed back the interface test cases.
[0175] In some optional implementations, the processing module 620 is further used to define an interface of a data collector, which defines methods and specifications for data collection; and the interface of the data collector is used to collect input and output parameters and test case information.
[0176] The construction module 610 is specifically used to construct a knowledge graph corresponding to the interface test case based on the input and output parameters and the test case information.
[0177] In other optional implementations, the processing module 620 is also used to clean and preprocess the input and output parameters and the test case information; the construction module 610 is specifically used to construct the knowledge graph based on the input and output parameters and test case information after data preprocessing.
[0178] Among them, the input and output parameters include at least one interface; the processing module 620 is also used to determine the relationship between various entities based on the knowledge graph, and the entities are various test cases that constitute the knowledge graph; based on the relationship and the at least one interface, the preset relationship scoring function is calculated; using the preset relationship scoring function, the knowledge graph is converted into the low-order neighborhood matrix (Afu) and the high-order neighborhood matrix (ASu).
[0179] Furthermore, the processing module 620 is specifically used to obtain the order, the central entity, the entity to be sampled, and the relationship between the central entity and the entity to be sampled in the knowledge graph; according to the preset relationship scoring function, the order, the central entity, the entity to be sampled, and the relationship between the central entity and the entity to be sampled in the knowledge graph, the low-order sampling threshold and the high-order sampling threshold are respectively calculated to generate a low-order neighborhood matrix and a high-order neighborhood matrix.
[0180] The low-order sampling threshold algorithm is expressed by the following equation (2):
[0181]
[0182] The high-order sampling threshold algorithm is expressed by the following relation (3):
[0183]
[0184] Among them, s u (r v,e ) is the preset relationship scoring function, v is the central entity, e is the entity to be sampled, r v,eis the relationship between the central entity v and the entity to be sampled e in the knowledge graph, k is the order, α is the ratio of the sampling order of the low-order neighborhood matrix to the high-order neighborhood matrix, and Af u is the low-order neighborhood representation vector, corresponding to the low-order neighborhood matrix, As u is a high-order neighborhood representation vector, corresponding to a high-order neighborhood matrix.
[0185] The weight relationship (4) is expressed as:
[0186] A u =βAf u +(1-β)As u (4)
[0187] Among them, β is the proportional factor, and its value range is β∈[0,1], A u is the representation vector of aggregated adjacent entities;
[0188] Use multiple feed-forward layers to update the representation vector A by aggregating the representations of neighboring entities u , and obtain the embedding vector, where the expression (5) of the embedding vector is:
[0189]
[0190] Among them, H l is the entity hidden representation matrix of the lth layer, H l+1 is the entity embedding vector of the l+1th layer, D u is a diagonal matrix, For standardization A u , W l is a layer-specific trainable weight matrix, σ is a nonlinear activation function, L is the number of layers, and l ranges from 0 to L-1.
[0191] The further functional description of each of the above modules and units is the same as that of the above corresponding embodiments and will not be repeated here.
[0192] The knowledge graph-based test case generation device in this embodiment is presented in the form of a functional unit, where the unit refers to an ASIC (Application Specific Integrated Circuit) circuit, a processor and memory that executes one or more software or fixed programs, and / or other devices that can provide the above functions.
[0193] The embodiment of the present invention also provides a computer device having the above Figure 6 The test case generation device based on knowledge graph is shown.
[0194] See also Figure 7, is a schematic diagram of the structure of a computer device provided by an optional embodiment of the present invention, the computer device includes: one or more processors 10, a memory 20, and interfaces for connecting various components, including high-speed interfaces and low-speed interfaces. The various components are connected to each other using different buses for communication, and can be installed on a common motherboard or in other ways as needed. The processor can process instructions executed in the computer device, including instructions stored in or on the memory to display graphical information of the GUI on an external input / output device (such as a display device coupled to the interface).
[0195] In some optional embodiments, if desired, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Similarly, multiple computer devices can be connected, and each device provides part of the necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system). Figure 7 A processor 10 is taken as an example.
[0196] The processor 10 may be a central processing unit, a network processor or a combination thereof. The processor 10 may further include a hardware chip. The hardware chip may be a dedicated integrated circuit, a programmable logic device or a combination thereof. The programmable logic device may be a complex programmable logic device, a field programmable gate array, a general purpose array logic or any combination thereof.
[0197] Among them, the memory 20 stores instructions that can be executed by at least one processor 10, so that the at least one processor 10 executes the test case generation method based on the knowledge graph shown in the above embodiment.
[0198] The memory 20 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created according to the use of the computer device, etc. In addition, the memory 20 may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some optional embodiments, the memory 20 may include a memory remotely arranged relative to the processor 10, and these remote memories may be connected to the computer device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0199] The memory 20 may include a volatile memory, such as a random access memory; the memory may also include a non-volatile memory, such as a flash memory, a hard disk or a solid state drive; the memory 20 may also include a combination of the above types of memory.
[0200] The computer device also includes an input device 30 and an output device 40. The processor 10, the memory 20, the input device 30 and the output device 40 may be connected via a bus or other means. Figure 7 The example of connecting through bus is taken in the following.
[0201] The input device 30 can receive input digital or character information, and generate key signal input related to the user settings and function control of the computer device, such as a touch screen, a keypad, a mouse, a track pad, a touch pad, an indicator bar, one or more mouse buttons, a trackball, a joystick, etc. The output device 40 may include a display device, an auxiliary lighting device (e.g., an LED) and a tactile feedback device (e.g., a vibration motor), etc. The above-mentioned display device includes but is not limited to a liquid crystal display, a light emitting diode, a display and a plasma display. In some optional embodiments, the display device can be a touch screen.
[0202] The computer device also includes a communication interface, which is used for the computer device to communicate with other devices or a communication network.
[0203] Optionally, the computer device may be a network device, such as a server or a server cluster, or may be a terminal device, such as a client or a PC, which is not limited in this embodiment.
[0204] An embodiment of the present invention also provides a computer-readable storage medium, and the above-mentioned method according to the embodiment of the present invention can be implemented in hardware, firmware, or can be implemented as a computer code that can be recorded in a storage medium, or can be implemented by downloading through a network and originally stored in a remote storage medium or a non-temporary machine-readable storage medium and will be stored in a local storage medium, so that the method described herein can be stored in such software processing on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware.
[0205] The storage medium may be a magnetic disk, an optical disk, a read-only storage memory, a random access memory, a flash memory, a hard disk or a solid state drive, etc.; further, the storage medium may also include a combination of the above-mentioned types of memories. It is understood that a computer, a processor, a microprocessor controller or programmable hardware includes a storage component that can store or receive software or computer code. When the software or computer code is accessed and executed by the computer, processor or hardware, the method shown in the above embodiment is implemented.
[0206] Embodiments of the present application may also provide a computer program product, including computer program instructions, which, when executed by a processor, cause the processor to perform the steps in the above method. Wherein, the computer program product may be written in any combination of one or more programming languages to perform program codes for performing the operations of the disclosed embodiments, wherein the programming languages include object-oriented programming languages, such as Java, C++, etc., and also include conventional procedural programming languages, such as "C" language or similar programming languages. The program code may be executed entirely on a user computing device, partially on a user device, as an independent software package, partially on a user computing device, partially on a remote computing device, or entirely on a remote computing device or server.
[0207] The above embodiments are only used to illustrate the technical solutions of the embodiments of the present invention, rather than to limit them. Although the embodiments of the present invention are described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some of the technical features therein by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A test case generation method based on knowledge graph, characterized in that: The method comprises: Constructing a knowledge graph corresponding to the interface test case, wherein the knowledge graph is a heterogeneous graph with each interface test case as an entity, and the edge of each interface test case represents the mutual connection between multiple entities; Using a preset relationship scoring function, the knowledge graph is converted into a low-order neighborhood matrix and a high-order neighborhood matrix; Fusing the low-order neighborhood matrix and the high-order neighborhood matrix according to preset weights to obtain an embedding vector for aggregating adjacent entities; Using a cross entropy loss function to adjust and aggregate the embedding vectors to generate a prediction model; The interface request information is input into the prediction model, an interface test case is generated after model prediction, and the interface test case is fed back.
2. The method according to claim 1, characterized in that Before constructing the knowledge graph corresponding to the interface test case, the method further includes: Defining an interface of a data collector, wherein the interface of the data collector defines a method and specification for data collection; Collecting input and output parameters and test case information using the interface of the data collector; The construction of the knowledge graph corresponding to the interface test case includes: According to the input and output parameters and the test case information, the knowledge graph corresponding to the interface test case is constructed.
3. The method according to claim 2, characterized in that The step of constructing the knowledge graph corresponding to the interface test case according to the input and output parameters and the test case information includes: Cleaning and data preprocessing the input and output parameters and the test case information; The knowledge graph is constructed based on the input and output parameters and test case information after data preprocessing.
4. The method according to claim 2, characterized in that: The input and output parameters include at least one interface; The method of converting the knowledge graph into a specific adjacency matrix by using a preset relationship scoring function includes: Determine the relationship between entities according to the knowledge graph, where the entities are the test cases constituting the knowledge graph; Calculating the preset relationship scoring function according to the relationship and the at least one interface; The preset relationship scoring function is used to convert the knowledge graph into the low-order neighborhood matrix and the high-order neighborhood matrix.
5. The method according to any one of claims 1 to 4, characterized in that: The using the preset relationship scoring function to convert the knowledge graph into the low-order neighborhood matrix and the high-order neighborhood matrix includes: Obtaining the order, the central entity, the entity to be sampled, and the relationship between the central entity and the entity to be sampled in the knowledge graph; According to the preset relationship scoring function, the order, the central entity, the entity to be sampled, and the relationship between the central entity and the entity to be sampled in the knowledge graph, the low-order sampling threshold and the high-order sampling threshold are calculated respectively to generate the low-order neighborhood matrix and the high-order neighborhood matrix.
6. The method according to claim 5, characterized in that The method generates the low-order neighborhood matrix and the high-order neighborhood matrix by respectively calculating the low-order sampling threshold and the high-order sampling threshold according to the preset relationship scoring function, the order, the central entity, the entity to be sampled, and the relationship between the central entity and the entity to be sampled in the knowledge graph, including: The preset relationship scoring function, the order, the central entity, the entity to be sampled, and the relationship are subjected to a low-order sampling threshold algorithm to generate a low-order neighborhood representation vector; and subjected to a high-order sampling threshold algorithm to generate a high-order neighborhood representation vector; Wherein, the low-order sampling threshold algorithm is expressed as: The high-order sampling threshold algorithm is expressed as: Among them, s u (r v,e ) is the preset relationship scoring function, v is the central entity, e is the entity to be sampled, r v,e is the relationship between the central entity v and the entity to be sampled e in the knowledge graph, k is the order, α is the ratio of the sampling order of the low-order neighborhood matrix to the high-order neighborhood matrix, and Af u is the low-order neighborhood representation vector, corresponding to the low-order neighborhood matrix, As u is a high-order neighborhood representation vector, corresponding to a high-order neighborhood matrix.
7. The method according to claim 6, characterized in that The step of fusing the low-order neighborhood matrix and the high-order neighborhood matrix according to preset weights to obtain an embedding vector for aggregating adjacent entities includes: The preset weight is set according to the scale factor, and the representation vector of the aggregated adjacent entities is obtained by calculating according to the preset weight according to the weight relationship formula; the weight relationship formula is: A u =βAf u +(1-β)As u Among them, β is the proportional factor, and its value range is β∈[0,1], A u is the representation vector of aggregated adjacent entities; Use multiple feed-forward layers to update the representation vector A by aggregating the representations of neighboring entities u , and obtain the embedding vector, where the expression of the embedding vector is: Among them, H l is the entity hidden representation matrix of the lth layer, H l+1 is the entity embedding vector of the l+1th layer, D u is a diagonal matrix, For standardization A u , W l is a layer-specific trainable weight matrix, σ is a nonlinear activation function, L is the number of layers, and l ranges from 0 to L-1.
8. A test case generation device based on knowledge graph, characterized in that: The device comprises: A construction module is used to construct a knowledge graph corresponding to the interface test case, wherein the knowledge graph is a heterogeneous graph with each interface test case as an entity, and the edge of each interface test case represents the mutual connection between multiple entities; A processing module, used to convert the knowledge graph into a low-order neighborhood matrix and a high-order neighborhood matrix using a preset relationship scoring function; A fusion module, used to fuse the low-order neighborhood matrix and the high-order neighborhood matrix according to a preset weight to obtain an embedding vector for aggregating adjacent entities; A generation module, used to adjust and aggregate the embedding vectors using a cross entropy loss function to generate a prediction model; The prediction module is used to input the interface request information into the prediction model, generate interface test cases after model prediction, and feed back the interface test cases.
9. A computer device, characterized in that: comprising a memory and a processor, wherein the memory and the processor are connected; The memory stores computer instructions, and the processor executes the test case generation method based on the knowledge graph described in any one of claims 1 to 7 by executing the computer instructions.
10. A computer-readable storage medium, characterized in that: The computer readable storage medium has computer instructions stored thereon. The computer instructions are used to enable a computer to execute the test case generation method based on a knowledge graph as described in any one of claims 1 to 7.
Citation Information
Cited By
Intelligent test case generation method and system based on dynamic knowledge graph
CN121935166A
A test case intelligent generation method and system based on a dynamic knowledge graph
CN121935166B