Digraph generation method and device, test case generation method and device, equipment and medium

By generating a function reference relationship diagram between the object code functions and determining the function combination function, the automatic generation of directed graphs is realized, solving the problem of low efficiency of directed graph generation in the prior art, and improving the efficiency and accuracy of the application field.

CN119621531APending Publication Date: 2025-03-14GUANGZHOU SHIZHEN INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311127460.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-09-01
Publication Date
2025-03-14

AI Technical Summary

Technical Problem

The existing technology is difficult to efficiently generate directed graphs, resulting in inefficient application in areas such as software testing and project solution solutions.

Method used

By determining the function reference relationship between the object code functions, a function reference relationship diagram is generated, and the function combination function is determined through natural language processing, thereby automatically generating a directed graph.

Benefits of technology

The automatic generation of directed graphs is realized, the generation efficiency of directed graphs is improved, labor costs are reduced, and the generated directed graphs can accurately cover code function calls, improving the generation efficiency and accuracy of test cases.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119621531A_ABST
    Figure CN119621531A_ABST
Patent Text Reader

Abstract

The invention provides a directed graph generation method and device, a test case generation method and device, electronic equipment and a computer readable storage medium, and relates to the technical field of software testing, the method comprises the following steps: determining a function reference relationship among a plurality of target code functions to obtain a function reference relationship graph; determining the function of each function combination in the function reference relation graph; wherein the function combination comprises at least one target code function; and according to the function reference relation graph and the function functions of the function combinations, generating a directed graph about the multiple target code functions. According to the method, the directed graph can be automatically generated, the generation efficiency of the directed graph is improved, and the labor cost is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of software testing technology, and more specifically, to a directed graph generation method, a test case generation method, an apparatus, an electronic device, and a computer-readable storage medium in the field of software testing technology. Background Art

[0002] A directed graph is a graph structure that consists of a set of nodes and a set of directed edges. Each edge has a starting point and an end point, and has a specified direction. Directed graphs can be used to represent various relationships and processes, and are widely used in many fields (such as computer science, network analysis, social network analysis, logistics planning, engineering design, software engineering, etc.) to assist in solving project solutions. However, the premise of solving project solutions through directed graphs is that the directed graphs need to be generated in advance. Therefore, how to generate directed graphs has become a problem that needs to be solved urgently. Summary of the invention

[0003] The present application provides a directed graph generation method, a test case generation method, an apparatus, an electronic device and a computer-readable storage medium. The method can realize automatic generation of directed graphs, improve the generation efficiency of directed graphs and reduce labor costs.

[0004] In a first aspect, a directed graph generation method is provided, the directed graph generation method comprising: determining a function reference relationship between multiple target code functions to obtain a function reference relationship graph; determining function functions of each function combination in the function reference relationship graph; wherein the function combination comprises at least one target code function; and generating a directed graph regarding multiple target code functions according to the function reference relationship graph and the function functions of each function combination.

[0005] In combination with the first aspect, in some possible implementations, determining the functional functions of each function combination in the function reference relationship diagram includes: performing natural language processing on the code annotations and / or code semantics of the target code functions in each function combination to obtain the functional functions of each function combination.

[0006] In combination with the first aspect and the above-mentioned implementation methods, in some possible implementation methods, generating a directed graph about multiple target code functions according to the function reference relationship graph and the function functions of each function combination includes: determining the first target code function in the function reference relationship graph; using the function functions of each function combination as the annotation of the first target code function to obtain the first node N1 of the directed graph; according to the first node N1 and the function reference relationship, determining other nodes Ni of the directed graph and the directed edges between each node from the function reference relationship graph; wherein i is greater than or equal to 2; generating a directed graph according to the first node N1, other nodes Ni and the directed edges.

[0007] In combination with the first aspect and the above-mentioned implementation methods, in some possible implementation methods, based on the first node N1 and the function reference relationship, determining other nodes Ni of the directed graph and the directed edges between each node from the function reference relationship graph includes: determining other target code functions except the first target code function in the function reference relationship graph as other nodes Ni; determining the out-degree and in-degree of each node based on the function reference relationship; and determining the directed edges between each node based on the out-degree and in-degree.

[0008] In combination with the first aspect and the above-mentioned implementation methods, in some possible implementation methods, after generating a directed graph about multiple target code functions based on the function reference relationship graph and the functional functions of each function combination, the directed graph generation method also includes: obtaining the number of references of the target code function corresponding to each node in the directed graph; determining the popularity of the target code function corresponding to each node based on the number of references; wherein the number of references is positively correlated with the popularity; and marking the popularity for each node.

[0009] In combination with the first aspect and the above-mentioned implementation methods, in some possible implementation methods, the directed graph generation method also includes: determining the original code functions that support a preset development language among multiple original code functions as candidate code functions to obtain multiple candidate code functions; filtering the candidate code functions that are non-business code functions among the multiple candidate code functions to obtain multiple target code functions.

[0010] In a second aspect, a test case generation method is provided, the test case generation method comprising: determining a function to be tested; obtaining a target directed graph matching the function to be tested from a graph database; wherein the graph database comprises a plurality of directed graphs, the directed graphs are generated according to a directed graph generation method, and the function functions corresponding to the target directed graph comprise the function to be tested; based on a depth-first traversal rule and the degree of attention annotated on each node in the target directed graph, the target directed graph is traversed to generate a test case for the function to be tested.

[0011] In a third aspect, a directed graph generation device is provided, the directed graph generation device comprising:

[0012] A first determining module is used to determine a function reference relationship between multiple target code functions to obtain a function reference relationship graph;

[0013] A second determination module is used to determine the function of each function combination in the function reference relationship diagram; wherein the function combination includes at least one target code function;

[0014] The directed graph generation module is used to generate a directed graph about multiple target code functions according to the function reference relationship graph and the function functions of each function combination.

[0015] In combination with the third aspect, in some possible implementations, the second determination module is specifically used to perform natural language processing on the code annotations and / or code semantics of the target code functions in each function combination to obtain the functional functions of each function combination.

[0016] In combination with the third aspect and the above implementation, in some possible implementations, the directed graph generation module includes:

[0017] The first annotation unit is used to determine the first target code function in the function reference relationship graph; the function of each function combination is used as the annotation of the first target code function to obtain the first node N1 of the directed graph;

[0018] A computing unit, used to determine other nodes Ni of the directed graph and directed edges between each node from the function reference relationship graph according to the first node N1 and the function reference relationship; wherein i is greater than or equal to 2;

[0019] The generating unit is used to generate a directed graph according to the first node N1, other nodes Ni and directed edges.

[0020] In combination with the third aspect and the above-mentioned implementation methods, in some possible implementation methods, the computing unit is specifically used to determine other target code functions except the first target code function in the function reference relationship graph as other nodes Ni; determine the out-degree and in-degree of each node according to the function reference relationship; determine the directed edges between each node according to the out-degree and in-degree.

[0021] In combination with the third aspect and the above implementations, in some possible implementations, the directed graph generating device further includes:

[0022] The second labeling unit is used to obtain the number of citations of the target code function corresponding to each node in the directed graph; determine the popularity of the target code function corresponding to each node according to the number of citations; wherein the number of citations is positively correlated with the popularity; and label the popularity for each node.

[0023] In combination with the third aspect and the above implementations, in some possible implementations, the directed graph generating device further includes:

[0024] The function filtering unit is used to determine the original code functions that support the preset development language among multiple original code functions as candidate code functions to obtain multiple candidate code functions; and filter the candidate code functions that are non-business code functions among the multiple candidate code functions to obtain multiple target code functions.

[0025] In a fourth aspect, a test case generation device is provided, the test case generation device comprising:

[0026] A third determination module is used to determine the function to be tested;

[0027] A matching module is used to obtain a target directed graph matching the function to be tested from a graph database; wherein the graph database includes a plurality of directed graphs, the directed graphs are generated by the directed graph generation method described above, and the function function corresponding to the target directed graph includes the function to be tested;

[0028] The use case generation module is used to traverse the target directed graph based on the depth-first traversal rule and the attention degree marked on each node in the target directed graph to generate test cases for the functions to be tested.

[0029] In a fifth aspect, an electronic device is provided, comprising a memory and a processor. The memory is used to store an executable program code, and the processor is used to call and run the executable program code from the memory, so that the electronic device executes the directed graph generation method in the first aspect or any possible implementation of the first aspect or executes the test case generation method in the implementation of the second aspect.

[0030] In the sixth aspect, a computer program product is provided, which includes: a computer program code, which, when executed on a computer, enables the computer to execute the directed graph generation method in the first aspect or any possible implementation of the first aspect, or to execute the test case generation method in the implementation of the second aspect.

[0031] In the seventh aspect, a computer-readable storage medium is provided, which stores a computer program code. When the computer program code runs on a computer, the computer executes the directed graph generation method in the above-mentioned first aspect or any possible implementation of the first aspect, or executes the test case generation method in the implementation of the above-mentioned second aspect.

[0032] The embodiments of the present application provide a directed graph generation method, a test case generation method, a device, an electronic device, and a computer-readable storage medium, which have the following technical effects:

[0033] The embodiment of the present application adopts a method of determining the function reference relationship between multiple target code functions to obtain a function reference relationship graph, determining the function functions of each function combination in the function reference relationship graph, wherein the function combination includes at least one target code function, and generating a directed graph about multiple target code functions according to the function reference relationship graph and the function functions of each function combination. The technical solution can realize the automatic generation of directed graphs, improve the generation efficiency of directed graphs, and reduce labor costs. Test cases can be generated through directed graphs. Since the generated directed graphs are closely related to the code function calls, the codes can be accurately covered. The test cases generated through directed graphs are not only efficient but also accurate. BRIEF DESCRIPTION OF THE DRAWINGS

[0034] Figure 1 A schematic flow chart of a directed graph generation method provided in an embodiment of the present application is shown;

[0035] Figure 2 An exemplary schematic diagram of a function reference relationship diagram is shown;

[0036] Figure 3 Another exemplary schematic diagram showing a function reference relationship graph;

[0037] Figure 4 A schematic diagram of a directed graph is shown;

[0038] Figure 5 A schematic flow chart of a test case generation method provided in an embodiment of the present application is shown;

[0039] Figure 6 A schematic diagram showing a test case corresponding to the function to be tested;

[0040] Figure 7 A flow chart of a directed graph generation component provided in an embodiment of the present application generating a directed graph and a test case is shown;

[0041] Figure 8 A schematic diagram of the structure of a directed graph generating device provided in an embodiment of the present application is shown;

[0042] Fig. 9 A schematic diagram of the structure of a test case generation device provided in an embodiment of the present application is shown;

[0043] Fig.10 A schematic structural diagram of an electronic device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION

[0044] The technical solution in the present application will be described clearly and in detail below in conjunction with the accompanying drawings. In the description of the embodiments of the present application, unless otherwise specified, " / " means or, for example, A / B can mean A or B: "and / or" in the text is only a description of the association relationship of associated objects, indicating that there can be three relationships, for example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, in the description of the embodiments of the present application, "multiple" means two or more than two.

[0045] In the following, the terms "first" and "second" are used for descriptive purposes only and are not to be understood as suggesting or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the features.

[0046] The following is an embodiment of a directed graph generation method provided in an embodiment of the present application.

[0047] Figure 1 FIG. 1 is a schematic flow chart of a directed graph generation method provided in an embodiment of the present application. Figure 1 As shown, the directed graph generation method provided in the embodiment of the present application is applied to an electronic device, and the electronic device is, for example, a computer, a server, etc. The directed graph generation method includes the following schemes:

[0048] S110: Determine the function reference relationship between multiple target code functions to obtain a function reference relationship graph.

[0049] In an exemplary embodiment, multiple target code functions are obtained from a code repository. The process of obtaining multiple target code functions from a code repository includes: determining original code functions that support a preset development language from multiple original code functions as candidate code functions to obtain multiple candidate code functions; filtering candidate code functions that are non-business code functions from multiple candidate code functions to obtain multiple target code functions. It should be understood that multiple original code functions are obtained from a code repository, original code functions that do not support a preset development language from the original code functions are filtered, original code functions that support a preset development language are retained, and original code functions that support a preset development language are determined as candidate code functions to obtain multiple candidate code functions. Then, candidate code functions that are non-business code functions from multiple candidate code functions are filtered, and the candidate code functions retained from multiple candidate code functions are target code functions to obtain multiple target code functions. Among them, the preset development languages ​​include java, js, C++, Python, etc., and non-business code functions are, for example, log functions, etc.

[0050] After obtaining multiple target code functions, code static analysis is performed on the multiple target code functions to obtain the function reference relationship between the multiple target code functions. The function reference relationship can also be called the function call relationship. Among them, code static analysis is to analyze whether a function is called and what function calls it. It will also record the file name, class name, method name, method parameters, caller source code line number, method annotation, loop call, entry method, etc. The function call relationship is used to describe what other functions call a certain code function. For example, through the obtained function call relationship, it can be obtained that the target code function A is called by the target code function B.

[0051] After obtaining the function reference relationship, each target code function is used as a node, and multiple target code functions are connected according to the function reference relationship to obtain a function reference relationship graph, which is stored. The function reference relationship graph can also be understood as an initial directed graph about multiple target code functions.

[0052] like Figure 2 As shown, Figure 2 An exemplary schematic diagram of a function reference relationship diagram is shown. For example, multiple target code functions are: SrcClass.srcfunc(), ClassA1.funcA1(), ClassA2a.funcA2a(), ClassA2b.funcA2b(), ClassA3.funcA3(), ClassB1.funcB1(), Classc1.funcC1(), and ClassC2.funcC2(). The function reference relationship is: ClassA1.funcA1(), ClassB1.funcB1(), and Classc1.funcC1() are all called by SrcClass.srcfunc(), ClassA2afuncA2a(), ClassA2b.funcA2b() are all called by ClassA1.funcA1(), ClassA3.funcA3() are all called by ClassA2b.funcA2b(), and ClassC2.funcC2() is called by Classc1.funcC1(). Then, take each target code function as a node, connect the eight target code functions according to the function reference relationship, and get the function reference relationship diagram. Figure 2 .

[0053] S120: Determine the function of each function combination in the function reference relationship diagram.

[0054] After obtaining the function reference relationship graph, the function reference relationship graph includes multiple function combinations, and the function combination is formed by at least one target code function, that is, the function combination includes at least one target code function. The function functions of each function combination in the function reference relationship graph are determined, and the function functions are marked for each function combination, and the function functions marked for each function combination include at least one function.

[0055] In a possible implementation, the above S120, determining the function of each function combination in the function reference relationship graph, includes the following scheme:

[0056] Natural language processing is performed on the code comments and / or code semantics of the target code functions in each function combination to obtain the function functions of each function combination.

[0057] The code comments and / or code semantics of the target code functions in each function combination are processed by natural language processing (NLP) algorithm to achieve semantic analysis of the code comments and / or code semantics and obtain the function functions of each function combination. Figure 3 As shown, Figure 3 Another exemplary schematic diagram of a function reference relationship graph is shown, in which ClassA1.funcA1(), ClassA2a.funcA2a(), ClassA2b.funcA2b() and ClassA3.funcA3() are function combination 1, ClassB1.funcB1() is function combination 2, Classc1.funcC1() and ClassC2.funcC2() are function combination 3, and after semantic analysis of the target code functions in the above three function combinations through NLP algorithm processing, the function function of function combination 1 is "query and modify", the function function of function combination 2 is "register", and the function function of function combination 3 is "add".

[0058] S130: Generate a directed graph of multiple target code functions according to the function reference relationship graph and the functional functions of each function combination.

[0059] After obtaining the function functions of each function combination, a mapping relationship between the function combination and the function functions is formed. Each function combination corresponds to a corresponding function function. According to the function functions and the function reference relationship, the target code function as the first node N1 of the directed graph, the target code function as the other nodes Ni of the directed graph, and the directed edges between the nodes in the directed graph are determined from the function reference relationship graph. The directed edges include multiple directed edges, which are edges with directions and may also have a head and a tail. The directed edges of the directed edges are all connected to a node, and i is greater than or equal to 2. After obtaining the first node N1, other nodes Ni, and directed edges, the first node N1 and other nodes Ni are connected through the directed edges to obtain a directed graph about multiple target code functions.

[0060] In a possible implementation, the above S130, generating a directed graph of multiple target code functions according to the function reference relationship graph and the function functions of each function combination, includes the following scheme:

[0061] Determine the first target code function in the function reference graph;

[0062] The function of each function combination is used as the label of the first target code function to obtain the first node N1 of the directed graph;

[0063] According to the first node N1 and the function reference relationship, determine the directed edges between other nodes Ni and each node in the directed graph from the function reference relationship graph;

[0064] A directed graph is generated based on the first node N1, other nodes Ni, and directed edges.

[0065] After obtaining the function functions of each function combination, determine the first target code function in the function reference relationship graph, and use the function functions of each function combination as the annotation of the first target code function, that is, the first target code function carrying the annotation is used as the first node N1 of the directed graph. Figure 3 As shown, the first target code function in the function reference relationship diagram is SrcClass.srcfunc(), and the function functions of the three function combinations include query and modification, registration and addition. Then "query and modification, registration and addition" are used as the annotation of SrcClass.srcfunc(), that is, SrcClass.srcfunc() carrying the "query and modification, registration and addition" annotation is used as the first node N1 of the directed graph.

[0066] After obtaining the first node N1 of the directed graph, the other nodes Ni of the directed graph and the directed edges between the nodes are determined from the function reference relationship graph according to the first node N1 and the function reference relationship, and the first node N1, other nodes Ni and directed edges are stored in a matrix. The directed edges are drawn using a directed graph tool, that is, the first node N1 and other nodes Ni are connected through directed edges to obtain a directed graph about multiple target code functions, and the generated directed graph is stored in a graph database.

[0067] In a possible implementation, the above-mentioned method of determining other nodes Ni of the directed graph and directed edges between each node from the function reference relationship graph according to the first node N1 and the function reference relationship includes the following schemes:

[0068] Determine other target code functions except the first target code function in the function reference relationship graph as other nodes Ni;

[0069] According to the function reference relationship, determine the out-degree and in-degree of each node;

[0070] Based on the out-degree and in-degree, the directed edges between nodes are determined.

[0071] Since the first target code function in the function reference relationship graph is marked, the first target code function is the first node N1 of the directed graph, then the other target code functions except the first target code function in the function reference relationship graph are determined as other nodes Ni. Then, based on the function reference relationship, the out-degree and in-degree of each node in the first node N1 and other nodes Ni are calculated. For each node, the out-degree of the node represents the number of directed edges starting from the node, and also represents the number of edges starting from the node. The in-degree of the node represents the number of directed edges ending at the node, and also represents the number of edges pointing to the node. After obtaining the out-degree and in-degree of each node, the directed edges between each node can be calculated based on the out-degree and in-degree. For each node, the directed edges starting from the node and the directed edges pointing to the node can be obtained.

[0072] like Figure 4 As shown, Figure 4 A schematic diagram of a directed graph is shown. For example, the function reference relationship graph includes 7 target code functions, namely func, funcA1, funcA2a, funcA2b, funcA3, funcB1, funcC1 and funcC2, then the generated directed graph includes 8 nodes, the target code function of the first node N1 of the directed graph is func, the target code function of the second node N2 of the directed graph is funcA1, the target code function of the third node N3 of the directed graph is funcA2a, the target code function of the fourth node N4 of the directed graph is funcA2b, the target code function of the fifth node N5 of the directed graph is funcA3, the target code function of the sixth node N6 of the directed graph is funcB1, the target code function of the seventh node N7 of the directed graph is funcC1, and the target code function of the eighth node N8 of the directed graph is funcC2. The directed edges include: directed edge L1 from func to funcA1, directed edge L2 from funcA1 to funcA2a, directed edge L3 from funcA1 to funcA2b, directed edge L4 from funcA2b to funcA3, directed edge L5 from func to funcB1, directed edge L6 from func to funcC1, and directed edge L7 from funcC1 to funcC2. Connect nodes N1-N7 according to directed edge L1-directed edge L7 to obtain a directed graph about 7 target code functions. Since the first node N1 carries multiple function functions, the annotations carried by the first node N1 can be understood as the function sets of multiple target code functions. The function sets can be used to determine which function test cases the directed graph can generate.

[0073] Since the directed graph is generated based on the code functions in the code repository, when the code functions in the code repository are updated, such as new additions, the directed graph will also be automatically iterated and updated, with low maintenance costs.

[0074] In a possible implementation, after the above S130 generates a directed graph about multiple target code functions according to the function reference relationship graph and the function functions of each function combination, the directed graph generation method includes the following scheme:

[0075] Get the number of references of the target code function corresponding to each node in the directed graph;

[0076] Determine the attention level of the target code function corresponding to each node according to the number of citations; the number of citations is positively correlated with the attention level;

[0077] Label the popularity of each node.

[0078] The number of citations is obtained in the above-mentioned static code analysis process. The number of citations of the target code function corresponding to each node in the directed graph is used to calculate the popularity of the target code function corresponding to each node. The greater the number of citations, the greater the popularity, and the smaller the number of citations, the smaller the popularity. In one way, the number of citations can be used as the popularity. In another way, multiple citation intervals are set in advance, each citation interval corresponds to a preset popularity, and the preset popularity corresponding to all citation intervals is different.

[0079] After obtaining the number of citations of the target code function, determine the citation interval in which the citation number is located, so as to obtain the attention of the target code function, and then annotate the attention of the target code function. In this way, the target code function corresponding to each node in the directed graph is annotated with attention. When generating test cases through a directed graph, the attention affects the depth of the traversal path. The greater the attention of a node in a directed graph, the more frequently the target code function corresponding to the node is used, and more attention is needed, and the deeper the traversal path is; the smaller the attention of a node in a directed graph, the less frequently the target code function corresponding to the node is used, and the shallower the traversal path is.

[0080] The embodiment of the present application adopts a method of determining the function reference relationship between multiple target code functions to obtain a function reference relationship graph, determining the function functions of each function combination in the function reference relationship graph, wherein the function combination includes at least one target code function, and generating a directed graph about multiple target code functions according to the function reference relationship graph and the function functions of each function combination. The technical solution can realize the automatic generation of directed graphs, improve the generation efficiency of directed graphs, and reduce labor costs. Test cases can be generated through directed graphs. Since the generated directed graphs are closely related to the code function calls, the codes can be accurately covered. The test cases generated through directed graphs are not only efficient but also accurate.

[0081] The following is a directed graph application embodiment provided in an embodiment of the present application, namely, an embodiment of a test case generation method. Figure 5 FIG. 1 is a schematic flow chart of a test case generation method provided by an embodiment of the present application. Figure 5 As shown, the test case generation method provided in the embodiment of the present application is applied to an electronic device, and the test case generation method includes the following schemes:

[0082] S210: Determine the function to be tested;

[0083] S220: Obtain a target directed graph matching the function to be tested from a graph database;

[0084] S230: Based on the depth-first traversal rule and the attention degree marked on each node in the target directed graph, traverse the target directed graph to generate test cases for the function to be tested.

[0085] In an exemplary embodiment, the graph database includes a plurality of directed graphs, and the directed graphs are generated according to the directed graph generation method described above. The function to be tested refers to the function to be tested. After the function to be tested is determined, a target directed graph matching the function to be tested is obtained from the graph database, and the function corresponding to the target directed graph includes the function to be tested, that is, the function set marked by the first node of the target directed graph includes the function to be tested.

[0086] The process of the depth-first traversal rule is: first visit the node Nj (j=1,2,3,...,n) in the target directed graph, mark Nj as visited; check the adjacent nodes of Nj, select a node that has not been visited from the adjacent nodes, continue the depth-first search from it, and backtrack when there is no such adjacent node; repeat the above operation until all nodes starting from Nj have been visited.

[0087] If there are still unvisited nodes in the target directed graph, select an unvisited node and continue the previous process from it until all nodes in the target directed graph are searched. For each node marked with a popularity, nodes whose popularity is greater than the set threshold will be traversed, and nodes whose popularity is less than or equal to the set threshold will not be traversed. For example, if the popularity of the nodes corresponding to the function to be tested in the target directed graph is greater than the set threshold, then these nodes will be traversed. If the popularity of the nodes corresponding to the function to be tested in the target directed graph is less than or equal to the set threshold, then the traversal depth is the set depth, for example, 3 nodes in depth, that is, the traversal will stop if the nodes corresponding to the function to be tested in the target directed graph have not been traversed.

[0088] After obtaining the target directed graph, the depth-first traversal rule and the attention degree of each node in the target directed graph are used to traverse the target directed graph and generate test cases for the function to be tested. The generation process is as follows:

[0089] MBT (Model Based Testing) is used to automatically generate test cases based on the function directed graph model. First, the function set is generated as a unit (then the test cases can be expanded to be generated according to a certain function). The starting point of the function set (such as SrcClass.srcfunc()) is the first node (starting point) of the target directed graph. The edge of the starting point of the function set is a function point (such as ClassA1.funcA1). The edge from the function point to other nodes (such as ClassA2a.funcA2a) is a test case. The content of the vertex of the edge (such as ClassA1.funcA1) is the test step, and the content of the node pointed to (such as ClassA2a.funcA2a) is the expected result. If there is only a vertex but no edge (such as ClasB1.funcB1), the return of this code function is the test result. Since the content of the code function has been generated by NLP analysis of code comments and code semantics. In this way, test cases for all function sets are gradually generated along the target directed graph, so as to obtain test cases for the functions to be tested. After obtaining the test case, a download link of the test case is generated and provided to the user.

[0090] Figure 6 A schematic diagram of the test case corresponding to the function to be tested is shown, such as Figure 3 , Figure 4 and Figure 6As shown, for example, the function to be tested is "query and modification", and there is an edge under the function set pointing to a function combination of "query and modification", and the function function is a page display function. One of the two edges points to the query-related one to generate a query case, and the other edge points to the modification to generate a modification-related modification case, that is, the query case and the modification case are test cases for the function to be tested.

[0091] By using the directed graph generated by the directed graph generation method to generate test cases, the test case generation efficiency can be improved, and accurate test cases can be obtained, which is beneficial to improving the test efficiency and the test accuracy.

[0092] The following is an embodiment of a directed graph generation component provided in an embodiment of the present application. Figure 7 A flowchart of a directed graph generation component provided in an embodiment of the present application generating a directed graph and a test case is shown, such as Figure 7 As shown, the process of the directed graph generation component generating directed graphs and test cases is as follows:

[0093] S310: Obtaining the original code function from the code repository; specifically, in response to the code repository address, branch, whether to generate a use case flag, and whether to generate a function diagram flag input by the user (such as: repository address: https: / / github.com / xxx / xxx.git; branch: develop; whether to generate a use case: yes; whether to generate a function diagram: no), the code repository address obtains the original code function from the code repository;

[0094] S312: Filtering the functions that do not support the preset development language and are non-business code functions in the original code functions to obtain multiple target code functions;

[0095] S314: Perform code static analysis on multiple target code functions, obtain function reference relationships between the multiple target code functions, generate a function reference relationship graph, and store the function reference relationship;

[0096] S316: Determine the function of each function combination in the function reference relationship diagram;

[0097] S318: generating a directed graph of multiple target code functions according to the function reference relationship graph and the function functions of each function combination, and storing the directed graph;

[0098] S320: Whether to generate test cases using the directed graph; if yes, generate the test cases, provide a download link for viewing, and store the test cases; if no, provide a download link for viewing.

[0099] The embodiment of the present application can realize the automatic generation of directed graphs through the directed graph generation component, improve the generation efficiency of directed graphs, and reduce labor costs. Test cases can be generated through directed graphs. Since the generated directed graphs are closely related to code function calls, the code can be accurately covered. The test cases generated by directed graphs are not only efficient but also accurate. In addition, the directed graphs generated by the component can be automatically iterated and updated, and the maintenance cost is low.

[0100] The following is an embodiment of the device of the present application, which can be used to execute the embodiment of the method of the present application. For details not disclosed in the embodiment of the device of the present application, please refer to the embodiment of the method of the present application.

[0101] Figure 8 FIG. 1 shows a schematic diagram of a structure of a directed graph generating device provided in an embodiment of the present application. Figure 8 As shown, the directed graph generating device 800 includes:

[0102] A first determining module 810 is used to determine a function reference relationship between multiple target code functions to obtain a function reference relationship graph;

[0103] The second determination module 820 is used to determine the function of each function combination in the function reference relationship diagram; wherein the function combination includes at least one target code function;

[0104] The directed graph generation module 830 is used to generate a directed graph about multiple target code functions according to the function reference relationship graph and the functional functions of each function combination.

[0105] In a possible implementation, the second determination module 820 is specifically configured to perform natural language processing on the code annotations and / or code semantics of the target code functions in each function combination to obtain the function functions of each function combination.

[0106] In a possible implementation, the directed graph generation module 830 includes:

[0107] The first annotation unit is used to determine the first target code function in the function reference relationship graph; the function of each function combination is used as the annotation of the first target code function to obtain the first node N1 of the directed graph;

[0108] A computing unit, used to determine other nodes Ni of the directed graph and directed edges between each node from the function reference relationship graph according to the first node N1 and the function reference relationship; wherein i is greater than or equal to 2;

[0109] The generating unit is used to generate a directed graph according to the first node N1, other nodes Ni and directed edges.

[0110] In a possible implementation, the computing unit is specifically used to determine other target code functions except the first target code function in the function reference relationship graph as other nodes Ni; determine the out-degree and in-degree of each node according to the function reference relationship; and determine the directed edges between each node according to the out-degree and in-degree.

[0111] In a possible implementation, the directed graph generating device 800 further includes:

[0112] The second labeling unit is used to obtain the number of citations of the target code function corresponding to each node in the directed graph; determine the popularity of the target code function corresponding to each node according to the number of citations; wherein the number of citations is positively correlated with the popularity; and label the popularity for each node.

[0113] In a possible implementation, the directed graph generating device 800 further includes:

[0114] The function filtering unit is used to determine the original code functions that support the preset development language among multiple original code functions as candidate code functions to obtain multiple candidate code functions; and filter the candidate code functions that are non-business code functions among the multiple candidate code functions to obtain multiple target code functions.

[0115] It should be noted that when the directed graph generation device provided in the above embodiment executes the directed graph generation method, only the division of the above-mentioned functional modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the directed graph generation device provided in the above embodiment and the directed graph generation method embodiment belong to the same concept. Therefore, for details not disclosed in the device embodiment of the present application, please refer to the above-mentioned directed graph generation method embodiment of the present application, which will not be repeated here.

[0116] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.

[0117] Fig. 9 A structural schematic diagram of a test case generating device provided in an embodiment of the present application is shown.

[0118] For example, Fig. 9 As shown, the test case generating device comprises:

[0119] A third determination module 910 is used to determine a function to be tested;

[0120] A matching module 920 is used to obtain a target directed graph matching the function to be tested from a graph database; wherein the graph database includes a plurality of directed graphs, the directed graphs are generated according to the above-mentioned test case generation method, and the function function corresponding to the target directed graph includes the function to be tested;

[0121] The use case generation module 930 is used to traverse the target directed graph based on the depth-first traversal rule and the attention level annotated on each node in the target directed graph to generate test cases for the function to be tested.

[0122] It should be noted that the test case generation device provided in the above embodiment only uses the division of the above functional modules as an example when executing the test case generation method. In actual applications, the above function allocation can be completed by different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the test case generation device provided in the above embodiment belongs to the same concept as the test case generation method embodiment. Therefore, for details not disclosed in the device embodiment of the present application, please refer to the embodiment of the test case generation method of the present application, which will not be repeated here.

[0123] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.

[0124] Fig.10 A schematic structural diagram of an electronic device provided in an embodiment of the present application is shown.

[0125] For example, Fig.10 As shown, the electronic device 1000 includes: a memory 1001 and a processor 1002, wherein the memory 1001 stores an executable program code 10011, and the processor 1002 is used to call and execute the executable program code 10011 to perform a directed graph generation method or a test case generation method.

[0126] In this embodiment, the electronic device can be divided into functional modules according to the above method example. For example, each functional module can be corresponded to, or two or more functions can be integrated into one processing module. The above integrated module can be implemented in the form of hardware. It should be noted that the division of modules in this embodiment is schematic and is only a logical function division. There may be other division methods in actual implementation.

[0127] In the case of dividing each functional module according to each function, the electronic device may include: a first determination module, a second determination module, a third determination module, a matching module, a use case generation module, etc. It should be noted that all relevant contents of each step involved in the above method embodiment can be referred to the functional description of the corresponding functional module, and will not be repeated here.

[0128] The electronic device provided in this embodiment is used to execute the above-mentioned directed graph generation method or test case generation method, and thus can achieve the same effect as the above-mentioned implementation method.

[0129] In the case of an integrated unit, the electronic device may include a processing module and a storage module. The processing module may be used to control and manage the actions of the electronic device. The storage module may be used to support the electronic device in executing mutual program codes and data.

[0130] The processing module may be a processor or a controller, which may implement or execute various exemplary logic blocks, modules and circuits disclosed in the present application. The processor may also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of digital signal processing (DSP) and a microprocessor, etc. The storage module may be a memory.

[0131] This embodiment also provides a computer-readable storage medium, which stores computer program code. When the computer program code runs on a computer, the computer executes the above-mentioned related method steps to implement a directed graph generation method or a test case generation method in the above-mentioned embodiment.

[0132] This embodiment also provides a computer program product. When the computer program product runs on a computer, it enables the computer to execute the above-mentioned related steps to implement a directed graph generation method or a test case generation method in the above-mentioned embodiment.

[0133] In addition, the electronic device provided in the embodiments of the present application may specifically be a chip, a component or a module, and the electronic device may include a connected processor and a memory; wherein the memory is used to store instructions, and when the electronic device is running, the processor may call and execute instructions so that the chip executes a directed graph generation method or a test case generation method in the above-mentioned embodiments.

[0134] Among them, the electronic device, computer-readable storage medium, computer program product or chip provided in this embodiment is used to execute the corresponding directed graph generation method or test case generation method provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding directed graph generation method or test case generation method provided above, and will not be repeated here.

[0135] Through the description of the above implementation methods, technical personnel in the relevant field can understand that for the convenience and simplicity of description, only the division of the above-mentioned functional modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.

[0136] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of modules or units is only a logical function division, and there may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0137] The above contents are only specific implementation methods of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

Claims

1. A directed graph generation method, characterized in that: The directed graph generation method comprises: Determine the function reference relationship between multiple target code functions to obtain a function reference relationship graph; Determine the function function of each function combination in the function reference relationship diagram; wherein the function combination includes at least one target code function; A directed graph about the plurality of target code functions is generated according to the function reference relationship graph and the functional functions of the respective function combinations.

2. The directed graph generation method according to claim 1, characterized in that: The function of determining each function combination in the function reference relationship diagram includes: Natural language processing is performed on the code annotations and / or code semantics of the target code functions in the various function combinations to obtain the functional functions of the various function combinations.

3. The directed graph generation method according to claim 1, characterized in that: Generating a directed graph about the plurality of target code functions according to the function reference relationship graph and the functional functions of the respective function combinations comprises: Determine the first target code function in the function reference relationship graph; Using the functional functions of the various function combinations as the labels of the first target code function to obtain the first node N1 of the directed graph; According to the first node N1 and the function reference relationship, determine the directed edges between other nodes Ni of the directed graph and each node from the function reference relationship graph; wherein i is greater than or equal to 2; The directed graph is generated according to the first node N1, the other nodes Ni and the directed edges.

4. The directed graph generation method according to claim 3, characterized in that: Determining the directed edges between other nodes Ni of the directed graph and each node from the function reference relationship graph according to the first node N1 and the function reference relationship includes: Determine other target code functions except the first target code function in the function reference relationship graph as the other nodes Ni; Determine the out-degree and in-degree of each node according to the function reference relationship; According to the out-degree and the in-degree, the directed edges between the nodes are determined.

5. The directed graph generation method according to any one of claims 1 to 4, characterized in that: After generating a directed graph about the plurality of target code functions according to the function reference relationship graph and the function functions of the respective function combinations, the directed graph generating method further comprises: Obtaining the number of references of the target code function corresponding to each node in the directed graph; Determining the attention level of the target code function corresponding to each node according to the number of citations; wherein the number of citations is positively correlated with the attention level; The degree of attention is marked for each node.

6. The directed graph generation method according to any one of claims 1 to 4, characterized in that: The directed graph generation method further comprises: Determine an original code function that supports a preset development language among the multiple original code functions as a candidate code function, thereby obtaining multiple candidate code functions; The candidate code functions that are non-business code functions among the multiple candidate code functions are filtered to obtain the multiple target code functions.

7. A test case generation method, characterized in that: The test case generation method comprises: Identify the functions to be tested; Acquire a target directed graph matching the function to be tested from a graph database; wherein the graph database includes a plurality of directed graphs, the directed graphs are generated according to the directed graph generation method according to any one of claims 1 to 6, and the function function corresponding to the target directed graph includes the function to be tested; Based on the depth-first traversal rule and the attention degree marked on each node in the target directed graph, the target directed graph is traversed to generate a test case for the function to be tested.

8. A directed graph generating device, characterized in that: The directed graph generating device comprises: A first determining module is used to determine a function reference relationship between multiple target code functions to obtain a function reference relationship graph; A second determination module is used to determine the function of each function combination in the function reference relationship diagram; wherein the function combination includes at least one target code function; A directed graph generation module is used to generate a directed graph about the multiple target code functions according to the function reference relationship diagram and the functional functions of the various function combinations.

9. A test case generating device, characterized in that: The test case generating device comprises: A third determination module is used to determine the function to be tested; A matching module, used for obtaining a target directed graph matching the function to be tested from a graph database; wherein the graph database includes a plurality of directed graphs, the directed graphs are generated according to the directed graph generation method according to any one of claims 1 to 6, and the function function corresponding to the target directed graph includes the function to be tested; The use case generation module is used to traverse the target directed graph based on the depth-first traversal rule and the attention degree marked on each node in the target directed graph to generate a test case for the function to be tested.

10. An electronic device, characterized in that: The electronic device comprises: A memory for storing executable program codes; A processor, configured to call and run the executable program code from the memory, so that the electronic device executes the directed graph generation method as described in any one of claims 1 to 6, or executes the test case generation method as described in claim 7.

11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed, it implements the directed graph generation method as described in any one of claims 1 to 6, or executes the test case generation method as described in claim 7.