Regression test quality assessment method and device based on code knowledge graph
Through the method based on the code knowledge graph, the problem of difficulty in evaluating the quality of regression test in the prior art is solved. By calculating the similarity between the impact range of the code modification content and the coverage range, objective evaluation and efficient evaluation of the quality of regression test are achieved.
Patent Information
- Application Number
- CN202410169589.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-02-06
- Publication Date
- 2025-01-10
- Estimated Expiration
- 2044-02-06
AI Technical Summary
The existing technology lacks effective regression test quality evaluation methods, which leads to inefficient regression tests and difficulty in objective evaluation of quality.
Based on the code knowledge graph, the code ontology model is designed, the code entities, attributes and relationships in the source code are extracted, and the similarity between the impact range of the modified content and the coverage range is calculated through knowledge fusion and sub-graph search algorithms to obtain the regression test quality evaluation value. .
The objective evaluation and efficient evaluation of the quality of regression tests are achieved, and the efficiency and accuracy of regression tests are improved.
Smart Images

Figure CN118069507B_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of computer technology, and specifically, relates to a regression test quality assessment method and device based on code knowledge graph. Background Art
[0002] Regression testing refers to retesting after modifying the old code to confirm that the modification has not introduced new errors or caused errors in other codes. As an integral part of the software life cycle, regression testing accounts for a large proportion of the workload in the entire software testing process. Multiple regression tests are performed at each stage of software development. In incremental and rapid iterative development, the continuous release of new versions makes regression testing more frequent, and in extreme programming methods, regression testing is required several times a day. Automatic regression testing will greatly reduce the cost of system testing, maintenance and upgrades.
[0003] In the related art, no effective evaluation method for regression testing quality has been proposed yet. Summary of the invention
[0004] Therefore, an embodiment of the present application is to provide a regression test quality assessment method, device, electronic device and storage medium based on a code knowledge graph, aiming to solve at least one problem existing in the above-mentioned prior art.
[0005] To achieve the above objectives, in a first aspect, the present application provides a regression test quality assessment method based on a code knowledge graph, comprising:
[0006] Design a code ontology model, wherein the code ontology model includes code entities, code entity attributes, and code entity relationships;
[0007] Based on the code ontology model, code entities, code entity attributes and code entity relationships in the source code of the tested software are extracted, and knowledge fusion is performed on the code entities, code entity attributes and code entity relationships in the source code to obtain a code knowledge graph of the source code, wherein the knowledge fusion includes entity disambiguation and coreference resolution;
[0008] Based on the code knowledge graph, the similarity between the subgraph of the impact range of the modified content of the program code of the tested software in the regression test and the subgraph of the regression test coverage range is calculated through the subgraph search algorithm and the similarity evaluation technology, and the similarity is normalized by the preset weight to obtain the regression test quality evaluation value.
[0009] In one embodiment, the extraction of code entities, code entity attributes and code entity relationships in the source code of the software under test based on the code ontology model includes: based on the code ontology model, taking the program address of the software under test as input, performing knowledge extraction through multi-file batch generation and traversal of the abstract syntax tree to obtain the code entities, code entity attributes and code entity relationships in the source code of the software under test.
[0010] In one embodiment, when extracting the code entity, a unique identifier is set for each code entity, and when parsing the code entity relationship and code attributes, the type of the code relationship and the name of the corresponding code entity and the unique identifier are recorded.
[0011] In one embodiment, after knowledge fusion is performed on the code entities, code entity attributes and code entity relationships in the source code, the method further includes: performing knowledge reasoning on the code entity relationships in the source code to obtain multi-dimensional code entity relationships of codes at different granularities in the source code.
[0012] In one embodiment, based on the code knowledge graph, the similarity between the modified content impact range subgraph and the regression test coverage range subgraph of the program code of the tested software in the regression test is calculated through a subgraph search algorithm and a similarity evaluation technology, including: based on the code knowledge graph, a modified content impact range subgraph and a regression test coverage range subgraph of the program code of the tested software are generated through a subgraph search algorithm, the modified content impact range subgraph and the regression test coverage range subgraph are vectorized to obtain corresponding impact range subgraph vectors and coverage range subgraph vectors, and the similarity between the modified content impact range subgraph and the regression test coverage range subgraph is calculated based on the impact range subgraph vector and the coverage range subgraph vector.
[0013] In one embodiment, based on the code knowledge graph, a modified content impact range subgraph and a regression test coverage range subgraph of the program code of the tested software are generated through a subgraph search algorithm, including: querying the code knowledge graph for code entities related to the modified part of the program code of the tested software, locating part of the code content in the program code that is directly affected by the code entities related to the modified part, and diffusing along points and edges to obtain the modified content impact range subgraph; according to the program call relationship mapping path of the test data in the program code of the tested software in the code knowledge graph, mapping the program code of the tested software to the code knowledge graph for combined deduplication to obtain the regression test coverage range subgraph.
[0014] In one embodiment, before vectorizing the modified content impact range subgraph and the regression test coverage range subgraph to obtain the corresponding impact range subgraph vector and coverage range subgraph vector, it also includes: counting the fan-in values of the code entities of the modified content part in the program code of the tested software and calculating the fan-in coefficient; calculating the multi-hop correlation between the modified code entities and other entities in the modified content impact range subgraph and the regression test coverage range subgraph; the similarity between the modified content impact range subgraph and the regression test coverage range subgraph calculated based on the impact range subgraph vector and the coverage range subgraph vector includes: taking the fan-in coefficient and the multi-hop correlation value of each code entity in the modified content part in the program code as the modified content impact range subgraph and the features of the nodes in the regression test coverage range subgraph to obtain the node vectors of the nodes in the modified content impact range subgraph and the regression test coverage range subgraph, and calculate the inner product of the impact range subgraph vector and the node vector of the modified content impact range subgraph with the coverage range subgraph vector and the node vector of the regression test coverage range subgraph to obtain the similarity between the modified content impact range subgraph and the regression test coverage range subgraph; wherein the fan-in value represents the number of parent modules of the current code entity, the fan-in coefficient is equal to the fan-in value of the current code entity divided by the maximum fan-in value of all code entities, the multi-hop correlation represents the distance between two code entities, and the multi-hop correlation of the current code entity is equal to one divided by the distance between the current code entity and another code entity.
[0015] In a second aspect, the present application also provides a regression test quality assessment device based on a code knowledge graph, comprising:
[0016] A model design module, used to design a code ontology model, wherein the code ontology model includes code entities, code entity attributes and code entity relationships;
[0017] A model building module is used to extract code entities, code entity attributes and code entity relationships in the source code of the tested software based on the code ontology model, and perform knowledge fusion on the code entities, code entity attributes and code entity relationships in the source code to obtain a code knowledge graph of the source code, wherein the knowledge fusion includes entity disambiguation and coreference resolution;
[0018] An evaluation module is used to calculate the similarity between the subgraph of the impact range of the modified content of the program code of the tested software in the regression test and the subgraph of the regression test coverage range based on the code knowledge graph and through a subgraph search algorithm and similarity evaluation technology, and normalize the similarity through a preset weight to obtain a regression test quality evaluation value.
[0019] In a third aspect, the present application also provides an electronic device, comprising a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the steps of the regression testing quality assessment method based on the code knowledge graph.
[0020] In a fourth aspect, the present application also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the processor executes the steps of the regression testing quality assessment method based on the code knowledge graph.
[0021] The embodiment of the present application provides a regression test quality assessment method, device, electronic device and storage medium based on code knowledge graph, by designing a code ontology model, the code ontology model includes code entities, code entity attributes and code entity relationships; based on the code ontology model, extracting code entities, code entity attributes and code entity relationships in the source code of the tested software, performing knowledge fusion on the code entities, code entity attributes and code entity relationships in the source code, and obtaining a code knowledge graph of the source code, wherein the knowledge fusion includes entity disambiguation and coreference resolution; based on the code knowledge graph, calculating the similarity between the subgraph of the impact range of the modified content of the program code of the tested software in the regression test and the subgraph of the regression test coverage range through a subgraph search algorithm and similarity assessment technology, and normalizing the similarity through a preset weight to obtain a regression test quality assessment value. Efficient regression testing is achieved, and objective evaluation of the quality of regression testing is achieved. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] The drawings constituting a part of this application are used to provide a further understanding of this application, so that other features, purposes and advantages of this application become more obvious. The schematic embodiment drawings and their descriptions of this application are used to explain this application and do not constitute an improper limitation on this application. In the drawings:
[0023] Figure 1 The implementation process of the regression test quality assessment method based on code knowledge graph provided in the embodiment of the present application;
[0024] Figure 2 A processing flow chart of a regression test quality assessment method based on a code knowledge graph provided in an embodiment of the present application;
[0025] Figure 3 An example diagram of a code knowledge graph for a regression test quality assessment method based on a code knowledge graph provided in an embodiment of the present application;
[0026] Figure 4An example diagram of a subgraph of the impact range of modified content of a regression test quality assessment method based on a code knowledge graph provided in an embodiment of the present application;
[0027] Figure 5 An example diagram of a regression test coverage range subgraph of a regression test quality assessment method based on a code knowledge graph provided in an embodiment of the present application;
[0028] Figure 6 A relationship diagram between a modified code entity and other entities of a regression test quality assessment method based on a code knowledge graph provided in an embodiment of the present application;
[0029] Figure 7 A schematic diagram of the main modules of a regression test quality assessment device based on a code knowledge graph provided in an embodiment of the present application;
[0030] Figure 8 An exemplary system architecture diagram that can be applied to the embodiments of the present application;
[0031] Fig. 9 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present application. DETAILED DESCRIPTION
[0032] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.
[0033] It should be noted that 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 are not necessarily used to describe a specific order or sequential order. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present application described here. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0034] In the present application, the terms "upper", "lower", "left", "right", "front", "back", "top", "bottom", "inner", "outer", "middle", "vertical", "horizontal", "lateral", "longitudinal" and the like indicate positions or positional relationships based on the positions or positional relationships shown in the drawings. These terms are mainly used to better describe the present application and its embodiments, and are not used to limit the indicated devices, elements or components to have a specific orientation, or to be constructed and operated in a specific orientation.
[0035] In addition, some of the above terms may be used to express other meanings in addition to indicating orientation or positional relationship. For example, the term "on" may also be used to express a certain dependency or connection relationship in some cases. For those of ordinary skill in the art, the specific meanings of these terms in this application can be understood according to specific circumstances.
[0036] In addition, the term "plurality" shall mean two or more.
[0037] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present application can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0038] Figure 1 The implementation process of a regression test quality assessment method based on a code knowledge graph provided by an embodiment of the present application is shown. For the sake of convenience, only the part related to the embodiment of the present application is shown, which is described in detail as follows:
[0039] A regression test quality assessment method based on code knowledge graph includes the following steps:
[0040] S101: Design a code ontology model, wherein the code ontology model includes code entities, code entity attributes, and code entity relationships;
[0041] S102: extracting code entities, code entity attributes, and code entity relationships in the source code of the tested software based on the code ontology model, and performing knowledge fusion on the code entities, code entity attributes, and code entity relationships in the source code to obtain a code knowledge graph of the source code, wherein the knowledge fusion includes entity disambiguation and coreference resolution;
[0042] S103: Based on the code knowledge graph, the similarity between the subgraph of the impact range of the modified content of the program code of the tested software in the regression test and the subgraph of the regression test coverage range is calculated through a subgraph search algorithm and a similarity evaluation technology, and the similarity is normalized by a preset weight to obtain a regression test quality evaluation value.
[0043] Therefore, as a whole, the embodiment of the present application uses the tested software code as the information source and realizes knowledge extraction by parsing the source code. First, obtain multi-granularity code entities such as packages, classes, domains, methods, statements, and then realize the extraction of relationships such as containment, calling, control and data by analyzing the control and data dependencies between code entities at the same level. Based on the extracted code entities and relationships, a multi-granularity and multi-level code knowledge graph is constructed through knowledge fusion and knowledge reasoning. Next, based on the code knowledge graph of the tested software, the similarity between the range subgraph affected by the code change and the range subgraph of the regression test coverage actually executed is calculated through subgraph search algorithms and similarity evaluation and other technologies, providing an objective basis for the quality evaluation of regression testing.
[0044] like Figure 2 , which is a processing flow chart of the regression test quality assessment method based on code knowledge graph provided in an embodiment of the present application.
[0045] In step S101: design a code ontology model, which includes code entities, code entity attributes and code entity relationships. Thus, based on the tested software code information, the relationship between code entities, code entity attributes and code entity relationships is established to construct a code model for subsequent regression testing.
[0046] It should be noted that the processing principles of different types of source codes are similar. In order to illustrate the principle, a Java file example is used in conjunction with the embodiments of the present application.
[0047]
[0048]
[0049] The code entities in the code ontology model include at least the following types:
[0050] Package: refers to the name of the package to which the file belongs. For example, "File" in Code 1 is an instance of a package, and the same applies to the following.
[0051] Class: refers to the name of a class. For example, "Demo" in Code 1 is an instance of a class.
[0052] Method: refers to the name of a method. For example, "getFile()" in Code 1 is an instance of a method.
[0053] Field: refers to the member variables in a class. For example, "buffer" and "bf" in Code 1 are instances of member variables.
[0054] Statement: refers to each statement in the method. Different statements are extracted in different ways. If it is a variable declaration, it is "variable type.variable name". For example, the statement "int i = 1" in Code 1 is an instance of a statement. Control node: refers to the context of a statement block with conditions such as if and while. For example, for the statement block "while((s = bf.readLine())! = null) {buffer.append(s.trim());}" in Code 1, extract "while", "s! = null" as instances of control nodes.
[0055] The code entity attributes in the code ontology model include at least the following types:
[0056] Type: refers to the type of the entity. For example, the type of the entity "StringBuffer.buffer" in Code 1 is "StringBuffer()".
[0057] Parameter list: refers to all parameters involved in the entity. For example, the parameter list of the entity "getFile()" in Code 1 is "path".
[0058] Package: refers to the package name to which the entity belongs. For example, the entity "getFile()" in Code 1 belongs to the package "File".
[0059] Class: refers to the class name to which the entity belongs. For example, the class of the entity "StringBuffer.buffer" in Code 1 is "Demo".
[0060] Method: refers to the method name to which the entity belongs. For example, the method to which the entity "StringBuffer.buffer" in Code 1 belongs is "getFile()".
[0061] The code entity relationships in the code ontology model include at least the following types:
[0062] Containment relationship: used to describe the inclusion between all entities. For example, the triple [Demo, containment, getFile()]Call relationship: used to describe the call between objects in a statement. For example, the triple [BufferedReader.bf, call, readLine()].
[0063] Conditional relation: used to describe the context entity of a control statement, such as the triple [while, condition, s! = null]. For each type of detail, a relation is defined specifically.
[0064] Data flow relationship: used to describe the contextual changes of data. It is a binary relationship between entities "statement" and "statement". For example, the triple [int i=1, data flow, i++].
[0065] The above is only an example of an embodiment of the present application. The embodiment of the present application may also include a variety of different code entities and code entity relationships. Therefore, those skilled in the art can understand that the code entities and the relationships between code entities can be expanded according to specific needs.
[0066] In step S102: based on the code ontology model, code entities, code entity attributes and code entity relationships in the source code of the tested software are extracted, and knowledge fusion is performed on the code entities, code entity attributes and code entity relationships in the source code to obtain a code knowledge graph of the source code, wherein the knowledge fusion includes entity disambiguation and coreference resolution.
[0067] Therefore, by analyzing the source code of the tested software, based on the definition of the ontology model, we extract multi-granularity code entities such as packages, classes, domains, methods, and statements in the source code. We also extract dependencies between code entities of the same granularity, as well as inclusion relationships between code entities of different granularities. Due to problems such as aliases, we need to perform knowledge alignment processing such as entity disambiguation and coreference resolution on the extracted code entities and relationships, and finally form a complete multi-granularity and multi-dimensional code knowledge graph.
[0068] In one embodiment, the extraction of code entities, code entity attributes and code entity relationships in the source code of the software under test based on the code ontology model includes: based on the code ontology model, taking the program address of the software under test as input, performing knowledge extraction through multi-file batch generation and traversal of the abstract syntax tree to obtain the code entities, code entity attributes and code entity relationships in the source code of the software under test.
[0069] In one embodiment, when extracting the code entity, a unique identifier is set for each code entity, and when parsing the code entity relationship and code attributes, the type of the code relationship and the name of the corresponding code entity and the unique identifier are recorded.
[0070] In one embodiment, after knowledge fusion is performed on the code entities, code entity attributes and code entity relationships in the source code, the method further includes: performing knowledge reasoning on the code entity relationships in the source code to obtain multi-dimensional code entity relationships of codes at different granularities in the source code.
[0071] Specifically, when the code ontology model is built, a program address of the tested software can be used as input, and knowledge can be extracted by batch generating and traversing the Abstract Syntax Tree (AST) of multiple files to obtain code entities and their code entity relationships that meet the definition of the code ontology model. When extracting code entities, a unique identifier is set for each code entity, and in the process of parsing code entity relationships and code entity attributes, the type of code entity relationship and the corresponding code entity name and unique identifier are recorded. Finally, after entity disambiguation, coreference resolution and other processes, these information extraction results are first fused with knowledge, thereby eliminating a large amount of redundant and repeated information in these candidate knowledge units. For example, for the method "visit (MethodDeclaration node)" and the method "visit (PackageDeclaration node)", although the extracted names are both visit(), these are two different methods, and their parameters and method contents are also different, which is ambiguous. These information extraction results can be first fused with knowledge through entity disambiguation, coreference resolution and other processes.
[0072] Furthermore, considering the needs of different users to evaluate and regress program units of different granularities, multi-dimensional relationships at different granularities are also required. Therefore, knowledge reasoning is used on the basis of the extracted code entities and code entity relationships to obtain multi-dimensional code entity relationships of codes at different granularities in the source code. If the evaluation granularity selected by the user is "package", but there is no calling relationship between packages in the extracted code entity relationship, then the containment relationship between the package and the method is needed to locate the package name to which the method belongs, so as to infer the calling relationship of the package based on the calling relationship of the method. For example, package a contains method b, package c contains method d, and method b calls method d, and it is inferred that there is a calling relationship between package a and package c. Rules are also set for reasoning for other granularities and dimensional relationships. The final multi-granularity and multi-dimensional code knowledge graph is as follows: Figure 3 As shown, Figure 3 The calling relationship in is an inference relationship.
[0073] In step S103: Based on the code knowledge graph, the similarity between the subgraph of the impact range of the modified content of the program code of the tested software in the regression test and the subgraph of the regression test coverage range is calculated through the subgraph search algorithm and the similarity evaluation technology, and the similarity is normalized by the preset weight to obtain the regression test quality evaluation value. In this way, the regression test quality evaluation is carried out based on the code knowledge graph. Here, the similarity between the scope of the code change impact and the actual executed regression test coverage range subgraph is calculated through the subgraph search and similarity evaluation techniques as an objective basis for the quality evaluation of the regression test.
[0074] In one embodiment, based on the code knowledge graph, the similarity between the modified content impact range subgraph and the regression test coverage range subgraph of the program code of the tested software in the regression test is calculated through a subgraph search algorithm and a similarity evaluation technology, including: based on the code knowledge graph, a modified content impact range subgraph and a regression test coverage range subgraph of the program code of the tested software are generated through a subgraph search algorithm, the modified content impact range subgraph and the regression test coverage range subgraph are vectorized to obtain corresponding impact range subgraph vectors and coverage range subgraph vectors, and the similarity between the modified content impact range subgraph and the regression test coverage range subgraph is calculated based on the impact range subgraph vector and the coverage range subgraph vector.
[0075] In one embodiment, based on the code knowledge graph, a modified content impact range subgraph and a regression test coverage range subgraph of the program code of the tested software are generated through a subgraph search algorithm, including: querying the code knowledge graph for code entities related to the modified part of the program code of the tested software, locating part of the code content in the program code that is directly affected by the code entities related to the modified part, and diffusing along points and edges to obtain the modified content impact range subgraph; according to the program call relationship mapping path of the test data in the program code of the tested software in the code knowledge graph, mapping the program code of the tested software to the code knowledge graph for combined deduplication to obtain the regression test coverage range subgraph.
[0076] In one embodiment, before vectorizing the modified content impact range subgraph and the regression test coverage range subgraph to obtain the corresponding impact range subgraph vector and coverage range subgraph vector, it also includes: counting the fan-in values of the code entities of the modified content part in the program code of the tested software and calculating the fan-in coefficient; calculating the multi-hop correlation between the modified code entities and other entities in the modified content impact range subgraph and the regression test coverage range subgraph; the similarity between the modified content impact range subgraph and the regression test coverage range subgraph calculated based on the impact range subgraph vector and the coverage range subgraph vector includes: taking the fan-in coefficient and the multi-hop correlation value of each code entity in the modified content part in the program code as the modified content impact range subgraph and the features of the nodes in the regression test coverage range subgraph to obtain the node vectors of the nodes in the modified content impact range subgraph and the regression test coverage range subgraph, and calculate the inner product of the impact range subgraph vector and the node vector of the modified content impact range subgraph with the coverage range subgraph vector and the node vector of the regression test coverage range subgraph to obtain the similarity between the modified content impact range subgraph and the regression test coverage range subgraph; wherein the fan-in value represents the number of parent modules of the current code entity, the fan-in coefficient is equal to the fan-in value of the current code entity divided by the maximum fan-in value of all code entities, the multi-hop correlation represents the distance between two code entities, and the multi-hop correlation of the current code entity is equal to one divided by the distance between the current code entity and another code entity.
[0077] Specifically, in regression testing, the test targets are mainly the modified parts, directly affected parts, and potentially affected parts of the program. This application generates a subgraph of the impact range of the modified content and a subgraph of the actual test coverage through a code knowledge graph, and performs a weighted similarity calculation on the two subgraphs to complete the evaluation of the regression testing method.
[0078] First, by searching the code entities related to the modified part of the program code of the tested software in the code knowledge graph, the directly affected part of the program code can be quickly located. On this basis, a specific subgraph (modification content impact range subgraph) is obtained by diffusion along the points and edges. This subgraph shows the scope affected by this modification. Assuming that a modified java file is given, different positioning strategies are adopted for code addition, deletion, and modification according to the specific modification content of the program. 1. Code addition: For the regression test of adding code operations, the modified code knowledge graph is regenerated. Add the new code entities and code relationships to the subgraph, and then diffuse along the points and edges related to these code entities to obtain the associated specific paths, combine them, eliminate the repeated coverage areas, and generate the scope that may be affected by this program modification. 2. Code deletion: For the regression test of deleting code operations, first find all the relevant code entities deleted in its code knowledge graph, and the subsequent subgraph generation process is the same as in 1. 3. Code modification: For the regression test of modifying code operations, first find all the relevant code entities before modification in its code knowledge graph, and the subsequent subgraph generation process is the same as in 1.
[0079] For example, for code 1, assume that the append() method in the StringBuffer class under the java.lang package is modified and rewritten, and a new Test.txt file is created with the following content:
[0080]
[0081] And design the following test cases to perform regression testing on the code as shown in the figure:
[0082] serial number enter Expected Results Real results 1 Test.txt HelloWorld
[0083] For the above example, first generate a subgraph of the range that may be affected after the code is modified. The specific process is: find the modified related code entity append() in the graph. Query along its associated points and edges, and find that the code entity has a call relationship with the "buffer.append(s.trim())" statement code entity, and also has an inclusion relationship with the "StringBuffer" class code entity. The latter will not be affected by its change, while the buffer variable of the former may change as a result, so only the points and edges of the former are expanded. Continue to query along the points and edges related to the "buffer.append(s.trim())" code entity, and find that the code entity has a data relationship with the "System.out.println(buffer.toString())" statement code entity, and the change of buffer may affect the output result, etc. Through the above method, a subgraph G of the code knowledge graph is obtained. T (Modify the content to affect the sub-map), such as Figure 4 As shown, it intuitively shows the scope that each modification in the program may affect.
[0084] Then, the test set of the regression test to be evaluated (the program code of the tested software) is mapped to the code knowledge graph to obtain the actual coverage of this test. Then, the test set selected by the regression test method to be evaluated is introduced, and according to the mapping path of the test data in the test set in the program call relationship knowledge graph, the combination and duplication are also performed to obtain the actual coverage range subgraph of the regression test method (regression test coverage range subgraph) G R ,like Figure 5 shown.
[0085] Secondly, after obtaining the two subgraphs, first count the fan-in value of the current code entity, that is, the number of parent modules that directly call the code entity, and then calculate the fan-in coefficient, that is, count the fan-in value of the code entity in the modified content part of the program code of the tested software and calculate the fan-in coefficient. Let the fan-in coefficient of the code entity be V i =C i / max{c}, where C i represents the fan-in value of code entity i, and max{c} represents the maximum fan-in value of all code entities. Because test experience shows that the modification of high fan-in entities will cause more errors, entities with different fan-in coefficients have different importance in similarity measurement, and the fan-in coefficient of the entity is used for subsequent similarity calculation.
[0086] Furthermore, the multi-hop correlation between the modified entities and other entities in the two subgraphs is calculated, that is, the distance h between the two entities. Two directly connected entities h=1 have a 1-hop correlation, and the relationship between them is the closest. Two entities indirectly connected through an intermediate entity h=2 have a 2-hop correlation, and the connection between them is slightly weaker than the 1-hop correlation. Similarly, the connection between entities gradually weakens as the h value increases. In regression testing, the part closest to the directly modified part is more likely to be affected, while the part farther away will be less affected. The multi-hop correlation of entities is used for subsequent similarity calculations. The multi-hop correlation is P i =1 / H i , for example, Figure 6 The relationship diagram between the modified code entity and other entities of the regression test quality assessment method based on code knowledge graph provided in the embodiment of the present application shows that the names, fan-in values, fan-in coefficients, hop counts and multi-hop correlation s of other entities except the modified entity are as follows: entity 1, c=2, v=1, h=1, p=1; entity 2, c=0, v=0, h=2, p=1 / 2; entity 3, c=0, v=0, h=2, p=1 / 2; entity 4, c=1, v=1 / 2, h=1, p=1; entity 5, c=0, v=0, h=2, p=1 / 2.
[0087] Finally, the two subgraphs are represented by vectors, and the similarity is calculated based on the vectors corresponding to the graphs. In this process, the fan-in coefficient and multi-hop association value of each entity are also extracted as the features of the nodes in the subgraph, and finally the vector representation of the node is obtained. Finally, the inner product of the two subgraph vectors is calculated to obtain the similarity.
[0088] Taking into account that regression testing may have different emphases in different scenarios, a normalized regression testing quality assessment algorithm with variable weights is used in the embodiment of the present application. The weight values of various indicators are dynamically adjusted according to actual software development requirements, and the final evaluation result is limited to the [0,1] interval through normalization, thereby completing a comprehensive assessment of the regression testing quality.
[0089] Therefore, the regression test quality assessment method based on code knowledge graph provided in the embodiment of the present application is designed by designing a code ontology model, wherein the code ontology model includes code entities, code entity attributes and code entity relationships; based on the code ontology model, the code entities, code entity attributes and code entity relationships in the source code of the tested software are extracted, and the code entities, code entity attributes and code entity relationships in the source code are fused with knowledge to obtain a code knowledge graph of the source code, wherein the knowledge fusion includes entity disambiguation and coreference resolution; based on the code knowledge graph, the similarity between the subgraph of the impact range of the modified content of the program code of the tested software in the regression test and the subgraph of the regression test coverage range is calculated through a subgraph search algorithm and a similarity assessment technology, and the regression test quality assessment value is obtained by normalizing the similarity through a preset weight. Efficient regression testing is achieved, and objective evaluation of the quality of regression testing is achieved.
[0090] Figure 7 The main module schematic diagram of the regression test quality assessment device based on the code knowledge graph provided in the embodiment of the present application is shown. For the convenience of explanation, only the part related to the embodiment of the present application is shown, which is described in detail as follows:
[0091] A regression test quality assessment device 200 based on code knowledge graph, comprising:
[0092] A model design module 201 is used to design a code ontology model, wherein the code ontology model includes code entities, code entity attributes and code entity relationships;
[0093] A model building module 202 is used to extract code entities, code entity attributes and code entity relationships in the source code of the tested software based on the code ontology model, and perform knowledge fusion on the code entities, code entity attributes and code entity relationships in the source code to obtain a code knowledge graph of the source code, wherein the knowledge fusion includes entity disambiguation and coreference resolution;
[0094] The evaluation module 203 is used to calculate the similarity between the subgraph of the impact range of the modified content of the program code of the tested software in the regression test and the subgraph of the regression test coverage range based on the code knowledge graph, through a subgraph search algorithm and a similarity evaluation technology, and normalize the similarity through a preset weight to obtain a regression test quality evaluation value.
[0095] In addition, the description of the specific embodiments of the model design module 201, the model construction module 202 and the evaluation module 203 of the regression test quality assessment device 200 based on the code knowledge graph in the embodiment of the present application is the same as the description of the regression test quality assessment method based on the code knowledge graph in the embodiment of the present application, and will not be repeated here.
[0096] Therefore, the regression test quality assessment device based on code knowledge graph provided in the embodiment of the present application realizes efficient regression testing and objectively evaluates the quality of regression testing.
[0097] An embodiment of the present application also provides an electronic device, including: one or more processors; a storage device for storing one or more programs, when the one or more programs are executed by one or more processors, the one or more processors implement the regression test quality assessment method based on the code knowledge graph of the embodiment of the present application.
[0098] An embodiment of the present application also provides a computer-readable medium on which a computer program is stored. When the program is executed by a processor, the regression test quality assessment method based on the code knowledge graph of the embodiment of the present application is implemented.
[0099] Figure 8 An exemplary system architecture 300 is shown to which a method or apparatus for regression test quality assessment based on a code knowledge graph according to an embodiment of the present application can be applied.
[0100] like Figure 8 As shown, the system architecture 300 may include terminal devices 301, 302, 303, a network 304 and a server 305. The network 304 is used to provide a medium for communication links between the terminal devices 301, 302, 303 and the server 305. The network 304 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0101] Users can use terminal devices 301, 302, 303 to interact with server 305 through network 304 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 301, 302, 303, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc.
[0102] The terminal devices 301 , 302 , and 303 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers, etc.
[0103] The server 305 may be a server providing various services, such as a background management server providing support for the messages sent by the users using the terminal devices 301, 302, 303. The background management server may perform analysis and other processing after receiving the request of the terminal device, and feed back the processing result to the terminal device.
[0104] It should be noted that the regression test quality assessment method based on the code knowledge graph provided in the embodiment of the present application is generally executed by the terminal device 301, 302, 303 or the server 305. Accordingly, the regression test quality assessment device based on the code knowledge graph is generally arranged in the terminal device 301, 302, 303 or the server 305.
[0105] It should be understood that Figure 8 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0106] Reference below Fig. 9 , which shows a schematic diagram of the structure of a computer system 400 suitable for implementing an electronic device of an embodiment of the present application. Fig. 9 The computer system 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.
[0107] like Fig. 9 As shown, the computer system 400 includes a central processing unit (CPU) 401, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 402 or a program loaded from a storage part 408 into a random access memory (RAM) 403. In the RAM 403, various programs and data required for the operation of the system 400 are also stored. The CPU 401, the ROM 402, and the RAM 403 are connected to each other via a bus 404. An input / output (I / O) interface 405 is also connected to the bus 404.
[0108] The following components are connected to the I / O interface 405: an input section 406 including a keyboard, a mouse, etc.; an output section 407 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 408 including a hard disk, etc.; and a communication section 409 including a network interface card such as a LAN card, a modem, etc. The communication section 409 performs communication processing via a network such as the Internet. A drive 410 is also connected to the I / O interface 405 as needed. A removable medium 411, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 410 as needed, so that a computer program read therefrom is installed into the storage section 408 as needed.
[0109] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 409, and / or installed from the removable medium 411. When the computer program is executed by the central processing unit (CPU) 401, the above-mentioned functions defined in the system of the present application are executed.
[0110] It should be noted that the computer-readable medium shown in the present application may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present application, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0111] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the above-mentioned module, program segment or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0112] The modules involved in the embodiments described in the present application may be implemented by software or hardware. The modules described may also be set in a processor, for example, it may be described as: a processor includes a determination module, an extraction module, a training module and a screening module. The names of these modules do not constitute a limitation on the modules themselves in some cases, for example, the determination module may also be described as a "module for determining a candidate user set".
[0113] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
[0114] The above description is only the preferred embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
Claims
1. A regression test quality assessment method based on code knowledge graph, characterized in that: include: Design a code ontology model, wherein the code ontology model includes code entities, code entity attributes, and code entity relationships; Based on the code ontology model, code entities, code entity attributes and code entity relationships in the source code of the tested software are extracted, and knowledge fusion is performed on the code entities, code entity attributes and code entity relationships in the source code to obtain a code knowledge graph of the source code, wherein the knowledge fusion includes entity disambiguation and coreference resolution; Based on the code knowledge graph, the similarity between the subgraph of the impact range of the modified content of the program code of the tested software in the regression test and the subgraph of the regression test coverage range is calculated by using a subgraph search algorithm and a similarity evaluation technology, and the similarity is normalized by a preset weight to obtain a regression test quality evaluation value; The method, based on the code knowledge graph, calculates the similarity between the modified content impact range subgraph and the regression test coverage range subgraph of the program code of the tested software in the regression test through a subgraph search algorithm and a similarity evaluation technology, including: based on the code knowledge graph, generating a modified content impact range subgraph and a regression test coverage range subgraph of the program code of the tested software through a subgraph search algorithm, vectorizing the modified content impact range subgraph and the regression test coverage range subgraph to obtain corresponding impact range subgraph vectors and coverage range subgraph vectors, and calculating the similarity between the modified content impact range subgraph and the regression test coverage range subgraph according to the impact range subgraph vector and the coverage range subgraph vector; The method of generating a modified content impact range subgraph and a regression test coverage range subgraph of the program code of the tested software based on the code knowledge graph and through a subgraph search algorithm includes: querying the code entities related to the modified part of the program code of the tested software in the code knowledge graph, locating the part of the code content in the program code that is directly affected by the code entities related to the modified part, and diffusing along points and edges to obtain the modified content impact range subgraph; mapping the program code of the tested software to the code knowledge graph according to the program call relationship mapping path of the test data in the program code of the tested software in the code knowledge graph, and obtaining the regression test coverage range subgraph after combining and removing duplicates; Before vectorizing the modified content impact range subgraph and the regression test coverage range subgraph to obtain the corresponding impact range subgraph vector and coverage range subgraph vector, the method further includes: counting the fan-in values of the code entities of the modified content part in the program code of the tested software and calculating the fan-in coefficients; calculating the multi-hop associations between the modified code entities and other entities in the modified content impact range subgraph and the regression test coverage range subgraph; and calculating the similarity between the modified content impact range subgraph and the regression test coverage range subgraph based on the impact range subgraph vector and the coverage range subgraph vector, including: using the fan-in coefficient and the multi-hop association value of each code entity in the modified content part of the program code as the fan-in coefficient and the multi-hop association value of the modified content impact range subgraph and the regression test coverage range subgraph. The features of the nodes in the test coverage range subgraph are extracted to obtain the node vectors of the nodes in the modified content impact range subgraph and the regression test coverage range subgraph, and the inner product of the impact range subgraph vector and the node vector of the modified content impact range subgraph and the coverage range subgraph vector and the node vector of the regression test coverage range subgraph is calculated to obtain the similarity between the modified content impact range subgraph and the regression test coverage range subgraph; wherein the fan-in value represents the number of parent modules of the current code entity, the fan-in coefficient is equal to the fan-in value of the current code entity divided by the maximum fan-in value of all code entities, the multi-hop correlation represents the distance between two code entities, and the multi-hop correlation of the current code entity is equal to one divided by the distance between the current code entity and another code entity.
2. The regression test quality assessment method based on code knowledge graph according to claim 1 is characterized in that: The method of extracting code entities, code entity attributes and code entity relationships in the source code of the software under test based on the code ontology model includes: based on the code ontology model, taking the program address of the software under test as input, performing knowledge extraction through multi-file batch generation and traversal of abstract syntax trees to obtain the code entities, code entity attributes and code entity relationships in the source code of the software under test.
3. The regression test quality assessment method based on code knowledge graph according to claim 2 is characterized in that: When extracting the code entities, a unique identifier is set for each of the code entities. When parsing the code entity relationships and code attributes, the type of the code entity relationships and the name of the corresponding code entity and the unique identifier are recorded.
4. The regression test quality assessment method based on code knowledge graph according to any one of claims 1 to 3, characterized in that: After knowledge fusion is performed on the code entities, code entity attributes and code entity relationships in the source code, the method further includes: performing knowledge reasoning on the code entity relationships in the source code to obtain multi-dimensional code entity relationships of codes at different granularities in the source code.
5. A regression test quality assessment device based on code knowledge graph, characterized in that: include: A model design module, used to design a code ontology model, wherein the code ontology model includes code entities, code entity attributes and code entity relationships; A model building module is used to extract code entities, code entity attributes and code entity relationships in the source code of the tested software based on the code ontology model, and perform knowledge fusion on the code entities, code entity attributes and code entity relationships in the source code to obtain a code knowledge graph of the source code, wherein the knowledge fusion includes entity disambiguation and coreference resolution; An evaluation module is used to calculate the similarity between the subgraph of the impact range of the modified content of the program code of the tested software in the regression test and the subgraph of the regression test coverage range based on the code knowledge graph and through a subgraph search algorithm and a similarity evaluation technology, and to normalize the similarity through a preset weight to obtain a regression test quality evaluation value; The method, based on the code knowledge graph, calculates the similarity between the modified content impact range subgraph and the regression test coverage range subgraph of the program code of the tested software in the regression test through a subgraph search algorithm and a similarity evaluation technology, including: based on the code knowledge graph, generating a modified content impact range subgraph and a regression test coverage range subgraph of the program code of the tested software through a subgraph search algorithm, vectorizing the modified content impact range subgraph and the regression test coverage range subgraph to obtain corresponding impact range subgraph vectors and coverage range subgraph vectors, and calculating the similarity between the modified content impact range subgraph and the regression test coverage range subgraph according to the impact range subgraph vector and the coverage range subgraph vector; The method of generating a modified content impact range subgraph and a regression test coverage range subgraph of the program code of the tested software based on the code knowledge graph and through a subgraph search algorithm includes: querying the code entities related to the modified part of the program code of the tested software in the code knowledge graph, locating the part of the code content in the program code that is directly affected by the code entities related to the modified part, and diffusing along points and edges to obtain the modified content impact range subgraph; mapping the program code of the tested software to the code knowledge graph according to the program call relationship mapping path of the test data in the program code of the tested software in the code knowledge graph, and obtaining the regression test coverage range subgraph after combining and removing duplicates; Before vectorizing the modified content impact range subgraph and the regression test coverage range subgraph to obtain the corresponding impact range subgraph vector and coverage range subgraph vector, the method further includes: counting the fan-in values of the code entities of the modified content part in the program code of the tested software and calculating the fan-in coefficients; calculating the multi-hop associations between the modified code entities and other entities in the modified content impact range subgraph and the regression test coverage range subgraph; and calculating the similarity between the modified content impact range subgraph and the regression test coverage range subgraph based on the impact range subgraph vector and the coverage range subgraph vector, including: using the fan-in coefficient and the multi-hop association value of each code entity in the modified content part of the program code as the fan-in coefficient and the multi-hop association value of the modified content impact range subgraph and the regression test coverage range subgraph. The features of the nodes in the test coverage range subgraph are extracted to obtain the node vectors of the nodes in the modified content impact range subgraph and the regression test coverage range subgraph, and the inner product of the impact range subgraph vector and the node vector of the modified content impact range subgraph and the coverage range subgraph vector and the node vector of the regression test coverage range subgraph is calculated to obtain the similarity between the modified content impact range subgraph and the regression test coverage range subgraph; wherein the fan-in value represents the number of parent modules of the current code entity, the fan-in coefficient is equal to the fan-in value of the current code entity divided by the maximum fan-in value of all code entities, the multi-hop correlation represents the distance between two code entities, and the multi-hop correlation of the current code entity is equal to one divided by the distance between the current code entity and another code entity.
6. An electronic device, characterized in that: It includes a memory and a processor, wherein a computer program is stored in the memory, and when the computer program is executed by the processor, the processor executes the steps of the regression test quality assessment method based on code knowledge graph described in any one of claims 1 to 4.
7. A computer-readable storage medium, characterized in that: A computer program is stored on the computer-readable storage medium. When the computer program is executed by the processor, the processor executes the steps of the regression test quality assessment method based on code knowledge graph according to any one of claims 1 to 4.
Citation Information
Patent Citations
Defect positioning method and system based on code knowledge graph
CN115629760A
Software testing method and system, storage medium and electronic device
CN116383081A