Knowledge graph construction method and device for test execution path coverage, and equipment

CN123014111APending Publication Date: 2026-10-30BEIJING XUEDIRUANJIAN DEVELOPMENT CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611131726.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-07-28
Publication Date
2026-10-30

AI Technical Summary

Technical Problem

然而,这种存储方式缺乏路径层次结构,导致执行过程中产生的路径信息全部丢失,无法被后续执行复用

Benefits of technology

[0009]借由上述技术方案,本申请提供的一种面向测试执行路径覆盖的知识图谱构建方法、装置及设备,相比于现有技术,通过引入路径节点作为测试用例与代码节点之间的中间层,将二元覆盖关系扩展为用例、路径、代码或者分支三层多跳链路,能够使知识图谱表达现有覆盖率数据无法存储的路径层次结构信息,从而能够支持路径经验跨会话持久复用。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123014111A_ABST
    Figure CN123014111A_ABST
Patent Text Reader

Abstract

The application discloses a knowledge graph construction method and device for test execution path coverage, and relates to the technical field of automatic testing. The method comprises the following steps: obtaining first coverage insertion data after a test task is completed; based on paths in the first coverage insertion data and test cases involved in the test task, path nodes and case nodes are respectively constructed, and first-type relationship edges are constructed based on the path nodes and the case nodes; based on code, conditional branches and version information involved in the test task, code nodes, branch nodes and version nodes are respectively constructed, the path nodes are taken as intermediate nodes between the case nodes and the code nodes, the branch nodes and the version nodes, and second-type relationship edges are constructed; and according to the path nodes, the case nodes, the code nodes, the branch nodes and the version nodes, and the first-type relationship edges and the second-type relationship edges, a knowledge graph is constructed. The application can make the knowledge graph record path hierarchical structure information.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of automated testing technology, and in particular to a method, apparatus and device for constructing a knowledge graph for test execution path coverage. Background Technology

[0002] Automated testing can execute regression test cases in batches, and test case coverage is a core indicator for measuring the completeness of automation. It can intuitively reflect the scope of functional coverage, guide the supplementation of scripts, and reduce the risk of online defects.

[0003] Currently, after automated tests are completed, test reports and coverage data are output. Coverage data is typically stored using a binary mapping between test cases and lines of code. However, this storage method lacks a path hierarchy, resulting in the loss of all path information generated during execution, making it unusable in subsequent executions. Summary of the Invention

[0004] In view of this, this application provides a method, apparatus and device for constructing a knowledge graph for test execution path coverage. The main feature is that by introducing path nodes as an intermediate layer between test cases and code nodes, the knowledge graph can record path hierarchy information, thereby supporting the persistent reuse of path experience across sessions.

[0005] According to a first aspect of this application, a method for constructing a knowledge graph oriented towards test execution path coverage is provided, the method comprising: Obtain the first coverage instrumentation data after the test task is completed; Based on the paths in the first coverage instrumentation data and the test cases involved in the test task, path nodes and test case nodes are constructed respectively, and a first type of relationship edge is constructed based on the path nodes and the test case nodes; Based on the code, conditional branches, and version information involved in the test task, code nodes, branch nodes, and version nodes are constructed respectively, and the path node is used as the intermediate node between the test case node and the code node, the branch node, and the version node to construct a second type of relationship edge; A knowledge graph is constructed based on the path nodes, use case nodes, code nodes, branch nodes, and version nodes, as well as the first type of relationship edges and the second type of relationship edges.

[0006] According to a second aspect of this application, a knowledge graph construction apparatus for test execution path coverage is provided, the apparatus comprising: The acquisition unit is used to acquire the first coverage instrumentation data after the test task is completed; The construction unit is used to construct path nodes and test case nodes based on the paths in the first coverage instrumentation data and the test cases involved in the test task, and to construct a first type of relationship edge based on the path nodes and the test case nodes. The construction unit is further configured to construct code nodes, branch nodes, and version nodes based on the code, conditional branches, and version information involved in the test task, and to construct a second type of relation edge by using the path node as an intermediate node between the test case node and the code node, the branch node, and the version node. The construction unit is further configured to construct a knowledge graph based on the path node, the use case node, the code node, the branch node, and the version node, as well as the first type of relation edge and the second type of relation edge.

[0007] According to a third aspect of this application, a storage medium is provided on which a computer program is stored, which, when executed by a processor, implements the above-described knowledge graph construction method for test execution path coverage.

[0008] According to a fourth aspect of this application, an electronic device is provided, including a storage medium, a processor, and a computer program stored on the storage medium and executable on the processor, wherein the processor executes the program to implement the above-described knowledge graph construction method for test execution path coverage.

[0009] By utilizing the above technical solutions, this application provides a knowledge graph construction method, apparatus, and device for test execution path coverage. Compared with the prior art, by introducing path nodes as an intermediate layer between test cases and code nodes, the binary coverage relationship is extended to a three-layer multi-hop link of test cases, paths, code, or branches. This enables the knowledge graph to express path hierarchical structure information that cannot be stored by existing coverage data, thereby supporting the persistent reuse of path experience across sessions.

[0010] The above description is only an overview of the technical solution of this application. In order to better understand the technical means of this application and to implement it in accordance with the contents of the specification, and to make the above and other objects, features and advantages of this application more obvious and understandable, the following are specific embodiments of this application. Attached Figure Description

[0011] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings: Figure 1 The illustration shows a flowchart of a knowledge graph construction method for test execution path coverage provided in an embodiment of this application; Figure 2 A schematic diagram of the knowledge graph-based query method provided in an embodiment of this application is shown. Figure 3 This illustration shows a schematic diagram of a knowledge graph construction device for test execution path coverage provided in an embodiment of this application. Detailed Implementation

[0012] The present application will be described in detail below with reference to the accompanying drawings and embodiments. It should be noted that, unless otherwise specified, the embodiments and features described in the embodiments of the present application can be combined with each other.

[0013] The existing binary mapping storage method lacks a path hierarchy structure, which causes all path information generated during execution to be lost and cannot be reused in subsequent executions.

[0014] To address the aforementioned problems, embodiments of the present invention provide a method, apparatus, and device for constructing a knowledge graph oriented towards test execution path coverage, such as... Figure 1 As shown, the method includes: Step 10: Obtain the first coverage instrumentation data after the test task is completed.

[0015] Among them, the test task is the task of testing the functionality of the software version. The first coverage instrumentation data includes the path coverage information when the test task is executed. This path coverage information records the lines of code, conditional branches, code functions, etc. executed when the software program is running.

[0016] In this embodiment of the invention, after the test task is completed, coverage instrumentation technology is used to inject probe code into the source code or bytecode to collect first coverage instrumentation data. Then, path coverage information, such as the executed lines of code, conditional branches, and code functions, is extracted from the first coverage instrumentation data and used as input for knowledge graph construction.

[0017] The embodiments of the present invention are mainly applicable to knowledge graph construction and query scenarios oriented towards test execution path coverage. The execution subject of the embodiments of the present invention is a device or equipment capable of knowledge graph construction and query, which can be set on the server side.

[0018] Step 20: Based on the paths in the first coverage instrumentation data and the test cases involved in the test task, construct path nodes and test case nodes respectively, and construct a first type of relationship edge based on the path nodes and the test case nodes.

[0019] Among them, test case nodes represent test cases in test tasks, path nodes represent specific code execution path segments, and the first type of relationship edge includes the coverage relationship edge between test case nodes and path nodes.

[0020] In this embodiment of the invention, based on the paths involved in the path coverage information in the first coverage instrumentation data, corresponding path nodes and their corresponding attribute information are constructed. Each path corresponds to one path node, and the attribute information of the path node includes: path hash identifier, path length, and first coverage time, etc. Simultaneously, based on the test cases involved in the test task, corresponding test case nodes and their corresponding attribute information are constructed. Each test case corresponds to one test case node, and the attribute information of the test case node includes: unique test case identifier, test case description, module to which it belongs, most recent execution time, and historical execution pass rate, etc.

[0021] In addition, it is necessary to construct coverage edges between test case nodes and path nodes. During construction, based on the relevant paths reached during test case execution, coverage edges between test case nodes and path nodes are constructed, and these coverage edges are identified as the first type of relationship edges. Simultaneously, the sequence of code lines traversed by the path during test task execution is determined, and the hash value corresponding to this sequence of code lines is calculated. Based on the hash value, the path hash identifier corresponding to the path node is determined.

[0022] Among them, the coverage relationship edge between the test case node and the path node indicates that when the test case corresponding to the test case node is executed, it reaches the path corresponding to the path node. The attribute information of the coverage relationship edge includes the number of times it reaches the path, the success rate of reaching the path, the most recent time of reaching the path, and the number of newly covered rows generated during the coverage.

[0023] After each test case covers the path, the reach success rate is updated on a rolling basis, using the following formula: New success rate = (Old success rate × Historical attempts + Current result) / (Historical attempts + 1) Among them, the historical count is the cumulative number of times the test case has been executed and reached this path in history. The count is incremented by 1 each time the test case is scheduled to be executed. The current result is a binary value for this execution, which is 1 if the path is successfully reached and 0 if the path is not reached.

[0024] In this embodiment of the invention, the hash value of the code node sequence traversed by the path is used as the globally unique identifier of the path node. The same path node is automatically reused in different test batches for the same execution trajectory. Across sessions, only the reach statistics need to be accumulated, without the need for repeated creation.

[0025] Step 30: Based on the code, conditional branches, and version information involved in the test task, construct code nodes, branch nodes, and version nodes respectively, and use the path node as the intermediate node between the test case node and the code node, the branch node, and the version node to construct a second type of relationship edge.

[0026] Among them, code nodes represent code functions or code blocks, branch nodes represent conditional branches, version nodes represent code versions, and the second type of relationship edges include traversal relationship edges, trigger relationship edges, required relationship edges, change relationship edges, and adjacent relationship edges.

[0027] In this embodiment of the invention, based on the code functions or code blocks involved in the test task, corresponding code nodes and their corresponding attribute information are constructed. Each code function or code block corresponds to one code node, and the attribute information of the code node includes: function name, file location, line range, and module. Simultaneously, based on the conditional branches involved in the test task, corresponding branch nodes and their corresponding attribute information are constructed. Each conditional branch corresponds to one branch node, and the attribute information of the branch node includes: the function containing the branch, a natural language description of the branch condition, and the branch type. The branch type specifically includes conditional judgment, loops, and exception handling. Furthermore, based on the code version involved in the test task, corresponding version nodes and their corresponding attribute information are constructed. Each code version corresponds to one version node, and the attribute information of the version node includes: version number, commit time, and list of changed files.

[0028] Furthermore, it is also necessary to construct traversal relationship edges, trigger relationship edges, requirement relationship edges, change relationship edges, and adjacency relationship edges. During construction, based on the relevant code functions or code blocks traversed by the path during test task execution, traversal relationship edges are constructed between path nodes and code nodes; based on the relevant conditional branches triggered by the path during test task execution, trigger relationship edges are constructed between path nodes and branch nodes; based on the relevant test cases that the conditional branches depend on, requirement relationship edges are constructed between conditional nodes and test case nodes; and based on the relevant code that has changed in the code version corresponding to the test task, change relationship edges are constructed between code nodes and version nodes.

[0029] Among them, the "passing relationship edge" means that the path execution of the path node passed through the code function or code block corresponding to the code node; the "triggered relationship edge" means that the path execution of the path node triggered the condition branch corresponding to the branch node; the "need relationship edge" means that the branch condition corresponding to the condition node has historically depended on the set of test cases; the attributes of the "need relationship edge" include the success rate of reaching the condition; and the "change relationship edge" means that the code function or code block corresponding to the code node has changed in the code version corresponding to the version node.

[0030] Meanwhile, if any two path nodes are adjacent in code structure, an adjacency relationship edge is established between the two path nodes, and the passing relationship edge, triggering relationship edge, need relationship edge, change relationship edge, and adjacent relationship edge are determined as the second type of relationship edge.

[0031] When constructing the adjacency relationship edge, the code node sequences that have passed through the relationship edge with any two path nodes are determined. Then, the longest common subsequence corresponding to these two code node sequences is calculated. The longest common subsequence records the code nodes that exist in both code node sequences. At the same time, the shortest code node sequence is determined based on the length of the two code node sequences. Then, the length of the longest common subsequence and the length of the shortest code node sequence are divided to obtain the adjacency degree. If the adjacency degree is greater than or equal to the preset degree threshold, it is determined that any two path nodes are adjacent in code structure, and an adjacency relationship edge is established between any two path nodes.

[0032] For example, with a preset relation degree threshold of 0.5, any two path nodes pass through code node sequence A and code node sequence B respectively. The longest common subsequence corresponding to code node sequence A and code node sequence B is LCS. When the length of LCS / min(length of A, length of B) ≥ 0.5, it means that at least half of the nodes in the shorter of the two paths overlap. At this time, an adjacent relation edge is established between any two path nodes.

[0033] Existing systems cannot express the topological proximity of code paths, and path exploration lacks directionality. To address this, this invention introduces adjacent relationship edges between path nodes in the knowledge graph, which explicitly connects path pairs that share code prefixes or suffixes, thereby improving the efficiency of subsequent graph queries.

[0034] Step 40: Construct a knowledge graph based on the path nodes, use case nodes, code nodes, branch nodes, and version nodes, as well as the first type of relationship edges and the second type of relationship edges.

[0035] In this embodiment of the invention, after constructing path nodes, test case nodes, code nodes, branch nodes, and version nodes, as well as the coverage relationship edges between test case nodes and path nodes, the traversal relationship edges between path nodes and code nodes, the trigger relationship edges between path nodes and branch nodes, the requirement relationship edges between condition nodes and test case nodes, the change relationship edges between code nodes and version nodes, and the adjacency relationship edges between path nodes, the first construction of the knowledge graph for test execution path coverage is completed. This knowledge graph includes five types of nodes and six types of edges.

[0036] The knowledge graph constructed in this embodiment of the invention uses path nodes as the intermediate layer between use case nodes and code nodes. The path uses the hash value of the code line sequence as a unique identifier, thereby expanding the binary coverage relationship into a three-layer multi-hop association link of use cases, paths, and code / branch, forming a graph structure with significantly better expressive power than binary coverage tables.

[0037] In some embodiments, after the knowledge graph is constructed, real-time incremental construction of the knowledge graph can be performed for the execution of subsequent test tasks. Based on this, the method further includes: obtaining second coverage instrumentation data after the completion of a new test task; constructing corresponding new path nodes and new traversal relationship edges between the new path nodes and the related code nodes they pass through, based on the new paths in the second coverage instrumentation data; if there are test case nodes in the knowledge graph corresponding to the test cases involved in the new test task, updating the test case node attributes; if there are no test case nodes in the knowledge graph corresponding to the test cases involved in the new test task, creating corresponding new test case nodes and establishing coverage relationship edges between the new test case nodes and the related path nodes covered during the execution of the new test task; updating the required relationship edges between the branch nodes corresponding to the conditional branches triggered during the execution of the new test task and the related test case nodes; if the new test task involves a new code version, creating corresponding new version nodes and establishing the new traversal relationship edges between the new test case nodes and the related code nodes they pass through. The process involves: establishing a change relationship edge between the new version node and the modified code node; obtaining the first code node sequence corresponding to the new path node and the second code node sequence corresponding to any existing path node in the knowledge graph; calculating the longest common subsequence between the first and second code node sequences; determining the shortest code node sequence between the first and second code node sequences; calculating the adjacency degree between the new path node and any existing path node based on the longest common subsequence and the shortest code node sequence; and if the adjacency degree is greater than or equal to a preset adjacency degree threshold, determining that the new path node and any existing path node are adjacent in code structure, and establishing an adjacency relationship edge between the new path node and any existing path node to complete the incremental update of the knowledge graph.

[0038] The second coverage instrumentation data includes path coverage information when a new test task is executed. This path coverage information records the lines of code, conditional branches, and code functions executed during the execution of the software program.

[0039] Specifically, after a new test task is completed, second coverage instrumentation data is collected to perform incremental update operations. During the update operation, based on the second coverage instrumentation data, all new paths appearing during the test execution are identified. For each new path, a corresponding new path node is created in the existing knowledge graph, and a traversal relationship edge is established between the new path node and the related code nodes it passes through. Simultaneously, for each test case appearing during the test execution, if a corresponding test case node exists in the knowledge graph, the attributes of that test case node are updated; if no corresponding test case node exists, a new test case node is created, and a coverage relationship edge is established between this new test case node and the related path nodes actually covered during execution. The reach count and most recent reach time are also updated. Furthermore, for each conditional branch reached during the test execution, the required relationship edge between the corresponding branch node and the related test case node is updated, and the reach success rate is also updated. Moreover, if the test task involves a new code version, a corresponding new version node is created, and a change relationship edge is established between the changed code node and the new version node.

[0040] Furthermore, after the new path node is created, an adjacency edge is created between the new path node and existing path nodes in the knowledge graph. Specifically, a first code node sequence C that has an edge passing through the new path node and a second code node sequence D that has an edge passing through any existing path node are determined. The longest common subsequence between the first code node sequence C and the second code node sequence D, and the shortest code node sequence between the first code node sequence C and the second code node sequence D are determined. Then, the length of the longest common subsequence is divided by the length of the shortest code node sequence to obtain the adjacency degree between the new path node and any existing path node. If the adjacency degree is greater than or equal to a preset adjacency degree threshold, the new path node and any existing path node are determined to be adjacent in code structure, and an adjacency edge is established between them. If the adjacency degree is less than or equal to the preset adjacency degree threshold, the new path node and any existing path node are determined not to be adjacent in code structure, and no adjacency edge is established between them.

[0041] The preset relationship threshold can be set according to actual business needs. This embodiment of the invention does not impose specific limitations on it, such as setting the preset relationship threshold to 0.5.

[0042] It should be noted that the incremental updates in this embodiment of the invention can be written in a transactional manner to ensure the consistency of the map data.

[0043] In real-time incremental updates, this invention only compares newly created path nodes with existing nodes, eliminating the need for full reconstruction, thereby improving the efficiency of incremental updates to the knowledge graph. Furthermore, this invention defines adjacent edges between paths, using the degree of adjacency as a quantification criterion to display the topological proximity of the modeling code, enabling the knowledge graph to support directed path proximity expansion queries.

[0044] In some embodiments, as code versions iterate, the code corresponding to some historical paths has changed, requiring graph aging management. Based on this, the method further includes: determining a first target path node that passes through the changed code node; calculating a new weight corresponding to the first target path node based on the original weight and decay coefficient corresponding to the first target path node, and the cumulative number of versions of code nodes associated with the first target path node that have changed; if the new weight is less than a preset weight threshold, determining the status information of the first target path node as pending archiving; if changes are detected in the code nodes associated with the first target path node in a first preset number of consecutive versions, and the first target path node has not been reached by any test cases in the execution of a second preset number of recent versions, determining the status information of the first target path node as invalid.

[0045] The preset weight threshold, the first preset quantity, and the second preset quantity can be set according to actual business needs. This embodiment of the invention does not impose specific limitations on this. For example, the weight threshold can be set to 0.1, the first preset quantity to 3, and the second preset quantity to 5.

[0046] Specifically, for the first target path node where the code node has changed, its recommendation weight can be reduced according to the following formula. New weight = Original weight × decay^n Here, decay represents the decay coefficient, which can be set according to actual business needs, such as setting decay=0.8; n represents the cumulative number of versions of the code node associated with the first target path node that has undergone changes.

[0047] When the new weight is reduced to a preset weight threshold (e.g., 0.1), the first target path node is determined to enter the pending archiving state. It no longer participates in the main result set of the query recommendation, but the first target path node is still retained in the knowledge graph for structural reference query.

[0048] Furthermore, assuming a first preset quantity of 3 and a second preset quantity of 5, if any code node associated with the first target path node has been changed in 3 or more consecutive versions, and the first target path node has not been reached by any test cases in the execution of the last 5 versions, then the status information of the first target path node is determined to be invalid and archived. Thus, the weight of each first target path node can be updated in the above manner, and its corresponding status information can also be determined.

[0049] It should be noted that the aging management cycle of the graph can be set according to actual business needs, such as executing it every time a version is changed, or executing it at a preset time interval, or executing it after each test task is completed.

[0050] To prevent historical path data from becoming invalid and reducing the accuracy of the knowledge graph after code version iterations, this invention introduces version nodes and changed relationship edges, and automatically demotes the weight of path nodes whose code has been modified, marking long-term invalid paths as pending archiving. Simultaneously, version aging and incremental update writing are merged into a unified transaction process to maintain the timeliness of active graph data.

[0051] In some embodiments, a knowledge graph-based query interface is also provided for the scheduling module to call, for example, regarding the query and scheduling process. Figure 2 The above includes: Step 50: Perform information query based on the updated knowledge graph to obtain the graph query results and the path hash identifier, topological adjacency and new weight of the target path nodes involved in the query process.

[0052] The topological adjacency is determined by the number of adjacent path nodes that have an adjacent edge with the target path node. The target path node includes a first target path node, a second target path node, or a third target path node.

[0053] This invention provides three types of core query interfaces, which are used for querying historical valid use cases, querying code change impact domains, and expanding and recommending path nearest neighbors, respectively.

[0054] Based on the historical valid test case query interface, a historical valid test case query request is received. The historical valid test case query request includes a list of code nodes and / or branch nodes that were not covered after the completion of the new test task. Based on the list of code nodes and / or branch nodes that were not covered, the updated knowledge graph is queried to obtain a second target path node that reaches the code nodes and / or branch nodes that were not covered. A second target test case node that covers the second target path node is determined, as well as the success rate and average number of new lines of code that the second target test case node has historically reached the code nodes and / or branch nodes. When the second target test case node includes multiple second test case nodes, a comprehensive score is calculated based on the success rate and average number of new lines of code corresponding to the multiple second test case nodes, and the total number of lines of code corresponding to the new test task. Based on the comprehensive score, a first recommended test case list is determined. Based on the first recommended test case list, the success rate, and the average number of new lines of code, the knowledge graph query result is determined. The knowledge graph query result, as well as the path hash identifier, topological adjacency, and new weight corresponding to the second target path node, are output.

[0055] Specifically, based on the list of uncovered code nodes and / or branch nodes after the completion of a new test task, the updated knowledge graph is queried to find the identifiers of the second target path nodes that historically reached these nodes. Then, based on the second target path node identifiers, the second target use case nodes that cover the corresponding paths are identified. When the second target use case node includes multiple second use case nodes, the comprehensive score of each second use case node is calculated based on the success rate of each second use case node reaching uncovered code nodes and / or branch nodes and the average number of new lines of code. The specific formula is as follows. score(j) = w1 × success rate (j) + w2 × average number of new lines of code (j) / total number of lines of code Where j represents the j-th second use case node; score(j) represents the overall score of the j-th second use case node; w1 and w2 represent weights, which can be set according to actual business needs, such as setting w1 to 0.6 and w2 to 0.4.

[0056] Next, based on the comprehensive scores corresponding to the multiple second use case nodes, the nodes are sorted to obtain the first recommended use case list. Finally, the first recommended use case list, success rate, and average number of new lines of code are output as the graph query results. Along with these, the path hash identifier, topological adjacency, and new weight corresponding to the second target path node are also output. The topological adjacency is determined based on the number of adjacent path nodes with adjacent edges to the second target path node.

[0057] Based on the code change impact domain query interface, a code change impact domain query request is received, which includes a list of code node identifiers that have been changed. Based on the list of code node identifiers that have been changed, the updated knowledge graph is queried to obtain a first target path node that passes through the code node that has been changed. A first target use case node that covers the first target path node is determined. When the first target use case node includes multiple first use case nodes, the number of path nodes that pass through the code node that each first use case node covers is determined. Based on the number of path nodes, the association strength corresponding to each of the multiple first use case nodes is determined. Based on the association strength, the multiple first use case nodes are sorted, and a second recommended use case list is generated. Based on the second recommended use case list, the knowledge graph query result is determined. The knowledge graph query result, along with the path hash identifier, topological adjacency, and new weight corresponding to the first target path node, are output.

[0058] Specifically, based on the list of changed code node identifiers, the updated knowledge graph is queried to find the first target path nodes that pass through these changed code nodes. Then, the first target use case nodes that cover the first target path nodes are identified, thereby determining the set of use cases affected by the changes. When the first target use case node includes multiple first use case nodes, the association strength corresponding to each first use case node is determined. Specifically, the association strength corresponding to each first use case node is determined based on the number of path nodes that each first use case node covers that pass through the changed code nodes. Then, the multiple first use case nodes are sorted according to the association strength. Based on the sorting result, a second recommended use case list is generated. Finally, the second recommended use case list is output as the graph query result, along with the path hash identifier, topological adjacency, and new weight corresponding to the first target path node. The topological adjacency is determined based on the number of adjacent path nodes with adjacent edges to the first target path node.

[0059] Based on the path nearest neighbor extension recommendation interface, a path nearest neighbor extension recommendation request is received, the request including the path hash identifier corresponding to the path node to be queried; based on the path hash identifier, a breadth-first search algorithm is used to search the updated knowledge graph to determine neighboring path nodes, and these neighboring path nodes are identified as the third target path node; third target use case nodes covering the neighboring path nodes are determined, and a third recommended use case list is generated based on these third target use case nodes; based on the third recommended use case list, the graph query result is determined; and the graph query result, along with the path hash identifier, topological adjacency, and new weight corresponding to the third target path node, are output.

[0060] Specifically, based on the path hash identifier corresponding to the path node to be queried, the knowledge graph is queried to find neighboring path nodes (third target path nodes) that highly overlap with the path node in the code node sequence. Then, third target use case nodes that can cover these neighboring path nodes are found. During the search, a breadth-first search algorithm is used. Starting from the path node to be queried, the algorithm traverses along the adjacent relationship edges in a breadth-first manner. At each level, all use case nodes corresponding to neighboring path nodes in that level are collected. The number of levels can be configured according to actual business needs, such as 1-2 levels. Then, based on the third target use case nodes, a third recommended use case list is generated to explore the uncovered areas around the path node to be queried. Finally, the third recommended use case list is output as the graph query result. The output also includes the path hash identifier, topological adjacency, and new weight corresponding to the third target use case node. The topological adjacency is determined based on the number of neighboring path nodes with adjacent relationship edges to the third target path node.

[0061] This invention, by introducing path nodes as an intermediate layer between test cases and code nodes, constructs a knowledge graph that supports the persistent reuse of path experience across sessions. Compared to scheduling from scratch each time, this improves coverage ramp-up speed by over 40% in the early stages of execution. Simultaneously, the graph structure storage makes path association query efficiency far superior to linear logs; for test cases of hundreds of thousands, the response time for critical path queries is in the millisecond range. Furthermore, this invention also features code change impact domain analysis capabilities, significantly improving the accuracy of test case selection for incremental regression testing and reducing the execution of irrelevant test cases.

[0062] Step 60: Inject the graph query results, the path hash identifier, topological adjacency, and new weight corresponding to the target path node into the newly added path knowledge graph recommendation block in the prompt words in the form of structured natural language, so that the scheduling execution engine can make scheduling decisions based on the graph query results.

[0063] In this embodiment of the invention, when constructing scheduling decision prompts, a new path knowledge graph recommendation block is added. The query results corresponding to the three types of query interfaces, along with the path hash identifier, topological adjacency, and new weights corresponding to the target path nodes, are injected into the prompts in structured natural language. An example of the format is shown below. Based on the historical execution path knowledge graph, the following use cases have historically effectively covered areas that are currently not covered: Use Case [XX]: Historically, the exception branch in the function checkUserLevel() has been successfully reached with a success rate of 85%, and an average of 12 new lines have been added and covered. Use case [YY]: Historically, path segments adjacent to the current gap have been covered; it is recommended to try this first. Please refer to the above historical experience and consider the current coverage status when deciding on the batch to be executed in this round.

[0064] Furthermore, the scheduling execution engine makes the final scheduling decision based on the graph query results. The graph query results provide structured path knowledge (such as which code nodes or branch nodes can be reached by which test cases in the past), and the scheduling execution engine is responsible for making a comprehensive judgment.

[0065] It should be noted that the query interface outputs standardized structured data, which can be connected to any scheduling execution engine. The large language model is only one of the optional scheduling decision execution components.

[0066] Furthermore, the embodiments of this invention inject graph query results and the path hash identifier, topological adjacency, and new weights corresponding to the target path nodes. This belongs to graph-structured path knowledge, which is a different level of knowledge source from the scheduling behavior experience base. The knowledge graph is static structural knowledge, while the triples are dynamic decision-making experience; the two can be used in parallel without substituting for each other. The scheduling behavior experience base records triggering conditions, scheduling decisions, and coverage benefits. That is, after each scheduling, it stores the circumstances, the decision made, and the benefits obtained as triples for reference during subsequent scheduling.

[0067] The graph query result injection in this embodiment of the invention provides the scheduling decision engine with structured path knowledge. Both the rule engine and the AI ​​model can achieve directed path exploration rather than random traversal based on fields such as path hash identifiers, topological adjacency, and new weights, thus accelerating coverage convergence. Furthermore, unlike traditional coverage tools that only output a flat format of a list of covered or uncovered lines of code, this embodiment defines a dedicated output format carrying hierarchical path information, including fields such as a list of recommended use cases, success rate, path hash identifiers, topological adjacency, and new weights. These fields are not present in ordinary coverage APIs. Based on these fields, this embodiment allows the downstream scheduling engine to obtain a structured basis for "why this use case is recommended," rather than a black-box ranking. In addition, the interface protocol of this embodiment is decoupled from the scheduling decision engine, allowing it to interface with rule engines, heuristic algorithms, or any AI scheduling component.

[0068] This invention provides a knowledge graph construction method for test execution path coverage. By introducing path nodes as an intermediate layer between test cases and code nodes, the binary coverage relationship is extended to a three-layer multi-hop link of test cases, paths, code, or branches. This enables the knowledge graph to express path hierarchical structure information that cannot be stored by existing coverage data, thereby supporting the persistent reuse of path experience across sessions.

[0069] Furthermore, as Figure 1 and Figure 2The specific implementation of the method shown in this embodiment provides a knowledge graph construction device for test execution path coverage, such as... Figure 3 As shown, the device includes an acquisition unit 101 and a construction unit 102.

[0070] The acquisition unit 101 can be used to acquire the first coverage instrumentation data after the test task is completed.

[0071] The construction unit 102 can be used to construct path nodes and test case nodes based on the paths in the first coverage instrumentation data and the test cases involved in the test task, and to construct a first type of relationship edge based on the path nodes and the test case nodes.

[0072] The construction unit 102 can also be used to construct code nodes, branch nodes and version nodes based on the code, condition branches and version information involved in the test task, and use the path node as the intermediate node between the test case node and the code node, the branch node and the version node to construct a second type of relationship edge.

[0073] The construction unit 102 can also be used to construct a knowledge graph based on the path node, the use case node, the code node, the branch node, and the version node, as well as the first type of relationship edge and the second type of relationship edge.

[0074] In some embodiments, the construction unit 102 may be specifically used to construct a coverage relationship edge between the test case node and the path node based on the relevant path reached when the test case is executed, and determine the coverage relationship edge as the first type of relationship edge; determine the code line sequence traversed by the path when the test task is executed, and calculate the hash value corresponding to the code line sequence; and determine the path hash identifier corresponding to the path node based on the hash value.

[0075] The construction unit 102 can also be specifically used to construct traversal relationship edges between the path nodes and the code nodes based on the relevant code functions or code blocks traversed by the path when the test task is executed; construct trigger relationship edges between the path nodes and the branch nodes based on the relevant conditional branches triggered by the path when the test task is executed; construct requirement relationship edges between the conditional nodes and the test case nodes based on the relevant test cases that the conditional branches depend on; construct change relationship edges between the code nodes and the version nodes based on the relevant code that has changed in the code version corresponding to the test task; if any two path nodes are adjacent in code structure, then establish an adjacency relationship edge between the two path nodes; and determine the traversal relationship edges, the trigger relationship edges, the requirement relationship edges, the change relationship edges, and the adjacency relationship edges as the second type of relationship edges.

[0076] In some embodiments, the apparatus further includes an updating unit.

[0077] The update unit can be used to obtain the second coverage instrumentation data after the completion of the new test task; based on the new path in the second coverage instrumentation data, construct the corresponding new path node and the traversal relationship edge between the new path node and the related code nodes it passes through; if there is a test case node corresponding to the test case involved in the new test task in the knowledge graph, then update the test case node attributes; if there is no test case node corresponding to the test case involved in the new test task in the knowledge graph, then create the corresponding new test case node and establish the coverage relationship edge between the new test case node and the related path nodes covered when the new test task is executed; update the requirement relationship edge between the branch node corresponding to the conditional branch triggered when the new test task is executed and the related test case node; if the new test task involves a new code version, then create the corresponding new version node and establish the new version node. The algorithm identifies the change relationship edges between version nodes and modified code nodes; obtains the first code node sequence corresponding to the new path node and the second code node sequence corresponding to any existing path node in the knowledge graph; calculates the longest common subsequence between the first and second code node sequences; determines the shortest code node sequence between the first and second code node sequences; calculates the adjacency degree between the new path node and any existing path node based on the longest common subsequence and the shortest code node sequence; if the adjacency degree is greater than or equal to a preset adjacency degree threshold, it determines that the new path node and any existing path node are adjacent in code structure, and establishes an adjacency relationship edge between the new path node and any existing path node to complete the incremental update of the knowledge graph.

[0078] In some embodiments, the apparatus further includes a management unit.

[0079] The management unit can be used to determine the first target path node that passes through the modified code node; calculate the new weight corresponding to the first target path node based on the original weight and attenuation coefficient corresponding to the first target path node, and the cumulative number of versions of the code node associated with the first target path node that has undergone changes; if the new weight is less than a preset weight threshold, then the status information of the first target path node is determined to be pending archiving; if the code node associated with the first target path node has been detected to have changed in a first preset number of consecutive versions, and the first target path node has not been touched by any test cases in the execution of a second preset number of recent versions, then the status information of the first target path node is determined to be invalid.

[0080] In some embodiments, the apparatus further includes a query unit and a scheduling unit.

[0081] The query unit can be used to perform information queries based on the updated knowledge graph, obtain graph query results and path hash identifiers, topological adjacency and new weights corresponding to the target path nodes involved in the query process, wherein the topological adjacency is determined by the number of adjacent path nodes that have adjacent edges with the target path node.

[0082] The scheduling unit can be used to inject the graph query results, the path hash identifier, topological adjacency, and new weight corresponding to the target path node into the newly added path knowledge graph recommendation block in the prompt words in the form of structured natural language, so that the scheduling execution engine can make scheduling decisions based on the graph query results.

[0083] In some embodiments, when the target path node includes a second target path node, the query unit may be specifically configured to receive a historical valid test case query request, the historical valid test case query request including a list of code nodes and / or branch nodes that were not covered after the completion of the new test task; based on the list of code nodes and / or branch nodes that were not covered, query the updated knowledge graph to obtain a second target path node that reaches the code nodes and / or branch nodes that were not covered; determine a second target test case node that covers the second target path node, and the success rate and average number of new lines of code that the second target test case node has historically reached the code nodes and / or branch nodes that were not covered; when the second target test case node includes multiple second test case nodes, calculate a comprehensive score corresponding to each of the multiple second test case nodes based on the success rate and average number of new lines of code corresponding to the multiple second test case nodes, and the total number of lines of code corresponding to the new test task; determine a first recommended test case list based on the comprehensive score; determine the graph query result based on the first recommended test case list, the success rate and the average number of new lines of code; and output the graph query result and the path hash identifier, topological adjacency and new weight corresponding to the second target path node.

[0084] In some embodiments, when the target path node includes a first target path node, the query unit may further be configured to receive a code change impact domain query request, the code change impact domain query request including a list of code node identifiers that have been changed; query the updated knowledge graph based on the list of code node identifiers that have been changed to obtain the first target path node that passes through the code node that has been changed; determine a first target use case node that covers the first target path node; when the first target use case node includes multiple first use case nodes, determine the number of path nodes that pass through the code node that are covered by each first use case node; determine the association strength corresponding to the multiple first use case nodes based on the number of path nodes; sort the multiple first use case nodes based on the association strength and generate a second recommended use case list; determine the graph query result based on the second recommended use case list; and output the graph query result and the path hash identifier, topological adjacency, and new weight corresponding to the first target path node.

[0085] In some embodiments, when the target path node includes a third target path node, the query unit may further be configured to receive a path neighbor expansion recommendation request, the path neighbor expansion recommendation request including a path hash identifier corresponding to the path node to be queried; based on the path hash identifier corresponding to the path node to be queried, use a breadth-first search algorithm to search the updated knowledge graph, determine neighboring path nodes, and determine the neighboring path nodes as the third target path node; determine third target use case nodes covering the neighboring path nodes, and generate a third recommended use case list based on the third target use case nodes; determine the graph query result based on the third recommended use case list; and output the graph query result and the path hash identifier, topological adjacency, and new weight corresponding to the third target path node.

[0086] It should be noted that other corresponding descriptions of the functional units involved in the knowledge graph construction device for test execution path coverage provided in this embodiment of the invention can be found in the following references. Figure 1 and Figure 2 The corresponding description in [the document] will not be repeated here.

[0087] Based on the above, Figure 1 and Figure 2 Accordingly, this embodiment also provides a storage medium storing a computer program that, when executed by a processor, implements the above-described method. Figure 1 and Figure 2 The method shown is for constructing a knowledge graph that covers test execution paths.

[0088] Based on this understanding, the technical solution of this application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (such as CD-ROM, USB flash drive, mobile hard drive, etc.) and includes several instructions to cause an electronic device (such as personal computer, server, or network device, etc.) to execute the methods of various implementation scenarios of this application.

[0089] Based on the above, Figure 1 and Figure 2 The method shown, and Figure 3 To achieve the above objectives, the present application also provides an electronic device, specifically a personal computer, tablet computer, server, or other network device, as shown in the virtual device embodiment. This device includes a storage medium and a processor; the storage medium stores a computer program; the processor executes the computer program to achieve the above-described objectives. Figure 1 and Figure 2 The method shown is for constructing a knowledge graph that covers test execution paths.

[0090] Optionally, the aforementioned physical devices may also include a user interface, a network interface, a camera, radio frequency (RF) circuitry, sensors, audio circuitry, a Wi-Fi module, etc. The user interface may include a display screen, input units such as a keyboard, etc., and optional user interfaces may also include USB interfaces, card reader interfaces, etc. The network interface may optionally include standard wired interfaces, wireless interfaces (such as Wi-Fi interfaces), etc.

[0091] Those skilled in the art will understand that the physical device structure provided in this embodiment does not constitute a limitation on the physical device, and may include more or fewer components, or combine certain components, or have different component arrangements.

[0092] The storage medium may also include an operating system and a network communication module. The operating system is a program that manages the hardware and software resources of the aforementioned physical device, supporting the operation of information processing programs and other software and / or programs. The network communication module is used to enable communication between the various components within the storage medium, as well as communication with other hardware and software in the information processing physical device.

[0093] Through the above description of the embodiments, those skilled in the art can clearly understand that this application can be implemented by means of software plus necessary general-purpose hardware platform, or it can be implemented by hardware.

[0094] This invention expands the binary coverage relationship into a three-layer multi-hop link of test cases, paths, code, or branches by introducing path nodes as an intermediate layer between test cases and code nodes. This enables the knowledge graph to express path hierarchical structure information that cannot be stored by existing coverage data, thereby supporting the persistent reuse of path experience across sessions.

[0095] Those skilled in the art will understand that the accompanying drawings are merely schematic diagrams of a preferred embodiment, and the modules or processes shown in the drawings are not necessarily essential for implementing this application. Those skilled in the art will understand that the modules in the apparatus of the embodiment can be distributed within the apparatus of the embodiment as described, or can be modified to be located in one or more apparatuses different from this embodiment. The modules of the above-described embodiment can be combined into one module, or further divided into multiple sub-modules.

[0096] The serial numbers in this application are for descriptive purposes only and do not represent the superiority or inferiority of any particular implementation scenario. The above disclosures are merely a few specific implementation scenarios of this application; however, this application is not limited thereto, and any variations conceived by those skilled in the art should fall within the protection scope of this application.

Claims

1. A method for constructing a knowledge graph oriented towards test execution path coverage, characterized in that, include: Obtain the first coverage instrumentation data after the test task is completed; Based on the paths in the first coverage instrumentation data and the test cases involved in the test task, path nodes and test case nodes are constructed respectively, and a first type of relationship edge is constructed based on the path nodes and the test case nodes; Based on the code, conditional branches, and version information involved in the test task, code nodes, branch nodes, and version nodes are constructed respectively, and the path node is used as the intermediate node between the test case node and the code node, the branch node, and the version node to construct a second type of relationship edge; A knowledge graph is constructed based on the path nodes, use case nodes, code nodes, branch nodes, and version nodes, as well as the first type of relationship edges and the second type of relationship edges.

2. The method according to claim 1, characterized in that, The construction of the first type of relationship edge based on the path node and the use case node includes: Based on the relevant paths reached during the execution of the test cases, a coverage relationship edge is constructed between the test case node and the path node, and the coverage relationship edge is determined as the first type of relationship edge; Determine the sequence of code lines traversed by the path during the execution of the test task, and calculate the hash value corresponding to the sequence of code lines; Based on the hash value, determine the path hash identifier corresponding to the path node; The step of using the path node as an intermediate node between the use case node and the code node, the branch node, and the version node to construct a second type of relationship edge includes: Based on the relevant code functions or code blocks traversed by the path during the execution of the test task, construct the traversal relationship edges between the path nodes and the code nodes; Based on the relevant conditional branches triggered by the path when the test task is executed, construct the trigger relationship edges between the path nodes and the branch nodes; Based on the relevant test cases that the conditional branch depends on, construct the requirement relationship edge between the conditional node and the test case node; Based on the relevant code changes in the code version corresponding to the test task, construct change relationship edges between the code node and the version node; If any two path nodes are adjacent in code structure, then an adjacency edge is established between the two path nodes. The edges that pass through the relationship, the edges that trigger the relationship, the edges that require the relationship, the edges that change the relationship, and the edges that are adjacent to the relationship are identified as the second type of relationship edges.

3. The method according to claim 2, characterized in that, The method further includes: Obtain the second coverage instrumentation data after the new test task is completed; Based on the new path in the second coverage instrumentation data, construct the corresponding new path node and the traversal relationship edge between the new path node and the related code node it passes through; If the knowledge graph contains test case nodes corresponding to the test cases involved in the new test task, then the test case node attributes are updated. If there is no test case node in the knowledge graph corresponding to the test case involved in the new test task, then a corresponding new test case node is created, and a coverage relationship edge is established between the new test case node and the relevant path nodes covered when the new test task is executed. Update the required relationship edge between the branch node corresponding to the condition branch triggered when the new test task is executed and the relevant test case node; If the new test task involves a new code version, then create a corresponding new version node and establish a change relationship edge between the new version node and the changed code node; Obtain the first code node sequence corresponding to the new path node, and the second code node sequence corresponding to any existing path node in the knowledge graph; Calculate the longest common subsequence between the first code node sequence and the second code node sequence; Determine the shortest code node sequence between the first code node sequence and the second code node sequence; Based on the longest common subsequence and the shortest code node sequence, calculate the adjacency degree between the new path node and any existing path node; If the adjacency degree is greater than or equal to a preset adjacency degree threshold, then the new path node is determined to be adjacent to any existing path node in terms of code structure, and an adjacency edge is established between the new path node and any existing path node to complete the incremental update of the knowledge graph.

4. The method according to claim 3, characterized in that, The method further includes: Determine the first target path node that passes through the modified code node; Based on the original weight and decay coefficient corresponding to the first target path node, and the cumulative number of versions of the code node associated with the first target path node that has changed, calculate the new weight corresponding to the first target path node. If the new weight is less than the preset weight threshold, then the status information of the first target path node is determined to be pending archiving; If the code node associated with the first target path node has been changed in all of the first preset number of consecutive versions, and the first target path node has not been reached by any test cases in the execution of the most recent second preset number of versions, then the status information of the first target path node is determined to be invalid.

5. The method according to claim 3, characterized in that, The method further includes: Information is queried based on the updated knowledge graph to obtain the graph query results and the path hash identifier, topological adjacency and new weight of the target path node involved in the query process. The topological adjacency is determined by the number of adjacent path nodes that have an adjacent relationship with the target path node. The graph query results, along with the path hash identifier, topological adjacency, and new weights corresponding to the target path nodes, are injected into the newly added path knowledge graph recommendation block in the prompt words in the form of structured natural language, so that the scheduling execution engine can make scheduling decisions based on the graph query results.

6. The method according to claim 5, characterized in that, When the target path node includes a second target path node, the information query based on the updated knowledge graph to obtain the graph query results and the path hash identifier, topological adjacency, and new weights corresponding to the target path nodes involved in the query process includes: Receive a historical valid test case query request, which includes a list of code nodes and / or branch node identifiers that were not covered after the completion of the new test task; Based on the list of uncovered code nodes and / or branch nodes, query the updated knowledge graph to obtain a second target path node that reaches the uncovered code nodes and / or branch nodes; Determine the second target use case node that covers the second target path node, and the success rate and average number of new lines of code that the second target use case node has historically reached the uncovered code nodes and / or branch nodes; When the second target test case node includes multiple second test case nodes, the comprehensive score corresponding to each of the multiple second test case nodes is calculated based on the success rate and average number of new lines of code corresponding to the multiple second test case nodes, and the total number of lines of code corresponding to the new test task. Based on the comprehensive score, a first recommended use case list is determined; The graph query result is determined based on the first recommended use case list, the success rate, and the average number of new lines of code. Output the graph query results and the path hash identifier, topological adjacency, and new weight corresponding to the second target path node.

7. The method according to claim 5, characterized in that, When the target path node includes the first target path node, the information query based on the updated knowledge graph to obtain the graph query result and the path hash identifier, topological adjacency, and new weight of the target path node involved in the query process includes: Receive a code change impact domain query request, the code change impact domain query request including a list of code node identifiers that have been changed; Based on the list of changed code node identifiers, query the updated knowledge graph to obtain the first target path node that passes through the changed code node; Determine the first target use case node that covers the first target path node; When the first target use case node includes multiple first use case nodes, determine the number of path nodes covered by the modified code node for each first use case node; Based on the number of path nodes, the association strength corresponding to each of the plurality of first use case nodes is determined; Based on the association strength, the plurality of first use case nodes are sorted, and a second recommended use case list is generated; Based on the second recommended use case list, the graph query result is determined; Output the graph query results, as well as the path hash identifier, topological adjacency, and new weight corresponding to the first target path node.

8. The method according to claim 5, characterized in that, When the target path node includes a third target path node, the information query based on the updated knowledge graph to obtain the graph query result and the path hash identifier, topological adjacency, and new weight of the target path nodes involved in the query process includes: Receive a path nearest neighbor expansion recommendation request, wherein the path nearest neighbor expansion recommendation request includes the path hash identifier corresponding to the path node to be queried; Based on the path hash identifier corresponding to the path node to be queried, the breadth-first search algorithm is used to search the updated knowledge graph, determine the neighboring path nodes, and determine the neighboring path nodes as the third target path node; Identify a third target use case node that covers the adjacent path nodes, and generate a third recommended use case list based on the third target use case node; Based on the third recommended use case list, the graph query results are determined; Output the graph query results and the path hash identifier, topological adjacency, and new weight corresponding to the third target path node.

9. A knowledge graph construction device for test execution path coverage, characterized in that, include: The acquisition unit is used to acquire the first coverage instrumentation data after the test task is completed; The construction unit is used to construct path nodes and test case nodes based on the paths in the first coverage instrumentation data and the test cases involved in the test task, and to construct a first type of relationship edge based on the path nodes and the test case nodes. The construction unit is further configured to construct code nodes, branch nodes, and version nodes based on the code, conditional branches, and version information involved in the test task, and to construct a second type of relation edge by using the path node as an intermediate node between the test case node and the code node, the branch node, and the version node. The construction unit is further configured to construct a knowledge graph based on the path node, the use case node, the code node, the branch node, and the version node, as well as the first type of relation edge and the second type of relation edge.

10. A storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the method of any one of claims 1 to 8.

11. An electronic device, comprising a storage medium, a processor, and a computer program stored on the storage medium and executable on the processor, characterized in that, When the processor executes the computer program, it implements the method of any one of claims 1 to 8.