Interface test case generation method based on double-layer graph network
By using an interface test case generation method based on a two-layer graph network, the agent automatically constructs an association graph and generates test cases, solving the problem of low test coverage in traditional testing and achieving efficient and accurate automated testing.
Patent Information
- Application Number
- CN202510981050.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-16
- Publication Date
- 2025-10-28
- Estimated Expiration
- 2045-07-16
AI Technical Summary
Traditional manual testing struggles to meet the demands of rapid software iteration, automated testing has low coverage, and AI agents fail to effectively generate interface automation test data and code during automated testing.
A two-layer graph network-based approach is adopted, which establishes connections with the system database and interface management tools through intelligent agents, constructs table-table association graphs and interface-table association graphs, and automatically generates interface test cases by utilizing node comprehensive importance evaluation indicators and test case generation strategies.
Automated test cases can be written automatically without the need for manual input, ensuring test accuracy and coverage, and improving test efficiency and quality.
Smart Images

Figure CN120849285A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of software testing technology, specifically relating to a method for generating interface test cases based on a two-layer graph network. Background Technology
[0002] In the field of software development, ensuring software quality is paramount, but traditional manual testing is no longer sufficient to meet the demands of rapid iteration. Therefore, artificial intelligence (AI) technology has been introduced into the field of automated testing, bringing about revolutionary changes. AI agents, as concrete implementations of AI, can simulate human intelligence, perform autonomous learning and decision-making, improve test coverage, enhance requirements understanding, and simulate real user operations. The application of AI agents in automated testing lays a solid foundation for building high-quality software and promotes the intelligent transformation of software quality management. Summary of the Invention
[0003] The problem this invention aims to solve is to achieve automated generation of interface test data and code, and proposes an interface test case generation method based on a two-layer graph network.
[0004] To achieve the above objectives, the present invention provides the following technical solution:
[0005] A method for generating interface test cases based on a two-layer graph network includes the following steps:
[0006] S1. Use the Model Context Protocol (MCP) to establish a connection between the agent and the database of the system under test. The agent obtains the database name, table name, field information and foreign key relationship information.
[0007] S2. Based on the data obtained by the agent in step S1, construct a table-table relationship graph;
[0008] S3. The agent uses the model context protocol to establish a connection with the interface management tool and the interface call log tool to obtain static interface information, dynamic interface information, interface composition information and usage information;
[0009] S4. Based on the data obtained by the agent in step S3, construct the interface-table association graph;
[0010] S5. Merge the table-table relationship diagram obtained in step S2 with the interface-table relationship diagram obtained in step S4 to form an interface relationship diagram;
[0011] S6. Develop comprehensive importance evaluation metrics for nodes and a test case generation strategy;
[0012] S7. Based on the node comprehensive importance evaluation index set in step S6, identify important nodes in the interface relationship graph obtained in step S5. According to the test case generation strategy, obtain all important interface paths according to the graph structure traversal algorithm, and generate test cases corresponding to all important interface paths.
[0013] Furthermore, in step S2, the nodes in the table-to-table association graph represent table names or field information attributes in the database, and the edges between nodes in the table-to-table association graph represent foreign key relationships; the specific implementation method is as follows:
[0014] S2.1. The intelligent agent identifies basic information in the database and generates SQL query statements;
[0015] S2.2. The intelligent agent identifies foreign key constraints and constructs a table-to-table relationship graph by using SQL query statements to query the database. It then uses a graph database to store and query the table-to-table relationship graph.
[0016] Furthermore, the specific implementation method of step S3 includes the following steps:
[0017] S3.1. Intelligent agent connection interface management tool, which extracts interface parameters, return values, and request path metadata from the OpenAPI specification;
[0018] S3.2. Intelligent agent connection interface call log tool to analyze the actual call status of the interface of the tested system and extract parameter values, response status, call frequency and interface call correlation information.
[0019] Furthermore, the nodes in the interface-table association graph of step S4 are the API interfaces in the system, including URLs, parameters, and return values. The edges between the nodes in the interface-table association graph represent the database tables operated on by the interfaces, including the following steps:
[0020] S4.1. The intelligent agent, combining interface parameters and address information from the interface management tool, obtains the operation database table. Through similarity analysis between interface parameter names and database field names, a mapping relationship is established. The mapping relationship formula is:
[0021] cosine(y q , y d )=
[0022] Among them, y q The quantized value of the parameter carried by the interface, y d This represents the quantified value of a field in the table, cosine(y q , y d ) represents the cosine of the quantized value of the interface parameter and the quantized value of the field in the table;
[0023] T represents the matrix transpose operation;
[0024] S4.2. The agent combines the interface call log and the database change log to infer the content of the interface's operation on the database.
[0025] Furthermore, step S5 uses Dijkstra's algorithm to infer the shortest association path between different interfaces. The nodes in the interface association graph are API interfaces, and the edges between nodes represent the database tables being operated on.
[0026] Furthermore, the specific implementation method of step S6 includes the following steps:
[0027] S6.1. Develop a comprehensive importance evaluation index S(v) for nodes, using degree centrality, betweenness centrality, and node ranking to comprehensively evaluate the importance of nodes. The expression is:
[0028] S(v) = α*C D (v)+β*C B (v)+γ*PR(v)
[0029] Where α, β, and γ are the degree centrality C D (v) Betweenness centrality C B The weighting coefficients for node ranking PR(v) are set to α=0.3, β=0.4, and γ=0.3.
[0030] S6.2. Formulate a test case generation strategy: Sort by S(v) in descending order and select the top 20% of nodes as core nodes; then sort by the importance of the core nodes, design a hierarchical traversal algorithm, prioritize traversing the branches of high-priority core nodes, and record the traversal path.
[0031] The beneficial effects of this invention are:
[0032] The present invention discloses an interface test case generation method based on a two-layer graph network, which eliminates the need for manual writing of automated test cases. The method includes request variables and test data involved in the script, ensuring the accuracy and coverage of the test. Attached Figure Description
[0033] Figure 1 This is a flowchart of an interface test case generation method based on a two-layer graph network as described in this invention. Detailed Implementation
[0034] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are only for explaining the invention and are not intended to limit the invention; that is, the described specific embodiments are merely a part of the embodiments of the invention, and not all of them. The components of the specific embodiments of the invention described and shown in the accompanying drawings can generally be arranged and designed in various different configurations, and the invention may also have other embodiments.
[0035] Therefore, the following detailed description of specific embodiments of the invention provided in the accompanying drawings is not intended to limit the scope of the claimed invention, but merely to illustrate selected specific embodiments of the invention. All other specific embodiments obtained by those skilled in the art based on these specific embodiments without inventive effort are within the scope of protection of this invention.
[0036] To further understand the invention's content, features, and effects, the following specific embodiments are provided, along with accompanying drawings. Figure 1 The detailed instructions are as follows:
[0037] Example 1:
[0038] A method for generating interface test cases based on a two-layer graph network includes the following steps:
[0039] S1. Use the Model Context Protocol (MCP) to establish a connection between the agent and the database of the system under test. The agent obtains the database name, table name, field information and foreign key relationship information.
[0040] S2. Based on the data obtained by the agent in step S1, construct a table-table relationship graph;
[0041] Furthermore, in step S2, the nodes in the table-to-table association graph represent table names or field information attributes in the database, and the edges between nodes in the table-to-table association graph represent foreign key relationships; the specific implementation method is as follows:
[0042] S2.1. The intelligent agent identifies basic information in the database and generates SQL query statements;
[0043] S2.2. The intelligent agent identifies foreign key constraints and constructs a table-to-table relationship graph by using SQL query statements to query the database. It then uses a graph database to store and query the table-to-table relationship graph.
[0044] S3. The agent uses the model context protocol to establish a connection with the interface management tool and the interface call log tool to obtain static interface information, dynamic interface information, interface composition information and usage information;
[0045] Furthermore, the specific implementation method of step S3 includes the following steps:
[0046] S3.1. Intelligent agent connection interface management tool, which extracts interface parameters, return values, and request path metadata from the OpenAPI specification;
[0047] S3.2. Intelligent agent connection interface call log tool to analyze the actual call status of the interface of the tested system and extract parameter values, response status, call frequency and interface call correlation information.
[0048] S4. Based on the data obtained by the agent in step S3, construct the interface-table association graph;
[0049] Furthermore, the nodes in the interface-table association graph of step S4 are the API interfaces in the system, including URLs, parameters, and return values. The edges between the nodes in the interface-table association graph represent the database tables operated on by the interfaces, including the following steps:
[0050] S4.1. The intelligent agent, combining interface parameters and address information from the interface management tool, obtains the operation database table. Through similarity analysis between interface parameter names and database field names, a mapping relationship is established. The mapping relationship formula is:
[0051] cosine(y q , y d )=
[0052] Among them, y q The quantized value of the parameter carried by the interface, y d This represents the quantified value of a field in the table, cosine(y q , y d ) represents the cosine of the quantized value of the interface parameter and the quantized value of the field in the table;
[0053] T represents the matrix transpose operation;
[0054] Furthermore, for example, the createOrder interface carries a userId parameter, which is the user_id field in the user table;
[0055] S4.2. The agent combines the interface call log and the database change log to infer the content of the interface's operation on the database.
[0056] S5. Merge the table-table relationship diagram obtained in step S2 with the interface-table relationship diagram obtained in step S4 to form an interface relationship diagram;
[0057] Furthermore, step S5 uses Dijkstra's algorithm to infer the shortest path between different interfaces. In the interface association graph, nodes represent API interfaces, and edges between nodes represent database tables being operated on. The shorter the path, the stronger the business relationship between the interfaces.
[0058] Furthermore, for example, the following diagram structure: User Table (Table) → Order Table (Table) ← CreateOrder (API) → Payment Table (Table) → Account Table (Table); the interface relationship diagram is as follows: FindUser (API) → User Table (Table) → Order Table (Table) → CreateOrder (API);
[0059] S6. Develop comprehensive importance evaluation metrics for nodes and a test case generation strategy;
[0060] Furthermore, the specific implementation method of step S6 includes the following steps:
[0061] S6.1. Develop a comprehensive importance evaluation index S(v) for nodes, using degree centrality, betweenness centrality, and node ranking to comprehensively evaluate the importance of nodes. The expression is:
[0062] S(v) = α*C D (v)+β*C B (v)+γ*PR(v)
[0063] Where α, β, and γ are the degree centrality C D (v) Betweenness centrality C B The weighting coefficients for node ranking PR(v) are set to α=0.3, β=0.4, and γ=0.3.
[0064] C D (v) = d in / d out
[0065] Where, d in d is the number of edges pointing to node v. out This represents the number of edges originating from node v.
[0066] C B (v)=∑ s≠v≠t σ st (v) / σ st
[0067] Where, σ st Let σ be the number of shortest paths from node s to node t. st (v) represents the number of shortest paths passing through node v;
[0068] PR(v)=(1−d)+d∑ u∈In(v) PR(u) / out(u)
[0069] Wherein, the damping coefficient d is 0.85, In(v) is the set of incoming edge nodes, out(u) is the number of outgoing edges of node u, and PR(u) is the PR value of node u;
[0070] S6.2. Formulate a test case generation strategy: Sort by S(v) in descending order and select the top 20% of nodes as core nodes; then sort by the importance of the core nodes, design a hierarchical traversal algorithm, prioritize traversing the branches of high-priority core nodes, and record the traversal path.
[0071] S7. Based on the node comprehensive importance evaluation index set in step S6, identify important nodes in the interface relationship graph obtained in step S5. According to the test case generation strategy, obtain all important interface paths according to the graph structure traversal algorithm, and generate test cases corresponding to all important interface paths.
[0072] Furthermore, test cases for processes such as: User registration → Order creation → Payment → Shipment → Confirmation of receipt.
[0073] It should be noted that relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0074] Although this application has been described above with reference to specific embodiments, various modifications can be made and components can be replaced with equivalents without departing from the scope of this application. In particular, as long as there is no structural conflict, the features in the specific embodiments disclosed in this application can be combined with each other in any way. The lack of an exhaustive description of these combinations in this specification is merely for the sake of brevity and resource conservation. Therefore, this application is not limited to the specific embodiments disclosed herein, but includes all technical solutions falling within the scope of the claims.
Claims
1. A method for generating interface test cases based on a two-layer graph network, characterized in that, Includes the following steps: S1. Use the Model Context Protocol (MCP) to establish a connection between the agent and the database of the system under test. The agent obtains the database name, table name, field information and foreign key relationship information. S2. Based on the data obtained by the agent in step S1, construct a table-table relationship graph; S3. The agent uses the model context protocol to establish a connection with the interface management tool and the interface call log tool to obtain static interface information, dynamic interface information, interface composition information and usage information; S4. Based on the data obtained by the agent in step S3, construct the interface-table association graph; S5. Merge the table-table relationship diagram obtained in step S2 with the interface-table relationship diagram obtained in step S4 to form an interface relationship diagram; S6. Develop comprehensive importance evaluation metrics for nodes and a test case generation strategy; S7. Based on the node comprehensive importance evaluation index set in step S6, identify important nodes in the interface relationship graph obtained in step S5. According to the test case generation strategy, obtain all important interface paths according to the graph structure traversal algorithm, and generate test cases corresponding to all important interface paths.
2. The method for generating interface test cases based on a two-layer graph network according to claim 1, characterized in that, In step S2, the nodes in the table-to-table association graph represent table names or field information attributes in the database, and the edges between nodes in the table-to-table association graph represent foreign key relationships; the specific implementation method is as follows: S2.
1. The intelligent agent identifies basic information in the database and generates SQL query statements; S2.
2. The intelligent agent identifies foreign key constraints and constructs a table-to-table relationship graph by using SQL query statements to query the database. It then uses a graph database to store and query the table-to-table relationship graph.
3. The method for generating interface test cases based on a two-layer graph network according to claim 2, characterized in that, The specific implementation method of step S3 includes the following steps: S3.
1. Intelligent agent connection interface management tool, which extracts interface parameters, return values, and request path metadata from the OpenAPI specification; S3.
2. Intelligent agent connection interface call log tool to analyze the actual call status of the interface of the tested system and extract parameter values, response status, call frequency and interface call correlation information.
4. The method for generating interface test cases based on a two-layer graph network according to claim 3, characterized in that, The nodes in the interface-table association graph of step S4 are the API interfaces in the system, including URLs, parameters, and return values. The edges between the nodes in the interface-table association graph represent the database tables operated on by the interfaces, including the following steps: S4.
1. The intelligent agent, combining interface parameters and address information from the interface management tool, obtains the operation database table. Through similarity analysis between interface parameter names and database field names, a mapping relationship is established. The mapping relationship formula is: kitchen(and q , and d )= Among them, y q The quantized value of the parameter carried by the interface, y d This represents the quantified value of a field in the table, cosine(y q , y d ) represents the cosine of the quantized value of the interface parameter and the quantized value of the field in the table; T represents the matrix transpose operation; S4.
2. The agent combines the interface call log and the database change log to infer the content of the interface's operation on the database.
5. The method for generating interface test cases based on a two-layer graph network according to claim 4, characterized in that, Step S5 uses Dijkstra's algorithm to infer the shortest path between different interfaces. The nodes in the interface association graph are API interfaces, and the edges between nodes represent the database tables being operated on.
6. The method for generating interface test cases based on a two-layer graph network according to claim 5, characterized in that, The specific implementation method of step S6 includes the following steps: S6.
1. Develop a comprehensive importance evaluation index S(v) for nodes, using degree centrality, betweenness centrality, and node ranking to comprehensively evaluate the importance of nodes. The expression is: S(v)=α*C D (v)+β*C B (v)+γ*PR(v) Where α, β, and γ are the degree centrality C D (v) Betweenness centrality C B The weighting coefficients for node ranking PR(v) are set to α=0.3, β=0.4, and γ=0.
3. S6.
2. Formulate a test case generation strategy: Sort by S(v) in descending order and select the top 20% of nodes as core nodes; then sort by the importance of the core nodes, design a hierarchical traversal algorithm, prioritize traversing the branches of high-priority core nodes, and record the traversal path.
Citation Information
Patent Citations
Complex network theory based software test use-case generating method
CN105068928A
Interface testing method, device and equipment based on association feature analysis and medium
CN113900936A
Test case generation method, device and equipment
CN115328756A
Case information generation method and device, electronic equipment, medium and program product
CN116521540A
Automatic generation management method and system for test cases
CN119807058A