CN113760690A - Method and device for analyzing program interface and computer equipment - Google Patents

Method and device for analyzing program interface and computer equipment Download PDF

Info

Publication number
CN113760690A
CN113760690A CN202010507201.6A CN202010507201A CN113760690A CN 113760690 A CN113760690 A CN 113760690A CN 202010507201 A CN202010507201 A CN 202010507201A CN 113760690 A CN113760690 A CN 113760690A
Authority
CN
China
Prior art keywords
interface
program
analyzed
code
test case
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202010507201.6A
Other languages
Chinese (zh)
Inventor
黎睿知
黄晶
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Tencent Technology Shenzhen Co Ltd
Original Assignee
Tencent Technology Shenzhen Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Tencent Technology Shenzhen Co Ltd filed Critical Tencent Technology Shenzhen Co Ltd
Priority to CN202010507201.6A priority Critical patent/CN113760690A/en
Publication of CN113760690A publication Critical patent/CN113760690A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3684Test management for test design, e.g. generating new test cases
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3676Test management for coverage analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3688Test management for test execution, e.g. scheduling of test suites

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)

Abstract

The application relates to the field of software development, and provides a method and a device for analyzing a program interface, computer equipment and a computer readable storage medium, which are used for solving the problems of high cost and low efficiency of manual statistics of the program interface in the prior art. The method comprises the following steps: reading codes of a program to be analyzed and codes of test cases; scanning a code of a program to be analyzed and a code of a test case, and respectively acquiring related information of an interface in the program to be analyzed and the test case; judging whether the interface of the test case covers the interface of the program to be analyzed or not according to the program to be analyzed and the related information of the interface in the test case; and if the program to be analyzed has an interface which is not covered by the interface of the test case, storing the interface which is not covered by the interface of the test case into the uncovered interface set. The technical scheme of the application has the advantages of high efficiency, low cost and low possibility of error, and particularly the advantages are more obvious when complex code structures and large and complicated code quantity are faced.

Description

Method and device for analyzing program interface and computer equipment
Technical Field
The present application relates to the field of software development, and in particular, to a method and an apparatus for analyzing a program interface, and a computer device.
Background
At various stages of software system development, there is typically a process of testing it. Testing software requires designing some test cases, which may be designed for program interfaces. A Program Interface (API), generally referred to as an Application Programming Interface (API), is a predefined agreement between different components of a software system or a predefined function, and is used to provide the ability for an Application program and a developer to access a set of routines based on certain software or hardware without accessing the original code or understanding the details of the internal working mechanism.
In the software testing stage, a person involved in software testing and the like desires that the test cases can completely cover the program interface, that is, enough test cases are available for the program interface to perform the software testing, and therefore, it is also a key link to analyze relevant information (for example, the number of interfaces, the types of interfaces, the names of interfaces, the parameters of interfaces, and the like) of the program interface before performing the software testing. At present, the method for analyzing the program interface mainly depends on manual operation, namely, the method depends on software testing and other related personnel to check the codes of the program line by line to obtain a statistical result.
However, manual statistics or analysis of the program interface by human labor is time-consuming and costly, and the analysis speed is slow, and particularly in the development process of large-scale industrial products, the cost of the program interface is increased sharply due to the complicated code structure and the numerous and complicated code quantity.
Disclosure of Invention
The embodiment of the application provides a method and a device for analyzing a program interface, computer equipment and a computer readable storage medium, which are used for solving the problems of high cost and low efficiency of manual statistics of the program interface in the prior art. The technical scheme is as follows:
in one aspect, a method of analyzing a program interface is provided, the method comprising:
reading codes of a program to be analyzed and codes of test cases;
scanning the code of the program to be analyzed and the code of the test case, and respectively acquiring related information of an interface in the program to be analyzed and the test case;
judging whether the interface of the test case covers the interface of the program to be analyzed or not according to the related information of the program to be analyzed and the interface in the test case;
and if the program to be analyzed has an interface which is not covered by the interface of the test case, storing the interface which is not covered by the interface of the test case into an uncovered interface set.
In one aspect, an apparatus for analyzing a program interface is provided, the apparatus comprising:
the code reading module is used for reading codes of the program to be analyzed and codes of the test cases;
the interface information acquisition module is used for scanning the code of the program to be analyzed and the code of the test case and respectively acquiring the relevant information of the interface in the program to be analyzed and the test case;
the judging module is used for judging whether the interface of the test case covers the interface of the program to be analyzed or not according to the program to be analyzed and the related information of the interface in the test case;
and the information storage module is used for storing the interface which is not covered by the interface of the test case into an uncovered interface set if the program to be analyzed has the interface which is not covered by the interface of the test case.
In one aspect, a computer device is provided that includes a memory, a processor, and a computer program stored in the memory and executable on the processor, the computer program code being loaded and executed by the one or more processors to perform the operations performed by the method of analyzing a program interface.
In one aspect, a computer-readable storage medium storing operations performed by a method in which a computer program is loaded and executed by a processor to implement the analysis program interface is provided.
According to the technical scheme provided by the application, different from the prior art that the related information of the interfaces such as the number of the interfaces in the program is manually counted in a mode of reading the program codes, the technical scheme provided by the invention is that the interface in the program to be analyzed is analyzed by scanning the codes of the program to be analyzed and the test cases and acquiring the related information of the interfaces. Because the code scanning can be automatically completed through a computer program, compared with a mode of manually analyzing a program interface in the prior art, the technical scheme provided by the application has the advantages of high efficiency, low cost and difficulty in error, and in the development process of large-scale industrialized products, the technical scheme provided by the application has more obvious advantages in the face of complicated code structures and numerous and complicated code quantities.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed to be used in the description of the embodiments are briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
FIG. 1 is a flow chart of a method for analyzing a program interface provided by an embodiment of the present application;
fig. 2 is a flowchart for scanning a code of a program to be analyzed and a code of a test case to obtain information related to an interface in the program to be analyzed and the test case, respectively, according to an embodiment of the present application;
FIG. 3 is a schematic diagram of information included in an uncovered interface set according to an embodiment of the present application;
fig. 4 is a flowchart for scanning codes of a program to be analyzed and codes of a test case to obtain information related to interfaces in the program to be analyzed and the test case, respectively, according to another embodiment of the present application;
FIG. 5 is a schematic diagram illustrating labeled information noted after an interface in code of a program to be analyzed and code of a test case provided in an embodiment of the present application;
FIG. 6 is a schematic structural diagram of an apparatus for analyzing a program interface according to an embodiment of the present disclosure;
fig. 7 is a schematic structural diagram of a computer device according to an embodiment of the present application.
Detailed Description
To make the objects, technical solutions and advantages of the present application more clear, embodiments of the present application will be described in further detail below with reference to the accompanying drawings.
Fig. 1 is a flowchart of a method for analyzing a program interface according to an embodiment of the present application. The method can be applied to some computer devices, and therefore, the embodiment of the present application is described based on the computer device as an execution subject. Referring to fig. 1, this embodiment mainly includes the following steps S101 to S104, which are described in detail as follows:
step S101: and reading the code of the program to be analyzed and the code of the test case.
In the embodiment of the present application, a specific command, for example, a code pull command, may be called by some script programs or script tools, the code of the program to be analyzed is read from the source file repository, and the source file of the latest version of the program to be analyzed is automatically obtained. The source file herein includes complete source code, including both modules for implementing 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 at regular time, the script program or the script tool may be integrated into a continuous integration framework, and when the time to be timed arrives, a 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, the same way as the reading of the code of the program to be analyzed can be adopted, and other ways can also be adopted, which is not limited by the invention; the test cases are defined or function the same as the prior art test cases.
Step 102: and scanning the code of the program to be analyzed and the code of the test case, and respectively acquiring the relevant information of the interface in the program to be analyzed and the test case.
As described above, in the software testing phase, it is desirable that the test cases can completely cover the program interface, that is, enough test cases are available for the program interface to perform the software testing, and therefore, it is necessary to obtain the information about the program to be analyzed and the interfaces in the test cases. Different from the prior art that the relevant information of the program interface is obtained in a mode of manually reading a program source code, in the embodiment of the application, after a script program or a script tool is started and a code of a program to be analyzed and a code of a test case are read from a source file warehouse, the relevant information of the interface in the program to be analyzed and the interface in the test case are respectively obtained by scanning the code of the program to be analyzed and the code of the test case.
As an embodiment of the present application, scanning the code of the program to be analyzed and the code of the test case, and respectively obtaining the relevant information of the interface in the program to be analyzed and the test case may be implemented by steps S201 to S203 as illustrated in fig. 2, which are described as follows:
step S201: and scanning the codes of the program to be analyzed and the codes of the test cases line by line to acquire the characteristic information of the interfaces in the codes.
Generally, an interface is a method in a program, which, when written in a programming language, has features that are different from other statements in the programming language, and these features constitute the feature information of the interface, for example, the definition format of the interface includes that the interface has an interface name followed by a parenthesis, and possibly parameters in the parenthesis, and the interface has a function body and other grammatical features, and so on. By scanning the code of the program to be analyzed and the code of the test case line by line, the characteristic information of the interface in the code can be acquired.
Step S202: and determining the interfaces of the program to be analyzed and the test cases according to the characteristic information of the interfaces acquired in the step S201.
Specifically, step S202 can be realized by step S2021 and step S2022 as follows:
step S2021: and judging whether an interface which conforms to the interface general definition format exists in the scanned codes or not according to the interface general definition format.
As described above, the defined format of the interface belongs to one of the characteristic information of the interface. In order to find out whether an interface exists in a scanned code to the maximum extent, the technical scheme of the application is to judge whether an interface which conforms to the interface general definition format exists in the scanned code according to the interface general definition format of the interface, and the method is to judge whether an interface which conforms to the elements exists in the scanned code according to the elements which are contained in the interface general definition format of the interface, namely, the interface name, a parenthesis (parameters may be contained in the parenthesis) and/or a function body and the like which are behind the interface name. Specifically, the implementation of step S2021 may be: setting a variable C for a specific syntax symbol (for example, a left bracket "{" and a right bracket "}" of a brace are specific syntax symbols appearing in pairs for statements where the interface is located), wherein the initial value of the variable C is 0; during scanning, according to a specific grammar mark of a statement where an interface is located in a programming language, taking the specific grammar mark as a starting line of line-by-line scanning of a code, if one format of specific grammar symbols appearing in pairs is scanned, increasing the value of a variable C by 1, and if the other format of the specific grammar symbols appearing in pairs is scanned, decreasing the value of the variable C by 1; according to the matching rule, when the value of the variable C becomes 0 again, the code scanning which is taken as the starting line of the line-by-line scanning of the code is marked to be ended by the specific grammar; if the statement of the element contained in the interface general definition format which accords with the interface exists in the code between the scanning start and the scanning end, the interface which accords with the interface general definition format can be judged to exist in the statement; then, the scanning of other specific syntax marks is continued, wherein the code segment is used as the starting line of the line-by-line scanning of the code.
The following describes an implementation of the above embodiment by taking an example in which a component (component) constructor is used in the WeChat applet code to construct a component, and a method needs to be defined in a method body (a specific syntax of the method body is identified as methods) code block of the component when the method is defined inside the constructor. In the above example, the specific syntax of the statement where the interface is located in the programming language is identified as methods, and the code blocks are as follows:
Figure BDA0002526962070000061
a variable may be set to the matching value of the left and right braces, assuming that the variable is marked as C, and its initial value is set to 0, starting from the line of the scan specific syntax identification methods, the value of the variable C is increased by 1 every time a left brace is scanned, and the value of the variable C is decreased by 1 every time a right brace is scanned; according to the above rule, when scanning the line of the specific syntax identification methods, the first time a left brace is scanned, the value of the variable C is increased by 1, that is, C is 1; continuing the scanning of the second line of codes, and increasing the value of the variable C by 1, namely C is 2, because a left brace is scanned; continuing to scan the third row of codes, and reducing the value of the variable C by 1 because a right brace is scanned, namely C is 1; continuing to scan the fourth line of code, and increasing the value of the variable C by 1, namely C is 2, because a left brace is scanned; continuing the scanning of the fifth row of codes, and reducing the value of the variable C by 1 because a right brace is scanned, namely C is 1; continuing to scan the codes in the sixth row, and reducing the value of the variable C by 1, namely, C is equal to 0, because a right brace is scanned; since the variable C becomes 0 again, it is determined that the last line of the method body of methods is scanned, and the code scanning for the method body is ended. The result of the scan shows that, if statements conforming to elements included in the interface common definition format of the interface exist in the code between the scan start and the scan end, for example, function1() { } and function2() { }, the function1() and the function2() are judged to belong to the interface of the program.
Step S2022: if the scanned code has an interface which conforms to the general interface definition format, a pseudo interface in the interface which conforms to the general interface definition format is eliminated or the interface does not need to be analyzed according to a preset elimination strategy, and the remaining interface after the pseudo interface is eliminated or the interface does not need to be analyzed is determined as the interface where the program to be analyzed and the test case exist.
In engineering practice, an "interface" conforming to an interface common definition format is sometimes not a true interface, i.e., a pseudo interface, for example, in some program languages, a conditional statement such as an "if" statement (e.g., if () { }), whose syntax also conforms to the interface common definition format in a formal view, but is obviously not an interface. In addition, there are some interfaces, although they are true interfaces, which belong to interfaces that do not need to be analyzed, such as internal call interfaces, where the internal call interface refers to an interface that conforms to the interface common definition format but does not belong to the declared interface in the method body (e.g., methods in the foregoing embodiments), such as the this method call in function1 and the anonymous function call in function2 in the following code:
Figure BDA0002526962070000071
the above are examples of pseudo interfaces in interfaces conforming to the interface common definition format or interfaces that do not need to be analyzed, and are also interfaces that need to be excluded according to a predetermined exclusion policy.
In this embodiment, some pseudo interfaces or generic format templates of the pseudo interfaces and some non-analysis-required interfaces may be summarized into one form to form a non-analysis-required interface white list, for example, if statements, for statements, and the like in the program language belong to the pseudo interfaces, and interfaces that are not suitable for interface testing due to UI verification or internal call interfaces that have been covered by other interfaces due to call of a relationship chain belong to the non-analysis-required interfaces, and these "interfaces" may be listed in the non-analysis-required interface white list. As an embodiment of the present application, excluding, according to a predetermined exclusion policy, a dummy interface or no need to analyze an interface from among interfaces conforming to a format of a common definition of an interface may be: and enabling the analysis-free interface white list to filter the interface conforming to the interface general definition format, and filtering out a pseudo interface in the interface conforming to the interface general definition format or not analyzing the interface. By comparing the interface conforming to the interface common definition format identified in step S2021 with the interfaces listed in the analysis-free interface white list, if the interface conforming to the interface common definition format identified in step S2021 exists in the analysis-free interface white list, the interfaces conforming to the interface common definition format identified in step S2021 and existing in the analysis-free interface white list are excluded. Taking pseudo interfaces such as if statements as an example, if the interface identified in step S2021 conforms to the interface common definition format is substantially an if statement, such pseudo interfaces should be excluded; as another example, some internal call interfaces that contain more obvious keywords or interfaces with a format, such as this () method (i.e., this. isload ()), anonymous function (i.e., () { }) in the above-mentioned example method, or, in terms of understanding the source code, non-interfaces that are easier to determine (e.g., functions for logging similar to logger. info () in the above-mentioned example method) are included), and these interfaces in a specific form are listed in the analysis-free interface white list, and as long as the interface conforming to the interface common definition format identified in step S2021 is compared with the interface name in the analysis-free interface white list, if there is an interface in the specific form in the interface conforming to the interface common definition format identified in step S2021, such an interface that does not need to be analyzed should also be excluded.
Considering that various algorithms of the deep learning model are becoming more mature at present, the deep learning model is widely applied to the fields of search technology, data mining, machine learning, machine translation, natural language processing, multimedia learning, voice, recommendation and personalization technologies, etc., the recognition accuracy of the deep learning model in these fields is close to or even exceeds the accuracy of manual recognition, but the efficiency is far better than that of manual recognition, therefore, in the embodiment of the present application, the deep learning model can be combined to exclude a pseudo interface or no need to analyze an interface in an interface conforming to an interface general definition format, specifically, as another embodiment of the present application, the elimination of a pseudo interface or no need to analyze an interface in an interface conforming to an interface general definition format according to a predetermined exclusion policy can be: and inputting the interface conforming to the interface general definition format into a deep learning model, and outputting the program to be analyzed and the interface where the test case exists through the learning of the deep learning model. The deep learning model is any existing deep learning model, such as a convolutional neural network. The deep learning model can be trained by adopting the characteristic information of the interface as a training sample in advance. And inputting the interface which accords with the general interface definition format into the trained deep learning model, wherein the output result is the interface of the program to be analyzed and the test case. For a large and complex program with a large number of interfaces or a program with a large number of pseudo interfaces or without an analysis interface, the method has certain advantages of eliminating the pseudo interfaces or without the analysis interface by combining a deep learning model.
Step S203: and recording the determined relevant information of the interface, wherein the relevant information of the interface comprises an interface name, interface parameters and a mapping relation between the interface and a file where the code is located.
In the embodiment of the present application, the mapping relationship between the 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. The relevant information of the interfaces is sorted and stored into the uncovered interface set.
In this embodiment of the present application, if, when writing codes of a program to be analyzed and a test case, interfaces in the program to be analyzed and the test case are marked according to specifications or according to preferences of programmers, as another embodiment of the present application, scanning the codes of the program to be analyzed and the codes of the test case, and respectively obtaining information related to the interfaces in the program to be analyzed and the test case may also be implemented by a method illustrated in fig. 4, which specifically includes step S401 and step S403, and the following description is given:
step S401: and scanning the codes of the program to be analyzed and the codes of the test cases line by line to acquire interface mark information in the codes.
Unlike the purpose of step S201 illustrated in fig. 2, 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 interface mark information in the code, where the interface mark information may be a mark made to an interface by a programmer during programming, for example, an interface name or other mark information may be directly written in a comment part behind a statement, as shown in fig. 5.
Step S402: and determining the interfaces of the program to be analyzed and the test cases according to the interface mark information acquired in the step S401.
Because the back annotation part of the interface in the code of the program to be analyzed and the code of the test case is directly annotated by using the interface mark information, when the keywords of the interface mark information are read, the interface of the program to be analyzed and the test case can be determined.
Step S403: and recording the relevant information of the interface determined in the step S401, wherein the relevant information includes the name of the interface, the parameters of the interface, and the mapping relationship between the interface and the file where the code is located.
In the embodiment of the present application, the implementation manner of step S403 is the same as the implementation manner of step S203 illustrated in fig. 2, and the related technical features, terms, or explanations may refer to the description of the foregoing embodiment, which is not described herein again.
Step S103: and judging whether the interface of the test case covers the interface of the program to be analyzed or not according to the program to be analyzed and the related information of the interface in the test case.
In the embodiment of the application, according to the specification of software development, the same interface is required to be named the same for the program to be analyzed and the test case. Therefore, judging whether the interface of the test case covers the interface of the program to be analyzed according to the program to be analyzed and the related information of the interface in the test case may be to compare the related information of the interface acquired from the program to be analyzed with the related information of the interface acquired from the test case, so as to judge whether the interface of the test case covers the interface of the program to be analyzed. For example, through comparison of the interface names, if a certain interface existing in the program to be analyzed does not exist in the test case, it may be determined that the program to be analyzed has an interface that is not covered by the interface of the test case.
Step S104: and if the program to be analyzed has an interface which is not covered by the interface of the test case, storing the interface which is not covered by the interface of the test case into the uncovered interface set.
In the embodiment of the present application, the uncovered interface set stores the interfaces that are not covered by the interfaces of the test cases in the program to be analyzed, and other related information, including the version of the program to be analyzed, the number of interfaces (for test cases) that need to be supplemented, the file where the interfaces that need to be supplemented are located, and the names of the interfaces that need to be supplemented, and so on, examples of which are shown in fig. 3.
Considering 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 a specific folder; or, some specific suffixed files have interfaces or files that must be scanned, and in order to reduce unnecessary operations and thus improve efficiency of interface acquisition, in the above embodiment of the present application, before scanning codes of a program to be analyzed and codes of test cases and acquiring interface related information in the program to be analyzed and the test cases, respectively, a scanning range may be determined according to a format or a path that the code may be stored in the file, so as to scan the codes of the program to be analyzed and the codes of the test cases within the determined scanning range.
In order to subsequently use the determined interfaces existing in the program to be analyzed and the test case, in the embodiment of the present application, if the interfaces in the program to be analyzed and the test case do not have the marking information, after the relevant information of the interfaces in the program to be analyzed and the test case can be obtained, the interfaces existing in the program to be analyzed and the test case are marked, and the marking method may be similar to the example shown in fig. 5.
Since software development is usually completed by a team, and other members of the team also need to obtain analysis data of an interface in a program to be analyzed in time, in the embodiment of the present application, after an interface that is not covered by an interface of a test case is stored in an uncovered interface set, the uncovered interface set is sorted and the sorted uncovered interface set is output to related personnel, for example, the related information in the uncovered interface set is shared to members of the team through instant messaging tools such as WeChat and QQ.
It can be known from the method for analyzing the program interface illustrated in fig. 1 above that, unlike the prior art that the interface related information such as the number of interfaces in the program is manually counted 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 codes of the program to be analyzed and the test cases to obtain the interface related information therein. Because the code scanning can be automatically completed through a computer program, compared with a mode of manually analyzing a program interface in the prior art, the technical scheme provided by the application has the advantages of high efficiency, low cost and difficulty in error, and in the development process of large-scale industrialized products, the technical scheme provided by the application has more obvious advantages in the face of complicated code structures and numerous and complicated code quantities.
Referring to fig. 6, it is a schematic structural diagram of an apparatus for analyzing a program interface according to an embodiment of the present application, where the apparatus may be integrated in a computer device such as a terminal, and the apparatus includes a code reading module 601, an interface information obtaining module 602, a determining module 603, and an information saving module 604, where:
the code reading module 601 is configured to read a code of a program to be analyzed and a code of a test case;
an interface information obtaining module 602, configured to scan a code of a program to be analyzed and a code of a test case, and obtain related information of an interface in the program to be analyzed and the test case, respectively;
the judging module 603 is configured to judge whether the interface of the test case already covers the interface of the program to be analyzed according to the program to be analyzed and the related information of the interface in the test case;
the information saving module 604 is configured to, if an interface not covered by the interface of the test case exists in the program to be analyzed, store the interface not covered by the interface of the test case into the uncovered interface set.
In a possible implementation manner, the interface information obtaining module 602 is configured to scan codes of a program to be analyzed and codes of a test case line by line to obtain feature information of an interface in the codes, determine an interface where the program to be analyzed and the test case exist according to the obtained feature information of the interface in the codes, and record related information of the determined interface, where the related information includes an interface name, an interface parameter, and a mapping relationship between the interface and a file where the codes are located; in a possible implementation manner, the interface for determining that the program to be analyzed and the test case exist according to the obtained feature information of the interface in the code may be: judging whether an interface which conforms to the general interface definition format exists in the scanned code according to the general interface definition format, if so, excluding a pseudo interface in the interface which conforms to the general interface definition format or not analyzing the interface according to a preset exclusion strategy; in a possible implementation manner, the excluding, according to the predetermined exclusion policy, a dummy interface or no need to analyze an interface from among the interfaces conforming to the interface common definition format may be: starting an analysis-free interface white list to filter the interface conforming to the interface general definition format, and filtering out a pseudo interface or not needing to analyze the interface; in a possible implementation manner, the excluding, according to the predetermined exclusion policy, a dummy interface or no need to analyze an interface from among the interfaces conforming to the interface common definition format may be: and inputting the interface conforming to the interface general definition format into a deep learning model, and outputting the program to be analyzed and the interface where the test case exists through the learning of the deep learning model.
In a possible implementation manner, the interface information obtaining module 602 is configured to scan codes of a program to be analyzed and codes of a test case line by line to obtain interface tag information in the codes, determine an interface where the program to be analyzed and the test case exist according to the obtained interface tag information in the codes, and record related information of the determined interface, where the related information includes an interface name, an interface parameter, and a mapping relationship between the interface and a file where the codes are located.
In a possible implementation manner, the apparatus of fig. 6 may further include a scan range determining module, configured to determine a scan range according to a format or a path in which a file in which the code may be stored before the interface information obtaining module 602 scans the code of the program to be analyzed and the code of the test case and obtains relevant information of an 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 scan range.
In one possible implementation manner, the apparatus of fig. 6 may further include a marking module and a sorting module, where:
the marking module is configured to mark the interfaces existing in the program to be analyzed and the test case after the interface information obtaining module 602 obtains the relevant information of the interfaces in the program to be analyzed and the test case;
and the sorting module is used for sorting the uncovered interface set and outputting the sorted uncovered interface set to related personnel after the interfaces which are not covered by the interfaces of the test cases are stored in the uncovered interface set.
It should be noted that, when the device for analyzing a program interface provided in the foregoing embodiment analyzes a program interface, only the division of the above functional modules is illustrated, and in practical applications, the above functions may be distributed to different functional modules according to needs, that is, the internal structure of the device may be divided into different functional modules to complete all or part of the above described functions. In addition, the apparatus for analyzing a program interface and the method for analyzing a program interface provided in the above embodiments belong to the same concept, and specific implementation processes and technical effects thereof are described in detail in the method embodiments and are not described herein again.
An embodiment of the present application further provides a computer device, where the computer device may be a terminal or a server, and as shown in fig. 7, a schematic structural diagram of the computer device according to the embodiment of the present application is shown, specifically:
the computer device may include components such as a processor 701 of one or more processing cores, memory 702 of one or more computer-readable storage media, a power supply 703, and an input unit 704. Those skilled in the art will appreciate that the computer device configuration illustrated in FIG. 7 does not constitute a limitation of computer devices, and may include more or fewer components than those illustrated, or some components may be combined, or a different arrangement of components. Wherein:
the processor 701 is a control center of the computer apparatus, connects various parts of the entire computer apparatus using various interfaces and lines, and performs various functions of the computer apparatus and processes data by running or executing software programs and/or modules stored in the memory 702 and calling data stored in the memory 702, thereby monitoring the computer apparatus as a whole. Optionally, processor 701 may include one or more processing cores; preferably, the processor 701 may integrate an application processor, which mainly handles operating systems, user interfaces, application programs, etc., and a modem processor, which mainly handles wireless communications. It will be appreciated that the modem processor described above may not be integrated into the processor 701.
The memory 702 may be used to store software programs and modules, and the processor 701 executes various functional applications and data processing by operating 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 program required by at least one function (such as a sound playing function, an image playing function, etc.), and the like; the storage data area may store data created according to use of the computer device, and the like. Further, the memory 702 may include high speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other volatile solid state storage device. Accordingly, the memory 702 may also include a memory controller to provide the processor 701 with access to the memory 702.
The computer device further includes a power source 703 for supplying power to each component, and optionally, the power source 703 may be logically connected to the processor 701 through a power management system, so that functions of managing charging, discharging, power consumption, and the like are implemented through the power management system. The power supply 703 may also include any component including one or more of a dc or ac power source, a recharging system, a power failure detection circuit, a power converter or inverter, a power status indicator, and the like.
The computer device may also include an input unit 704, the input unit 704 being operable to receive input numeric or character information and generate keyboard, mouse, joystick, optical or trackball signal inputs related to user settings and function control.
Although not shown, the computer device may further include a display unit and the like, which are not described in detail herein. Specifically, in this embodiment, the processor 701 in the computer device loads 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 runs the application program stored in the memory 702, thereby implementing various functions as follows: reading codes of a program to be analyzed and codes of test cases; scanning a code of a program to be analyzed and a code of a test case, and respectively acquiring related information of an interface in the program to be analyzed and the test case; judging whether the interface of the test case covers the interface of the program to be analyzed or not according to the program to be analyzed and the related information of the interface in the test case; and if the program to be analyzed has an interface which is not covered by the interface of the test case, storing the interface which is not covered by the interface of the test case into the uncovered interface set.
For the above embodiments, reference may be made to the foregoing embodiments, and details are not described herein.
Therefore, different from the prior art that interface related information such as the number of interfaces in a program is manually counted in a mode of reading a program code, the technical scheme of the invention is that the interface related information in the program to be analyzed is acquired by scanning the codes of the program to be analyzed and the test case to analyze the interface in the program to be analyzed. Because the code scanning can be automatically completed through a computer program, compared with a mode of manually analyzing a program interface in the prior art, the technical scheme provided by the application has the advantages of high efficiency, low cost and difficulty in error, and in the development process of large-scale industrialized products, the technical scheme provided by the application has more obvious advantages in the face of complicated code structures and numerous and complicated code quantities.
It will be understood by those skilled in the art that all or part of the steps of the methods of the above embodiments may be performed by instructions or by associated hardware controlled by the instructions, which may be stored in a computer readable storage medium and loaded and executed by a processor.
To this end, embodiments of the present application provide 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 for analyzing a program interface provided by the embodiments of the present application. For example, the instructions may perform the steps of: reading codes of a program to be analyzed and codes of test cases; scanning a code of a program to be analyzed and a code of a test case, and respectively acquiring related information of an interface in the program to be analyzed and the test case; judging whether the interface of the test case covers the interface of the program to be analyzed or not according to the program to be analyzed and the related information of the interface in the test case; and if the program to be analyzed has an interface which is not covered by the interface of the test case, storing the interface which is not covered by the interface of the test case into the uncovered interface set.
The above detailed implementation of each operation can refer to the foregoing embodiments, and is not described herein again.
Wherein the computer-readable storage medium may include: read Only Memory (ROM), Random Access Memory (RAM), magnetic or optical disks, and the like.
Since the instructions stored in the computer-readable storage medium can execute the steps in any method for analyzing a program interface provided in the embodiments of the present application, the beneficial effects that can be achieved by any method for analyzing a program interface provided in the embodiments of the present application can be achieved, for details, see the foregoing embodiments, and are not described herein again.
The method, the apparatus, the computer device, and the computer-readable storage medium for analyzing a program interface provided in the embodiments of the present application are described in detail above, and a specific example is applied in the present application to explain the principles and embodiments of the present application, and the description of the above embodiments is only used to help understand the method and the core idea of the present application; meanwhile, for those skilled in the art, according to the idea of the present application, there may be variations in the specific embodiments and the application scope, and in summary, the content of the present specification should not be construed as a limitation to the present application.

Claims (10)

1. A method of analyzing a program interface, the method comprising:
reading codes of a program to be analyzed and codes of test cases;
scanning the code of the program to be analyzed and the code of the test case, and respectively acquiring related information of an interface in the program to be analyzed and the test case;
judging whether the interface of the test case covers the interface of the program to be analyzed or not according to the related information of the program to be analyzed and the interface in the test case;
and if the program to be analyzed has an interface which is not covered by the interface of the test case, storing the interface which is not covered by the interface of the test case into an uncovered interface set.
2. The method for analyzing program interfaces according to claim 1, wherein the scanning the codes of the program to be analyzed and the codes of the test cases to obtain the related information of the interfaces in the program to be analyzed and the test cases, respectively, includes:
scanning the code of the program to be analyzed and the code of the test case line by line to acquire characteristic information of an interface in the code;
determining the interfaces of the program to be analyzed and the test cases according to the characteristic information of the interfaces;
and recording the relevant information of the determined interface, wherein the relevant information comprises an interface name, interface parameters and a mapping relation between the interface and the file where the code is located.
3. The method for analyzing program interfaces according to claim 2, wherein the determining the interfaces where the program to be analyzed and the test cases exist according to the characteristic information of the interfaces comprises:
judging whether an interface which conforms to the interface general definition format exists in the scanned code according to the interface general definition format;
and if the scanned code has an interface which conforms to the universal interface definition format, excluding a pseudo interface in the interface which conforms to the universal interface definition format or not analyzing the interface according to a preset exclusion strategy.
4. The method for parsing an interface of a program according to claim 3, wherein said excluding, according to a predetermined exclusion policy, a dummy interface or no need to parse an interface from among the interfaces conforming to the universal definition format of the interface comprises:
and enabling an analysis-free interface white list to filter the interface conforming to the interface general definition format, and filtering the pseudo interface or not needing to analyze the interface.
5. The method for parsing an interface of a program as recited in claim 3, wherein said excluding, according to a predetermined exclusion policy, a dummy interface or no need to parse an interface from among said interfaces conforming to said universal definition format of an interface comprises
And inputting the interface conforming to the interface general definition format into a deep learning model, and outputting the interfaces of the program to be analyzed and the test case through the learning of the deep learning model.
6. The method for analyzing program interfaces according to claim 1, wherein the scanning the codes of the program to be analyzed and the codes of the test cases to obtain the interface-related information in the program to be analyzed and the test cases, respectively, includes:
scanning the code of the program to be analyzed and the code of the test case line by line to acquire interface mark information in the code;
determining interfaces of the program to be analyzed and the test case according to the interface mark information;
and recording the relevant information of the determined interface, wherein the relevant information comprises an interface name, interface parameters and a mapping relation between the interface and the file where the code is located.
7. The method according to any one of claims 1 to 6, wherein before the scanning the codes of the program to be analyzed and the test cases and acquiring the interface-related information in the program to be analyzed and the test cases, respectively, the method further comprises:
and determining the scanning range according to a format or a path which can be stored in a 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 in the range.
8. The method of analyzing a program interface of any one of claims 1 to 6, further comprising:
after acquiring the relevant information of the 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 the interfaces which are not covered by the interfaces of the test cases are stored in an uncovered interface set, the uncovered interface set is sorted, and the sorted uncovered interface set is output to related personnel.
9. An apparatus for analyzing a program interface, the apparatus comprising:
the code reading module is used for reading codes of the program to be analyzed and codes of the test cases;
the interface information acquisition module is used for scanning the code of the program to be analyzed and the code of the test case and respectively acquiring the relevant information of the interface in the program to be analyzed and the test case;
the judging module is used for judging whether the interface of the test case covers the interface of the program to be analyzed or not according to the program to be analyzed and the related information of the interface in the test case;
and the information storage module is used for storing the interface which is not covered by the interface of the test case into an uncovered interface set if the program to be analyzed has the interface which is not covered by the interface of the test case.
10. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that the processor implements the steps of the method according to any one of claims 1 to 8 when executing the computer program.
CN202010507201.6A 2020-06-05 2020-06-05 Method and device for analyzing program interface and computer equipment Pending CN113760690A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010507201.6A CN113760690A (en) 2020-06-05 2020-06-05 Method and device for analyzing program interface and computer equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010507201.6A CN113760690A (en) 2020-06-05 2020-06-05 Method and device for analyzing program interface and computer equipment

Publications (1)

Publication Number Publication Date
CN113760690A true CN113760690A (en) 2021-12-07

Family

ID=78785145

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010507201.6A Pending CN113760690A (en) 2020-06-05 2020-06-05 Method and device for analyzing program interface and computer equipment

Country Status (1)

Country Link
CN (1) CN113760690A (en)

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109144879A (en) * 2018-09-03 2019-01-04 腾讯科技(深圳)有限公司 Method for testing and analyzing and device
CN109918294A (en) * 2019-01-29 2019-06-21 刘建鹏 A kind of autonomous controllability detection method of mixed source software and system
CN109976999A (en) * 2017-12-28 2019-07-05 北京京东尚科信息技术有限公司 The measure and measurement apparatus of test case coverage rate
CN110727597A (en) * 2019-10-15 2020-01-24 杭州安恒信息技术股份有限公司 Method for completing use case based on log troubleshooting invalid codes
CN110750459A (en) * 2019-10-23 2020-02-04 天津汇缘诚信科技有限公司 White box analysis-based method for automatically generating test cases and managing test processes
CN110795069A (en) * 2018-08-02 2020-02-14 Tcl集团股份有限公司 Code analysis method, intelligent terminal and computer readable storage medium

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109976999A (en) * 2017-12-28 2019-07-05 北京京东尚科信息技术有限公司 The measure and measurement apparatus of test case coverage rate
CN110795069A (en) * 2018-08-02 2020-02-14 Tcl集团股份有限公司 Code analysis method, intelligent terminal and computer readable storage medium
CN109144879A (en) * 2018-09-03 2019-01-04 腾讯科技(深圳)有限公司 Method for testing and analyzing and device
CN109918294A (en) * 2019-01-29 2019-06-21 刘建鹏 A kind of autonomous controllability detection method of mixed source software and system
CN110727597A (en) * 2019-10-15 2020-01-24 杭州安恒信息技术股份有限公司 Method for completing use case based on log troubleshooting invalid codes
CN110750459A (en) * 2019-10-23 2020-02-04 天津汇缘诚信科技有限公司 White box analysis-based method for automatically generating test cases and managing test processes

Similar Documents

Publication Publication Date Title
US20210334093A1 (en) Automating Identification of Code Snippets for Library Suggestion Models
US11340896B2 (en) Library model addition
US11494181B2 (en) Automating generation of library suggestion engine models
CN106909510B (en) Method for obtaining test case and server
CN112394942B (en) Distributed software development compiling method and software development platform based on cloud computing
US11579856B2 (en) Multi-chip compatible compiling method and device
CN110990019B (en) Java class analysis method and device, storage medium and electronic equipment
CN109918081B (en) Compiling method and compiler
CN110673854A (en) SAS language compiling method, device, equipment and readable storage medium
US20110126179A1 (en) Method and System for Dynamic Patching Software Using Source Code
US9311077B2 (en) Identification of code changes using language syntax and changeset data
CN110347588B (en) Software verification method, device, computer equipment and storage medium
US8881126B2 (en) Systems and methods for testing a compiler through compile-time decision feedback
Rahman et al. A DSL for importing models in a requirements management system
KR20090011974A (en) Method for extracting the target files of compilation
CN112783736B (en) Method and device for monitoring running body time of software component and electronic equipment
CN113760690A (en) Method and device for analyzing program interface and computer equipment
CN114064601B (en) Storage process conversion method, device, equipment and storage medium
CN115129598A (en) Risk detection method, device, system and medium for SQL (structured query language) statements
CN113961238A (en) Object conversion method and device, electronic equipment and storage medium
CN114089980A (en) Programming processing method, device, interpreter and nonvolatile storage medium
CN113448874A (en) Method and device for generating unit test script
CN113672638A (en) Method, system and electronic equipment for querying data
CN112559345A (en) LoadRunner-based interface testing method, computer equipment and storage medium
CN112596737A (en) Method, system, equipment and storage medium for scanning function call relation

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination