Method, device and computer equipment for analyzing program interface
By scanning the code to obtain interface information, the program interface is automatically analyzed, which solves the problem of high time consumption and low efficiency of manual analysis, and realizes efficient and low-cost interface analysis, which is suitable for large-scale industrial product development.
Patent Information
- Application Number
- CN202010507201.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-06-05
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2040-06-05
AI Technical Summary
In the existing technology, manual analysis of program interfaces is time-consuming, costly and inefficient. Especially in the development process of large-scale industrial products, the cost of analyzing program interfaces increases sharply when faced with complex code structures and a large number of codes.
By scanning the code of the program to be analyzed and the test case, the relevant information of the interface is obtained, and it is judged whether the test case covers the interface of the program to be analyzed. If not, it is stored in the set of uncovered interfaces, and the analysis is automatically completed using the computer program to reduce manual intervention.
It improves the efficiency of the analysis program interface, reduces the cost, and reduces the error rate, especially in the development of large-scale industrial products, showing obvious advantages.
Smart Images

Figure CN113760690B
Abstract
Description
Technical Field
[0001] The present application relates to the field of software development, and in particular to a method, device and computer equipment for analyzing a program interface. Background Art
[0002] At different stages of software system development, there is usually a testing process. To test the software, you need to design some test cases, which may be designed for the program interface. The program interface generally refers to the application programming interface (API), which is a set of predefined functions or agreements that connect different components of the software system. Its function is to provide application programs and developers with the ability to access a set of routines based on a certain software or hardware without having to access the original code or understand the details of the internal working mechanism.
[0003] During the software testing phase, software testers and other related personnel hope that the test cases can completely cover the program interface, that is, to have enough test cases for the program interface to test the software. Therefore, before testing the software, analyzing the relevant information of the program interface (for example, the number of interfaces, interface types, interface names and interface parameters, etc.) is also a key link. At present, the method of analyzing program interfaces mainly relies on manual work, that is, software testers and other related personnel check the program code line by line and get statistical results.
[0004] However, manual statistics or analysis of program interfaces is time-consuming, costly, and slow, especially in the development of large-scale industrial products. The complex code structure and large amount of code lead to a sharp increase in the cost of analyzing program interfaces. Summary of the invention
[0005] The embodiments of the present application provide a method, apparatus, computer device and computer-readable storage medium for analyzing program interfaces to solve the problem of high cost and low efficiency of manual statistics of program interfaces in the prior art. The technical solution is as follows:
[0006] In one aspect, a method for analyzing a program interface is provided, the method comprising:
[0007] Read the code of the program to be analyzed and the code of the test case;
[0008] Scan the code of the program to be analyzed and the code of the test case to obtain relevant information of the interface in the program to be analyzed and the test case respectively;
[0009] According to the relevant information of the interface in the program to be analyzed and the test case, determine whether the interface of the test case has covered the interface of the program to be analyzed;
[0010] If the program to be analyzed has interfaces that are not covered by the interfaces of the test case, the interfaces that are not covered by the interfaces of the test case are stored in an uncovered interface set.
[0011] In one aspect, a device for analyzing a program interface is provided, the device comprising:
[0012] A code reading module is used to read the code of the program to be analyzed and the code of the test case;
[0013] An interface information acquisition module, used to scan the code of the program to be analyzed and the code of the test case, and respectively acquire relevant information of the interfaces in the program to be analyzed and the test case;
[0014] A judgment module, used to judge whether the interface of the test case has covered the interface of the program to be analyzed according to the relevant information of the interface in the program to be analyzed and the test case;
[0015] The information storage module is used to store the interface not covered by the interface of the test case into an uncovered interface set if the program to be analyzed has an interface not covered by the interface of the test case.
[0016] On the one hand, a computer device is provided, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program code is loaded and executed by the one or more processors to implement the operations performed by the method of the analysis program interface.
[0017] In one aspect, a computer-readable storage medium is provided, which stores a computer program that is loaded and executed by a processor to implement operations performed by the method for analyzing a program interface.
[0018] It can be seen from the technical solution provided by the present application that, unlike the prior art which manually counts the number of interfaces in the program and other related information of the interface by reading the program code, the technical solution of the present invention is to analyze the interface in the program to be analyzed by scanning the code of the program to be analyzed and the test case to obtain the related information of the interface therein. Since the code scanning can be automatically completed by a computer program, compared with the manual analysis of program interfaces in the prior art, the technical solution provided by the present application has the advantages of high efficiency, low cost and low error-proneness. In the process of large-scale industrial product development, facing the complicated code structure and the huge number of codes, the above advantages of the technical solution provided by the present application are more obvious. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0020] Figure 1 is a flow chart of a method for analyzing a program interface provided by an embodiment of the present application;
[0021] Figure 2 It is a flowchart of scanning the code of the program to be analyzed and the code of the test case provided by the embodiment of the present application, and obtaining relevant information of the interface in the program to be analyzed and the test case respectively;
[0022] Figure 3 is a schematic diagram of information included in a set of uncovered interfaces provided in an embodiment of the present application;
[0023] Figure 4 A flowchart of scanning the code of a program to be analyzed and the code of a test case to obtain relevant information of interfaces in the program to be analyzed and the test case, respectively, provided by another embodiment of the present application;
[0024] Figure 5 It is a schematic diagram of the marking information indicated after the interface in the code of the program to be analyzed and the code of the test case provided in the embodiment of the present application;
[0025] Figure 6 It is a structural schematic diagram of a device for analyzing a program interface provided in an embodiment of the present application;
[0026] Figure 7 It is a structural diagram of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0027] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.
[0028] Attached Figure 1 is a flow chart of a method for analyzing a program interface provided by an embodiment of the present application. The method can be applied to some computer devices, so the present application embodiment is introduced based on a computer device as the execution subject. Figure 1 This embodiment specifically includes the following steps S101 to S104, which are described in detail as follows:
[0029] Step S101: Read the code of the program to be analyzed and the code of the test case.
[0030] In an embodiment of the present application, some script programs or script tools can be used to call specific commands, such as code pull commands, to read the code of the program to be analyzed from the source file warehouse, and automatically obtain the source file of the latest version of the program to be analyzed. The source file here includes a complete source code, including both modules that implement business functions and interface functions for external calls. It should be noted that in order to automatically execute the technical solution of the present invention on a regular basis, the above-mentioned script program or script tool can be integrated into a continuous integration framework, and when the scheduled time arrives, the code pull command is executed to read the code of the program to be analyzed. As for the reading of the code of the test case, it can be carried out in the same way as reading the code of the program to be analyzed, or it can be carried out in other ways, and the present invention does not limit this; the definition or function of the test case is the same as that of the test case in the prior art.
[0031] Step 102: Scan the code of the program to be analyzed and the code of the test case to obtain relevant information of the interface in the program to be analyzed and the test case respectively.
[0032] As mentioned above, in the software testing phase, it is hoped that the test cases can completely cover the program interface, that is, there are enough test cases for the program interface to test the software. Therefore, it is necessary to obtain relevant information about the interface in the program to be analyzed and the test case. Different from the prior art, which obtains relevant information about the program interface by manually reading the program source code, in the embodiment of the present application, after the script program or script tool is started and the code of the program to be analyzed and the code of the test case are read from the source file repository, the relevant information about the interface in the program to be analyzed and the test case is obtained by scanning the code of the program to be analyzed and the code of the test case.
[0033] As an embodiment of the present application, scanning the code of the program to be analyzed and the code of the test case to obtain the relevant information of the interface in the program to be analyzed and the test case can be performed as shown in the attached Figure 2 The exemplary steps S201 to S203 are implemented as follows:
[0034] Step S201: Scan the code of the program to be analyzed and the code of the test case line by line to obtain feature information of the interface in the code.
[0035] Generally speaking, as a method in a program, an interface has some characteristics different from other statements in a programming language when it is written in a programming language. These characteristics constitute the characteristic information of the interface, for example, the definition format of the interface includes an interface name followed by parentheses, possible parameters in the parentheses, a function body and other grammatical features, etc. The characteristic information of the interface in the code can be obtained by scanning the code of the program to be analyzed and the code of the test case line by line.
[0036] Step S202: According to the characteristic information of the interface obtained in step S201, determine the interface where the program to be analyzed and the test case exist.
[0037] Specifically, step S202 can be implemented by the following steps S2021 and S2022:
[0038] Step S2021: According to the interface general definition format, determine whether there is an interface that complies with the interface general definition format in the scanned code.
[0039] As mentioned above, the definition format of the interface belongs to one of the characteristic information of the interface. In order to find out whether there is an interface in the scanned code to the greatest extent possible, the technical solution of the present application is to determine whether there is an interface that conforms to the general definition format of the interface in the scanned code according to the general definition format of the interface, and the method is to determine whether there is an interface that conforms to the general definition format of the interface according to the elements contained in the general definition format of the interface, namely, the interface name, the parentheses after the interface name (the parentheses may also contain parameters) and / or the function body, etc., to determine whether there is an interface that conforms to these elements in the scanned code. Specifically, the implementation of step S2021 can be: setting a variable C for specific syntax symbols that appear in pairs in the statement where the interface is located (for example, the left bracket "{" and the right bracket "}" of the curly braces are specific syntax symbols that appear in pairs in the statement where the interface is located), and the initial value of the variable C is 0; when scanning, according to the specific syntax identifier of the statement where the interface is located in the programming language, this specific syntax identifier is used as the starting line for scanning the code line by line, and if one format of the specific syntax symbols that appear in pairs is scanned each time, the value of the variable C is increased by 1, and if another format of the specific syntax symbols that appear in pairs is scanned each time, the value of the variable C is reduced by 1; according to this matching rule, when the value of the variable C becomes 0 again, the code scanning with this specific syntax identifier as the starting line for scanning the code line by line ends; if there are statements that conform to the elements included in the interface general definition format of the interface in the code between the start and end of the scan, it can be determined that there is an interface that conforms to the interface general definition format; then, continue to scan other specific syntax identifiers as the code segments that start scanning the code line by line.
[0040] The following is an example of using a component constructor in the WeChat applet code to construct a component, and when defining a method inside the constructor, it is required to define the method in the method body of the component (the specific syntax of the method body is marked as methods) code block, to illustrate the implementation scheme of the above embodiment. In the above example, the specific syntax of the statement where the interface is located in the programming language is marked as methods, and its code block is as follows:
[0041] methods:{
[0042] function1(){
[0043] },
[0044] function2(){
[0045] },
[0046] …
[0047] }
[0048] A variable can be set for the matching value of the left and right curly braces. Assume that the variable is marked as C and its initial value is set to 0. Starting from the line that scans the specific syntax identifier methods, the value of variable C increases by 1 each time a left curly brace is scanned, and the value of variable C decreases by 1 each time a right curly brace is scanned. According to the above rules, when scanning the line of the specific syntax identifier methods, the first time a left curly brace is scanned, the value of variable C is increased by 1, that is, C=1; continue scanning the second line of code, because a left curly brace is scanned, the value of variable C is increased by 1, that is, C=2; and then The scanning of the third line of code continues. Since a right brace is scanned, the value of variable C is reduced by 1, that is, C=1; the scanning of the fourth line of code continues. Since a left brace is scanned, the value of variable C is increased by 1, that is, C=2; the scanning of the fifth line of code continues. Since a right brace is scanned, the value of variable C is reduced by 1, that is, C=1; the scanning of the sixth line of code continues. Since a right brace is scanned, the value of variable C is reduced by 1, that is, C=0; since variable C becomes 0 again, it is determined that the last line of the method body of methods is scanned, and the code scanning of this method body ends. The scanning result shows that there are statements that conform to the elements included in the interface general definition format of the interface in the code between the scanning start and the scanning end, for example, function1(){} and function2(){}, then it is determined that function1() and function2() belong to the interface of the program.
[0049] Step S2022: If there are interfaces that conform to the interface general definition format in the scanned code, pseudo interfaces or interfaces that do not need to be analyzed in the interfaces that conform to the interface general definition format are excluded according to a predetermined exclusion strategy. After excluding pseudo interfaces or interfaces that do not need to be analyzed, the remaining interfaces are determined as interfaces that exist in the programs and test cases to be analyzed.
[0050] In engineering practice, an "interface" that conforms to the general definition format of an interface is sometimes not a real interface, i.e., a pseudo-interface. For example, in some programming languages, conditional statements such as "if" statements (e.g., if(){}) also conform to the general definition format of an interface in terms of syntax, but are obviously not interfaces. In addition, there are some interfaces that are real interfaces but do not require analysis, such as internal call interfaces. The internal call interface here refers to an interface that conforms to the general definition format of an interface but is not declared in a method body (e.g., methods in the aforementioned embodiment), such as the this method call in function1 and the anonymous function call in funtion2 in the following code:
[0051] methods:{
[0052] function1(){
[0053] if(this.isLoad()){}
[0054] },
[0055] function2(){
[0056] setTimeout(()=>{});
[0057] },
[0058] }
[0059] The above are all examples of pseudo interfaces or interfaces that do not need to be analyzed in interfaces that conform to the interface common definition format, and are also interfaces that need to be excluded according to a predetermined exclusion policy.
[0060] In this embodiment, some pseudo interfaces or general format templates of pseudo interfaces and some interfaces that do not require analysis can be summarized into a form to form an analysis-free interface whitelist. For example, if statements and for statements in programming languages belong to pseudo interfaces, and interfaces that need to be verified by UI and are not suitable for interface testing or internal call interfaces that have been covered by other interfaces through call relationship chains belong to analysis-free interfaces. These "interfaces" can be included in the above-mentioned analysis-free interface whitelist. As an embodiment of the present application, excluding pseudo interfaces or analysis-free interfaces in interfaces that conform to the interface general definition format according to a predetermined exclusion strategy can be: enabling the analysis-free interface whitelist to filter interfaces that conform to the interface general definition format, filtering out pseudo interfaces or analysis-free interfaces in interfaces that conform to the interface general definition format. By comparing the interface that conforms to the interface general definition format identified by step S2021 with the interface listed in the analysis-free interface whitelist, if the interface that conforms to the interface general definition format identified by step S2021 exists in the analysis-free interface whitelist, the interface that conforms to the interface general definition format identified by step S2021 and exists in the analysis-free interface whitelist is excluded. Taking pseudo-interfaces such as if statements as an example, as long as the interface that conforms to the general definition format of the interface identified by step S2021 is actually an if statement, such pseudo-interfaces should be excluded; for example, some internal call interfaces contain interfaces with relatively obvious keywords or formats, such as the this() method (i.e., this.isLoad()) and anonymous functions (i.e., ()=>{}) in the above-mentioned example method body methods, or, based on the understanding of the source code, contain non-interfaces that are relatively easy to identify (for example, functions similar to logger.info() for logging in the above-mentioned example method body methods). These specific forms of interfaces will be listed in the analysis-free interface whitelist. As long as the interface that conforms to the general definition format of the interface identified by step S2021 is compared with the interface name in the analysis-free interface whitelist, if the interface that conforms to the general definition format of the interface identified by step S2021 contains the above-mentioned specific form of interface, such interfaces that do not require analysis should also be excluded.
[0061] Considering that various algorithms of deep learning models are becoming more and more mature, they are widely used in search technology, data mining, machine learning, machine translation, natural language processing, multimedia learning, speech, recommendation and personalization technology, etc., and their recognition accuracy in these fields is close to or even exceeds the accuracy of manual recognition, but the efficiency is far better than manual recognition. Therefore, in the embodiment of the present application, the deep learning model can also be combined to exclude pseudo interfaces or interfaces that do not need to be analyzed in the interface that conforms to the general definition format of the interface. Specifically, as another embodiment of the present application, according to a predetermined exclusion strategy, the pseudo interfaces or interfaces that do not need to be analyzed in the interface that conforms to the general definition format of the interface can be: input the interface that conforms to the general definition format of the interface into the deep learning model, and output the interface where the program to be analyzed and the test case exist through the learning of the deep learning model. The deep learning model here is any existing deep learning model, such as a convolutional neural network. The feature information of the interface can be used as a training sample in advance to train the deep learning model. After the interface that conforms to the general definition format of the interface is input into the trained deep learning model, its output result is the interface where the program to be analyzed and the test case exist. For large and complex programs with a large number of interfaces or programs with a large number of pseudo-interfaces or interfaces that do not need to be analyzed, combining deep learning models to eliminate pseudo-interfaces or eliminate the need for analyzing interfaces has certain advantages.
[0062] Step S203: record the determined interface related information, wherein the interface related information includes the interface name, interface parameters, and a mapping relationship between the interface and the file where the code is located.
[0063] In the embodiment of the present application, the mapping relationship between the above interface and the file where the code is located refers to which file the interface belongs to and what the storage path of the file is. After the relevant information of these interfaces is sorted out, it will be stored in the uncovered interface set.
[0064] In an embodiment of the present application, if, when writing the code of the program to be analyzed and the test case, the interfaces in the program to be analyzed and the test case are marked according to the specification or out of the programmer's preference, then as another embodiment of the present application, scanning the code of the program to be analyzed and the code of the test case to obtain the interface-related information in the program to be analyzed and the test case respectively can also be performed as shown in the attached Figure 4 The exemplary method implementation specifically includes step S401 and step S403, which are described as follows:
[0065] Step S401: Scan the code of the program to be analyzed and the code of the test case line by line to obtain interface marking information in the code.
[0066] With attached Figure 2The purpose of step S201 in the example is different. In this embodiment, the purpose of scanning the code of the program to be analyzed and the code of the test case line by line is to obtain the interface marking information in the code. The interface marking information here can be the mark made by the programmer on the interface when programming. For example, the interface name or other marking information can be directly written in the comment part after the statement, such as the attached Figure 5 shown.
[0067] Step S402: According to the interface marking information obtained in step S401, determine the interface where the program to be analyzed and the test case exist.
[0068] Since the comment part after the interface in the code of the program to be analyzed and the code of the test case is directly annotated with the interface tag information, when the keywords of the interface tag information are read, it can be determined that the program to be analyzed and the test case exist the interface.
[0069] Step S403: record the relevant information of the interface determined in step S401, wherein the relevant information includes the interface name, interface parameters, and the mapping relationship between the interface and the file where the code is located.
[0070] In the embodiment of the present application, the implementation method of step S403 is the same as that of the aforementioned Figure 2 The implementation method of the exemplary step S203 is the same, and the technical features, terms or explanations involved can refer to the description of the aforementioned embodiments, which will not be repeated here.
[0071] Step S103: judging whether the interface of the program to be analyzed has covered the interface of the program to be analyzed according to the related information of the interface in the test case and the program to be analyzed.
[0072] In an embodiment of the present application, according to the specifications of software development, for the program to be analyzed and the test case, the same interface must be named the same. Therefore, based on the relevant information of the interface in the program to be analyzed and the test case, it can be determined whether the interface of the test case has covered the interface of the program to be analyzed by comparing the relevant information of the interface obtained from the program to be analyzed with the relevant information of the interface obtained from the test case, thereby determining whether the interface of the test case has covered the interface of the program to be analyzed. For example, after comparing the interface names, if a certain interface that exists in the program to be analyzed does not exist in the test case, it can be determined that the program to be analyzed has an interface that is not covered by the interface of the test case.
[0073] Step S104: If the program to be analyzed has interfaces that are not covered by the interfaces of the test case, the interfaces that are not covered by the interfaces of the test case are stored in an uncovered interface set.
[0074] In an embodiment of the present application, the uncovered interface set stores interfaces in the program to be analyzed that are not covered by the interfaces of the test case and other related information, including the version of the program to be analyzed, the number of interfaces to be supplemented (for test cases), the files where the interfaces to be supplemented are located, and the names of the interfaces to be supplemented, etc., an example of which is shown in the attached Figure 3 shown.
[0075] Taking into account that some files do not store code or have interfaces, for example, some resource files generally do not have interfaces, and these resource files are usually stored in specific folders; or, some files with specific suffixes must have interfaces or are files that must be scanned, in order to reduce unnecessary operations and thus improve the efficiency of interface acquisition, in the above-mentioned embodiment of the present application, before scanning the code of the program to be analyzed and the code of the test case to obtain the interface-related information in the program to be analyzed and the test case respectively, the scanning scope can be determined according to the format or path in which the file where the code is located may be saved, so as to scan the code of the program to be analyzed and the code of the test case within the determined scanning scope.
[0076] In order to use the interfaces existing in the determined programs to be analyzed and test cases in the subsequent implementation, in the embodiment of the present application, if the interfaces in the programs to be analyzed and test cases have no marking information, the interfaces existing in the programs to be analyzed and test cases can be marked after obtaining the relevant information of the interfaces in the programs to be analyzed and test cases. The marking method can be similar to that in the attached Figure 5 .
[0077] Since software development is usually completed by a team, other members of the team also need to obtain the analysis data of the interfaces in the program to be analyzed in a timely manner. Therefore, in an embodiment of the present application, after the interfaces not covered by the test cases are stored in the uncovered interface set, the uncovered interface set is sorted out and the sorted uncovered interface set is output to relevant personnel. For example, the above-mentioned relevant information in the uncovered interface set is shared with team members through instant messaging tools such as WeChat and QQ.
[0078] From the above attached Figure 1It can be seen from the example method of analyzing program interfaces that, unlike the prior art method of manually counting the number of interfaces in the program and other interface-related information by reading program codes, the technical solution of the present invention is to analyze the interfaces in the program to be analyzed by scanning the codes of the program to be analyzed and the test cases to obtain the interface-related information therein. Since scanning codes can be automatically completed by computer programs, compared with the prior art method of manually analyzing program interfaces, the technical solution provided by the present application has the advantages of high efficiency, low cost and low error-proneness. In the process of large-scale industrial product development, facing the complicated code structure and the huge number of codes, the above advantages of the technical solution provided by the present application are more obvious.
[0079] Please see attached Figure 6 , is a schematic diagram of the structure of a device for analyzing a program interface provided in an embodiment of the present application. The device can be integrated in a computer device such as a terminal. The device includes a code reading module 601, an interface information acquisition module 602, a judgment module 603 and an information storage module 604, wherein:
[0080] The code reading module 601 is used to read the code of the program to be analyzed and the code of the test case;
[0081] The interface information acquisition module 602 is used to scan the code of the program to be analyzed and the code of the test case to obtain the relevant information of the interface in the program to be analyzed and the test case respectively;
[0082] The judgment module 603 is used to judge whether the interface of the program to be analyzed has covered the interface of the program to be analyzed according to the relevant information of the interface in the program to be analyzed and the test case;
[0083] The information saving module 604 is used to store the interfaces not covered by the test case interfaces into an uncovered interface set if the program to be analyzed has interfaces not covered by the test case interfaces.
[0084] In one possible implementation, the interface information acquisition module 602 is used to scan the code of the program to be analyzed and the code of the test case line by line to obtain the characteristic information of the interface in the code, determine the interface of the program to be analyzed and the test case based on the characteristic information of the interface in the acquired code, and record the relevant information of the determined interface, wherein the relevant information includes the interface name, interface parameters and the mapping relationship between the interface and the file where the code is located; in one possible implementation, the above-mentioned determination of the interface of the program to be analyzed and the test case based on the characteristic information of the interface in the acquired code can be: according to the interface general definition format, determine whether there is an interface that conforms to the interface general definition format in the scanned code, if there is an interface that conforms to the interface general definition format in the scanned code For interfaces in the general definition format, pseudo-interfaces or interfaces that do not need to be analyzed in the interfaces that conform to the general definition format of the interface are excluded according to a predetermined exclusion strategy; in a possible implementation method, the above-mentioned exclusion of pseudo-interfaces or interfaces that do not need to be analyzed in the interfaces that conform to the general definition format of the interface according to the predetermined exclusion strategy can be: enabling a whitelist of analysis-free interfaces to filter the interfaces that conform to the general definition format of the interface, filtering out pseudo-interfaces or interfaces that do not need to be analyzed; in a possible implementation method, the above-mentioned exclusion of pseudo-interfaces or interfaces that do not need to be analyzed in the interfaces that conform to the general definition format of the interface according to the predetermined exclusion strategy can be: inputting the interfaces that conform to the general definition format of the interface into a deep learning model, and outputting the interfaces existing in the programs to be analyzed and test cases through learning by the deep learning model.
[0085] In one possible implementation, the interface information acquisition module 602 is used to scan the code of the program to be analyzed and the code of the test case line by line to obtain the interface marking information in the code, determine the interfaces of the program to be analyzed and the test case based on the interface marking information in the acquired code, and record the relevant information of the determined interface, wherein the relevant information includes the interface name, interface parameters, and the mapping relationship between the interface and the file where the code is located.
[0086] In a possible implementation, the above-mentioned Figure 6 The device may also include a scanning range determination module, which is used to determine the scanning range according to the format or path in which the file where the code is located may be saved before the interface information acquisition module 602 scans the code of the program to be analyzed and the code of the test case, and obtains the relevant information of the interface in the program to be analyzed and the test case respectively, so as to scan the code of the program to be analyzed and the code of the test case within the determined scanning range.
[0087] In a possible implementation, the above-mentioned Figure 6 The device may further include a marking module and a sorting module, wherein:
[0088] A marking module, used for marking the interfaces in the program to be analyzed and the test case after the interface information acquisition module 602 acquires the relevant information of the interfaces in the program to be analyzed and the test case;
[0089] The sorting module is used to sort the uncovered interface set after storing the interfaces not covered by the test case interfaces into the uncovered interface set and output the sorted uncovered interface set to relevant personnel.
[0090] It should be noted that the device for analyzing program interfaces provided in the above embodiments only uses the division of the above functional modules as an example when analyzing program interfaces. In actual applications, the above functional distribution 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 device for analyzing program interfaces provided in the above embodiments and the method embodiment for analyzing program interfaces belong to the same concept. The specific implementation process and technical effects are detailed in the method embodiment, which will not be repeated here.
[0091] The present application also provides a computer device, which may be a terminal or a server. Figure 7 As shown, it shows a schematic diagram of the structure of the computer device involved in the embodiment of the present application, specifically:
[0092] The computer device may include one or more processing core processors 701, one or more computer readable storage media memories 702, a power supply 703, an input unit 704 and other components. Those skilled in the art will appreciate that Figure 7 The computer device structure shown in the figure does not constitute a limitation on the computer device, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently. Among them:
[0093] The processor 701 is the control center of the computer device. It uses various interfaces and lines to connect various parts of the entire computer device. By running or executing software programs and / or modules stored in the memory 702 and calling data stored in the memory 702, it executes various functions of the computer device and processes data, thereby performing overall detection of the computer device. Optionally, the processor 701 may include one or more processing cores; preferably, the processor 701 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and application programs, and the modem processor mainly processes wireless communications. It is understandable that the above-mentioned modem processor may not be integrated into the processor 701.
[0094] The memory 702 can be used to store software programs and modules. The processor 701 executes various functional applications and data processing by running the software programs and modules stored in the memory 702. The memory 702 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area may store data created according to the use of the computer device, etc. In addition, the memory 702 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices. Accordingly, the memory 702 may also include a memory controller to provide the processor 701 with access to the memory 702.
[0095] The computer device also includes a power supply 703 for supplying power to various components. Optionally, the power supply 703 can be logically connected to the processor 701 through a power management system, so as to manage charging, discharging, and power consumption through the power management system. The power supply 703 can also include any components such as one or more DC or AC power supplies, recharging systems, power failure detection circuits, power converters or inverters, and power status indicators.
[0096] The computer device may further include an input unit 704, which may be used to receive input digital or character information and generate keyboard, mouse, joystick, optical or trackball signal input related to user settings and function control.
[0097] Although not shown, the computer device may also include a display unit, etc., which will not be described in detail here. Specifically in this embodiment, the processor 701 in the computer device will load the executable file corresponding to the process of one or more application programs into the memory 702 according to the following instructions, and the processor 701 will run the application stored in the memory 702, thereby realizing various functions, as follows: reading the code of the program to be analyzed and the code of the test case; scanning the code of the program to be analyzed and the code of the test case, and obtaining the relevant information of the interface in the program to be analyzed and the test case respectively; judging whether the interface of the test case has covered the interface of the program to be analyzed according to the relevant information of the interface in the program to be analyzed and the test case; if the program to be analyzed has an interface that is not covered by the interface of the test case, the interface that is not covered by the interface of the test case is stored in the uncovered interface set.
[0098] The specific implementation of the above operation can refer to the previous implementation, which will not be described again here.
[0099] From the above, it can be seen that, unlike the prior art which manually counts the number of interfaces in the program and other interface-related information by reading the program code, the technical solution of the present invention is to analyze the interface in the program to be analyzed by scanning the code of the program to be analyzed and the test case to obtain the interface-related information therein. Since the code scanning can be automatically completed by a computer program, compared with the prior art method of manually analyzing the program interface, the technical solution provided by the present application has the advantages of high efficiency, low cost and low error-proneness. In the process of large-scale industrial product development, facing the complicated code structure and the huge amount of code, the above advantages of the technical solution provided by the present application are more obvious.
[0100] A person of ordinary skill in the art will appreciate that all or part of the steps in the various methods of the above embodiments may be completed by instructions, or by controlling related hardware through instructions. The instructions may be stored in a computer-readable storage medium and loaded and executed by a processor.
[0101] To this end, an embodiment of the present application provides a computer-readable storage medium, in which a plurality of instructions are stored, and the instructions can be loaded by a processor to execute the steps in any method of analyzing a program interface provided by an embodiment of the present application. For example, the instruction can execute the following steps: reading the code of the program to be analyzed and the code of the test case; scanning the code of the program to be analyzed and the code of the test case, and obtaining the relevant information of the interface in the program to be analyzed and the test case respectively; judging whether the interface of the test case has covered the interface of the program to be analyzed according to the relevant information of the interface in the program to be analyzed and the test case; if the program to be analyzed has an interface that is not covered by the interface of the test case, the interface that is not covered by the interface of the test case is stored in the uncovered interface set.
[0102] The specific implementation of each of the above operations can be found in the previous embodiments, which will not be described in detail here.
[0103] The computer-readable storage medium may include: a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.
[0104] Since the instructions stored in the computer-readable storage medium can execute the steps in any method of analyzing a program interface provided in the embodiments of the present application, the beneficial effects that can be achieved by any method of analyzing a program interface provided in the embodiments of the present application can be achieved. Please refer to the previous embodiments for details and will not be repeated here.
[0105] The above is a detailed introduction to a method, device, computer equipment and computer-readable storage medium for analyzing a program interface provided in an embodiment of the present application. Specific examples are used herein to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea; at the same time, for technical personnel in this field, according to the idea of the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A method for analyzing a program interface, characterized in that: The method comprises: Read the code of the program to be analyzed and the code of the test case; Scanning the code of the program to be analyzed and the code of the test case line by line to obtain feature information of the interface in the code; According to the interface general definition format, determine whether there is an interface that conforms to the interface general definition format in the scanned code; wherein, according to the interface general definition format, determine whether there is an interface that conforms to the interface general definition format in the scanned code, including: obtaining specific syntax symbols that appear in pairs in the statement where the interface is located, and setting a variable corresponding to the specific syntax symbol, wherein the initial value of the variable is 0; using the specific syntax identifier of the statement where the interface is located in the programming language as the starting line for scanning the code line by line; when scanning the code of the program to be analyzed and the code of the test case according to the starting line, if one format of the specific syntax symbols that appear in pairs is scanned, the value of the variable is increased by 1, and if another format of the specific syntax symbols that appear in pairs is scanned, the value of the variable is reduced by 1; when the value of the variable becomes 0 again, it is determined that the code scanning with the specific syntax identifier as the starting line for scanning the code line by line is ended; if there is a statement that conforms to the elements included in the interface general definition format of the interface in the code between the scan start and the scan end, it is determined that there is an interface that conforms to the interface general definition format; If there is an interface conforming to the interface universal definition format in the scanned code, then excluding pseudo interfaces or interfaces that do not need to be analyzed in the interface conforming to the interface universal definition format according to a predetermined exclusion strategy; Recording the relevant information of the determined interface, wherein the relevant information includes the interface name, interface parameters, and a mapping relationship between the interface and the file where the code is located; the interface is an interface for external calls; According to the relevant information of the interface in the program to be analyzed and the test case, determine whether the interface of the test case has covered the interface of the program to be analyzed; If the program to be analyzed has interfaces that are not covered by the interfaces of the test case, the interfaces that are not covered by the interfaces of the test case are stored in an uncovered interface set.
2. The method for analyzing a program interface according to claim 1, characterized in that: The step of excluding pseudo interfaces or interfaces that do not need to be analyzed in the interface that conforms to the interface common definition format according to a predetermined exclusion strategy includes: The analysis-free interface whitelist is enabled to filter the interfaces that conform to the interface common definition format, and filter out the pseudo interfaces or interfaces that do not require analysis.
3. The method for analyzing a program interface according to claim 1, characterized in that: The method of excluding pseudo interfaces or interfaces that do not need to be analyzed in the interface that conforms to the interface common definition format according to a predetermined exclusion strategy includes: The interface that conforms to the interface general definition format is input into a deep learning model, and through the learning of the deep learning model, the interface where the program to be analyzed and the test case exist is output.
4. The method for analyzing a program interface according to claim 1, wherein: The method further comprises: Scanning the code of the program to be analyzed and the code of the test case line by line to obtain interface tag information in the code; Determine the interface where the program to be analyzed and the test case exist according to the interface marking information; The relevant information of the determined interface is recorded.
5. The method for analyzing a program interface according to any one of claims 1 to 4, characterized in that: Before scanning the code of the program to be analyzed and the code of the test case line by line to obtain feature information of the interface in the code, the method further includes: The scanning scope is determined according to the possible saving format or path of the file where the code is located, so as to scan the code of the program to be analyzed and the code of the test case within the scope.
6. The method for analyzing a program interface according to any one of claims 1 to 4, characterized in that: The method further comprises: After obtaining relevant information of interfaces in the program to be analyzed and the test case, marking the interfaces existing in the program to be analyzed and the test case; After storing the interfaces not covered by the interfaces of the test case into the uncovered interface set, the uncovered interface set is sorted and the sorted uncovered interface set is output to relevant personnel.
7. A device for analyzing a program interface, characterized in that: The device comprises: A code reading module is used to read the code of the program to be analyzed and the code of the test case; An interface information acquisition module, used to scan the code of the program to be analyzed and the code of the test case line by line to obtain feature information of the interface in the code; According to the interface general definition format, determine whether there is an interface that conforms to the interface general definition format in the scanned code; wherein, according to the interface general definition format, determine whether there is an interface that conforms to the interface general definition format in the scanned code, including: obtaining specific syntax symbols that appear in pairs in the statement where the interface is located, and setting a variable corresponding to the specific syntax symbol, wherein the initial value of the variable is 0; using the specific syntax identifier of the statement where the interface is located in the programming language as the starting line for scanning the code line by line; when scanning the code of the program to be analyzed and the code of the test case according to the starting line, if one format of the specific syntax symbols that appear in pairs is scanned, the value of the variable is increased by 1, and if another format of the specific syntax symbols that appear in pairs is scanned, the value of the variable is reduced by 1; when the value of the variable becomes 0 again, it is determined that the code scanning with the specific syntax identifier as the starting line for scanning the code line by line is ended; if there is a statement that conforms to the elements included in the interface general definition format of the interface in the code between the scan start and the scan end, it is determined that there is an interface that conforms to the interface general definition format; If there is an interface conforming to the interface universal definition format in the scanned code, then excluding pseudo interfaces or interfaces that do not need to be analyzed in the interface conforming to the interface universal definition format according to a predetermined exclusion strategy; Recording the relevant information of the determined interface, wherein the relevant information includes the interface name, interface parameters, and a mapping relationship between the interface and the file where the code is located; the interface is an interface for external calls; A judgment module, used to judge whether the interface of the test case has covered the interface of the program to be analyzed according to the relevant information of the interface in the program to be analyzed and the test case; The information storage module is used to store the interface not covered by the interface of the test case into an uncovered interface set if the program to be analyzed has an interface not covered by the interface of the test case.
8. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.
