CN114780429A - Method, device and equipment for determining code coverage rate and storage medium - Google Patents

Method, device and equipment for determining code coverage rate and storage medium Download PDF

Info

Publication number
CN114780429A
CN114780429A CN202210491782.8A CN202210491782A CN114780429A CN 114780429 A CN114780429 A CN 114780429A CN 202210491782 A CN202210491782 A CN 202210491782A CN 114780429 A CN114780429 A CN 114780429A
Authority
CN
China
Prior art keywords
code
identification information
target code
determining
execution
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
CN202210491782.8A
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.)
Industrial and Commercial Bank of China Ltd ICBC
Original Assignee
Industrial and Commercial Bank of China Ltd ICBC
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 Industrial and Commercial Bank of China Ltd ICBC filed Critical Industrial and Commercial Bank of China Ltd ICBC
Priority to CN202210491782.8A priority Critical patent/CN114780429A/en
Publication of CN114780429A publication Critical patent/CN114780429A/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/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/362Software debugging
    • G06F11/3644Software debugging by instrumenting at runtime

Abstract

The disclosure provides a method for determining code coverage, which can be applied to the field of finance. The method comprises the following steps: acquiring first identification information of the target code, wherein the first identification information comprises identification information of a piling position in the target code; responding to the test operation in a preset time period, and determining first execution information corresponding to the test operation, wherein the first execution information comprises an execution record of a code corresponding to the piling position in the target code; acquiring historical first execution information in a preset time period; determining second execution information according to the first execution information and historical first execution information, wherein the second execution information comprises the execution times of the corresponding code of the piling position in the target code in a preset time period; and determining the code coverage rate of the target code according to the first identification information and the second execution information. The present disclosure also provides a code coverage determination apparatus, a device, a storage medium, and a program product.

Description

Method, device, equipment and storage medium for determining code coverage rate
Technical Field
The present disclosure relates to the field of finance, and in particular, to the field of information testing, and in particular, to a method and an apparatus for determining code coverage, an electronic device, a computer-readable storage medium, and a computer program product.
Background
The program test coverage rate is one of effective standards for verifying the code test quality in the computer software development process. At present, high-level programming languages such as c + +, java and c # have perfect code coverage rate statistical tools. However, for an SQL (Structured Query Language) storage process, the related art can only count the coverage of a single test, and cannot count the coverage of multiple tests in the storage process. In addition, in the process of counting and storing the code coverage rate of the process, the piling tool adopted by the related technology depends on a toolkit provided by the Oracle database, and the piling tool cannot be suitable for databases of other forms.
Disclosure of Invention
In view of the above, the present disclosure provides a code coverage determination method, apparatus, electronic device, computer-readable storage medium, and computer program product for determining code coverage for multiple tests over a period of time.
According to a first aspect of the present disclosure, there is provided a method for determining code coverage, including: acquiring first identification information of the target code, wherein the first identification information comprises identification information of a piling position in the target code; responding to the test operation in a preset time period, and determining first execution information corresponding to the test operation, wherein the first execution information comprises an execution record of a code corresponding to the piling position in the target code; acquiring historical first execution information in a preset time period; determining second execution information according to the first execution information and historical first execution information, wherein the second execution information comprises the execution times of the code corresponding to the piling position in the target code in a preset time period; and determining the code coverage rate of the target code according to the first identification information and the second execution information.
According to an embodiment of the present disclosure, the target code includes a plurality of branch test codes, wherein determining, in response to the test operation within the preset time period, first execution information corresponding to the test operation includes: responding to a preset test operation in a preset time period, and determining a preset branch test code; and determining an execution record corresponding to the piling position code in the preset branch test code based on the preset branch test code.
According to an embodiment of the present disclosure, determining the code coverage of the target code according to the first identification information and the second execution information includes: determining the total branch number of the target code according to the first identification information; determining the number of test branches of the target code according to the second execution information; and determining the code coverage rate of the target code according to the ratio of the total branch number to the test branch number.
According to an embodiment of the present disclosure, wherein obtaining the first identification information of the object code includes: piling the branch position in the target code under the condition that the piling state of the target code is determined to be not started to obtain updated first identification information of the target code; and under the condition that the piling state of the target code is determined to be finished, determining first identification information of the target code according to historical first identification information of the target code in the historical piling process.
According to an embodiment of the present disclosure, wherein piling the branch position in the target code, and obtaining the updated first identification information of the target code includes: analyzing the target code and determining the syntax tree structure data of the target code; determining the branch position in the target code according to the syntax tree structure data; piling the branch position to obtain updated first identification information of the target code.
According to an embodiment of the present disclosure, further comprising: after the current piling process of the branch position in the target code is finished, second identification information of the target code is determined, wherein the second identification information is the unique identification information of each line of codes in the target code; acquiring historical second identification information of the target code, wherein the historical second identification information is second identification information of a previous piling process of the current piling process; and updating the second execution information according to the second identification information under the condition that the second identification information is different from the historical second identification information.
According to a second aspect of the present disclosure, there is provided a code coverage determination apparatus including: the first acquisition module is used for acquiring first identification information of the target code, wherein the first identification information comprises identification information of a piling position in the target code; the first determining module is used for responding to the test operation in the preset time period and determining first execution information corresponding to the test operation, wherein the first execution information comprises an execution record of a code corresponding to the piling position in the target code; the second acquisition module is used for acquiring historical first execution information in a preset time period; the second determining module is used for determining second execution information according to the first execution information and historical first execution information, wherein the second execution information comprises the execution times of the code corresponding to the piling position in the target code in a preset time period; and the third determining module is used for determining the code coverage rate of the target code according to the first identification information and the second execution information.
According to a third aspect of the present disclosure, there is provided an electronic device comprising: one or more processors; a memory for storing one or more instructions, wherein the one or more instructions, when executed by the one or more processors, cause the one or more processors to implement the method for determining code coverage described above.
According to a fourth aspect of the present disclosure, there is provided a computer-readable storage medium having stored thereon executable instructions that, when executed by a processor, cause the processor to implement the above-described code coverage determination method.
According to a fifth aspect of the present disclosure, there is provided a computer program product comprising computer executable instructions for implementing the above code coverage determination method when executed.
Drawings
The foregoing and other objects, features and advantages of the disclosure will be apparent from the following description of embodiments of the disclosure, which proceeds with reference to the accompanying drawings, in which:
fig. 1 schematically shows a system architecture of a code coverage determination method according to an embodiment of the present disclosure;
FIG. 2 schematically illustrates a flow chart of a method of code coverage determination according to an embodiment of the disclosure;
FIG. 3 schematically illustrates a flow chart of a method of determining first performance information according to an embodiment of the disclosure;
FIG. 4 schematically illustrates a flow chart of a method of determining code coverage in accordance with a particular embodiment of the present disclosure;
fig. 5 schematically shows a flow chart of a method of obtaining first identification information according to an embodiment of the present disclosure;
FIG. 6 schematically illustrates a flow chart of a method of determining to update first identification information according to an embodiment of the present disclosure;
FIG. 7 schematically illustrates a flow chart of a method of updating second performance information according to an embodiment of the disclosure;
fig. 8 is a block diagram schematically illustrating a structure of a code coverage determination apparatus according to an embodiment of the present disclosure; and
fig. 9 schematically shows a block diagram of an electronic device adapted to a code coverage determination method according to an embodiment of the present disclosure.
Detailed Description
Hereinafter, embodiments of the present disclosure will be described with reference to the accompanying drawings. It should be understood that these descriptions are illustrative only and are not intended to limit the scope of the present disclosure. In the following detailed description, for purposes of explanation, numerous specific details are set forth in order to provide a thorough understanding of the embodiments of the disclosure. It may be evident, however, that one or more embodiments may be practiced without these specific details. Moreover, in the following description, descriptions of well-known structures and techniques are omitted so as to not unnecessarily obscure the concepts of the present disclosure.
The terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the disclosure. The terms "comprises," "comprising," and the like, as used herein, specify the presence of stated features, steps, operations, and/or components, but do not preclude the presence or addition of one or more other features, steps, operations, or components.
All terms (including technical and scientific terms) used herein have the same meaning as commonly understood by one of ordinary skill in the art unless otherwise defined. It is noted that the terms used herein should be interpreted as having a meaning that is consistent with the context of this specification and should not be interpreted in an idealized or overly formal sense.
Where a convention analogous to "at least one of A, B and C, etc." is used, in general such a construction is intended in the sense one having skill in the art would understand the convention (e.g., "a system having at least one of A, B and C" would include but not be limited to systems that have a alone, B alone, C alone, a and B together, a and C together, B and C together, and/or A, B, C together, etc.).
An embodiment of the present disclosure provides a method for determining code coverage, including: acquiring first identification information of the target code, wherein the first identification information comprises identification information of a piling position in the target code; responding to the test operation in a preset time period, and determining first execution information corresponding to the test operation, wherein the first execution information comprises an execution record of a piling position corresponding code in the target code; acquiring historical first execution information in a preset time period; determining second execution information according to the first execution information and historical first execution information, wherein the second execution information comprises the execution times of the corresponding code of the piling position in the target code in a preset time period; and determining the code coverage rate of the target code according to the first identification information and the second execution information.
Fig. 1 schematically shows a system architecture of a code coverage determination method according to an embodiment of the present disclosure.
As shown in fig. 1, a system architecture 100 according to this embodiment may include terminal devices 101, 102, 103, a network 104, and a server 105. The network 104 serves as a medium for providing communication links between the terminal devices 101, 102, 103 and the server 105. Network 104 may include various connection types, such as wired, wireless communication links, or fiber optic cables, among others.
The user may use the terminal devices 101, 102, 103 to interact with the server 105 via the network 104 to receive or send messages or the like. Various applications may be installed on the terminal devices 101, 102, 103, such as shopping-like applications, web browser applications, search-like applications, instant messaging tools, mailbox clients, social platform software, etc. (by way of example only).
The terminal devices 101, 102, 103 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like.
The server 105 may be a server providing various services, such as a background management server (for example only) providing support for websites browsed by users using the terminal devices 101, 102, 103. The background management server may analyze and perform other processing on the received data such as the user request, and feed back a processing result (e.g., a webpage, information, or data obtained or generated according to the user request) to the terminal device.
It should be noted that the method for determining the code coverage provided by the embodiment of the present disclosure may be generally executed by the server 105. Accordingly, the code coverage determination apparatus provided by the embodiment of the present disclosure may be generally disposed in the server 105. The method for determining code coverage provided by the embodiments of the present disclosure may also be performed by a server or a server cluster different from the server 105 and capable of communicating with the terminal devices 101, 102, 103 and/or the server 105. Accordingly, the code coverage determination apparatus provided by the embodiment of the present disclosure may also be disposed in a server or a server cluster different from the server 105 and capable of communicating with the terminal apparatuses 101, 102, 103 and/or the server 105.
It should be understood that the number of terminal devices, networks, and servers in fig. 1 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for an implementation.
The method for determining the code coverage of the disclosed embodiment will be described in detail below with reference to fig. 2 to 7 based on the system architecture described in fig. 1.
Fig. 2 schematically shows a flow chart of a method of determining code coverage according to an embodiment of the present disclosure.
As shown in fig. 2, the method includes operations S210 to S250.
According to an embodiment of the present disclosure, a stored procedure is a database object, which can be regarded as a function or a subroutine of a database, belonging to a specific code combination in the database. Storing procedures means storing complex programs in a database for external program calls. One storage process comprises branches, namely a plurality of selection statements, and the plurality of selection statements correspond to a plurality of conditions. The target code tested by the present disclosure is the storage process.
In operation S210, first identification information of the target code is acquired, the first identification information including identification information of a piling position in the target code.
According to an embodiment of the present disclosure, the stored procedures contain line code that conforms to the stored logic of the stored procedures. In the case where different stored procedures contain the same line code data, there may be differences in the logical information that the line code data expresses in the different stored procedures. For example, the execution code in different storage processes differs for the same selection condition. Therefore, in a round of test, the target storage process, i.e. the target code, to be tested needs to be determined.
According to the embodiment of the disclosure, in the case of determining an object code, first identification information of the object code is acquired. The first identification information includes identification information of a piling position in the object code, and the first identification information may be acquired from a storage database. The object code comprises a plurality of selection sentences, different selection sentences correspond to different branch storage paths, and the piling position in the first identification information is the position of the selection sentences in the object code.
According to an embodiment of the present disclosure, the first identification information recorded in the storage database may be in the form of a piling row storage table. For example, the object code is storage procedure 1, and the data in the pile driving line storage table is "[ reference numeral 1, storage procedure 1, line number 2], [ reference numeral 2, storage procedure 2, line number 4] … [ reference numeral n, storage procedure m, line number i ]", which indicates the storage procedure to which the pile driving line belongs, and the line number thereof in the storage procedure. At this time, the first identification information of all the piling positions of the target code obtained from the piling row storage table, that is, the first identification information of which the target code is the storage process 1, may be "[ reference numeral 1, storage process 1, row number 2] … [ reference numeral n, storage process 1, row number i ]".
In operation S220, in response to a test operation within a preset period, first execution information corresponding to the test operation is determined.
According to an embodiment of the present disclosure, the first execution information includes an execution record of a piling position corresponding code in the target code. And responding to the test operation in the preset time period, and determining first execution information corresponding to the test operation. The first performance information may be recorded in a storage database.
According to an embodiment of the present disclosure, the form of the record storing the first execution information in the database may include a pile driving row executed record storage table. In a case where the piling position corresponding code is executed, the first execution information is stored in the piling row executed record storage table.
For example, behavior 2 of the object code selects a statement, two selection conditions being: the branch condition a1 and the branch condition a2 record the first execution information in the pile driving line executed record storage table in the case where the code of the 2 nd line is executed, and specifically, the recording form of the first execution information may be "store procedure 1, execution a 1".
In operation S230, historical first execution information within a preset period is acquired.
According to the embodiment of the disclosure, a tester can perform a plurality of test operations within a preset time period, and each test operation can be a test operation for different branches in the same target code. And under the condition of determining the first execution information, determining the current target code according to the first execution information, and further determining historical first execution information of the current target code in the preset time period.
According to the embodiment of the present disclosure, the obtaining of the historical first execution information may be obtained by a storage database, and specifically, the historical first execution information may be obtained according to a record storage table in the storage database in which the pile driving is executed.
In operation S240, second execution information is determined according to the first execution information and the historical first execution information.
According to the embodiment of the present disclosure, the second execution information includes the number of times of execution of the piling position corresponding code in the target code within a preset period. The second performance information may be recorded in a storage database. The form of the record of the second execution information in the storage database may include a pile driving row executed number summary storage table.
According to the embodiment of the present disclosure, the first execution information and the historical first execution information are both execution records of the pile driving position corresponding code in the target code within a preset period of time. Since there may be overlapping branch test codes in multiple operations within a preset time period, in the case of calculating the code coverage, the overlapping branch test codes need to be determined, so as to avoid repeatedly calculating the coverage of the branch test codes. Therefore, the number of times of execution of the pile driving position corresponding code within the preset period can be determined from the first execution information and the execution record of the historical first execution information.
For example, the object code is store procedure 1, action 2 pile driving position, the first execution record is "store procedure 1, execute a 1", the historical first execution record is "store procedure 1, execute a 1", and "store procedure 1, execute a 1". I.e., line 2 is executed 3 times within a preset time period, the second execution information obtained from the first execution information and the historical first execution information may be in the form of "store procedure 1, line 2, execute a1, 3 times".
In operation S250, a code coverage of the object code is determined according to the first identification information and the second execution information.
According to the embodiment of the present disclosure, since the first identification information includes identification information of the piling position in the target code, all the piling positions can embody all code information of the target code. According to the execution times of the execution codes in the second execution information, the overlapped branch test codes can be determined, and further specific execution code information in a preset time period is determined. The code coverage of the target code is determined based on the entire code information determined by the first identification information and the specific execution code information determined by the second execution information.
According to the method and the device, the test record corresponding to the test operation in the preset time period can be obtained by obtaining the first execution information of the tester in the preset time period; further obtaining second execution information by combining the historical test records, and counting the second execution information in a preset time period to obtain the test execution records of all the test codes; and then combining the identification information of the piling position according to the second execution information, thereby realizing the coverage rate of a plurality of tests for summarizing the target code in a preset time period.
Fig. 3 schematically illustrates a flow chart of a method of determining first performance information according to an embodiment of the present disclosure.
As shown in fig. 3, the first execution information method of this embodiment includes operations S321 to S322, which may be a specific embodiment of operation S220.
According to an embodiment of the present disclosure, operation S220 is to perform a plurality of test operations within a preset time period in response to the test operation within the preset time period, where each test operation may test a different part of the target code, that is, the target code includes a plurality of branch test codes.
In operation S321, a preset branch test code is determined in response to a preset test operation within a preset period.
According to an embodiment of the present disclosure, the pile driving position is a position of a selection statement in the target code, i.e., a branch position. And responding to a preset test operation in a preset time period, determining a selection result of a selection statement needing to be tested, and further determining a preset branch test code under the selection result.
In operation S322, based on the preset branch test code, an execution record corresponding to a piling position code in the preset branch test code is determined.
According to the embodiment of the disclosure, after the preset branch test code is determined, a test can be performed by using the preset branch test code, and an execution record of a corresponding piling position code is generated after the test is finished.
For example, the target code is a storage process 1, which includes 5 lines of codes, and the 2 nd line of piling position, according to the first identification information, the identification of the 2 nd line can be obtained as: branch condition a1 and branch condition a2, the corresponding two branches being a1 and a2, respectively; action 4 pile position, the sign is: branch conditions B1 and B2, corresponding to two branches B1 and B2, respectively, and branch conditions B1 and B2 are branches in a 2. The object code contains 3 branches "a 1", "a 2-b 1", "a 2-b 2".
The preset branch conditions needed to be utilized by the test operation are as follows: the branch condition A2 and the branch condition B1, therefore, the predetermined branch test code determined according to the predetermined test operation is the test code corresponding to the "memory path a 2-B1". After the test is ended, the execution record of the piling position code in the storage path a2-b1 can be determined.
Fig. 4 schematically illustrates a flow chart of a method of determining code coverage according to a specific embodiment of the present disclosure.
As shown in fig. 4, the method for determining the code coverage of this embodiment includes operations S451 to S453, which may be a specific embodiment of operation S250.
In operation S451, a total number of branches of the target code is determined according to the first identification information.
According to the embodiment of the present disclosure, the first identification information includes position identification information of all the piling positions in the target code, and since the piling positions are positions where the branches are located in the target code, the total number of branches of the target code can be determined according to the first identification information.
In operation S452, a number of test branches of the target code is determined according to the second execution information.
According to the embodiment of the disclosure, the second execution information includes the execution times of the piling position corresponding code in the target code within the preset time period, and whether the piling position is executed within the preset time period or not can be obtained according to the second execution information, and the specific test branch information is obtained after the piling position is executed for several times. For example, still taking the target code as the stored procedure 1 as an example, the piling position is the 2 nd line in the target code, and the 2 nd line is executed 0 times, which indicates that all branches below the 2 nd line are not executed in the preset time period; line 2 is executed 1 time and the row 4 piling position is not executed, indicating that the branch to this execution is a 1.
In operation S453, the code coverage of the object code is determined according to a ratio of the total number of branches and the number of test branches.
According to the embodiment of the disclosure, after the information of the total branch number and the test branch number is obtained, the code coverage rate of the target code can be determined according to the ratio of the total branch number and the test branch number. For example, taking row 2 as being executed 1 time and row 4 pile driving position as not being executed, the total number of branches is 3 and the code coverage is 33.3%.
Fig. 5 schematically shows a flowchart of a method of acquiring first identification information according to an embodiment of the present disclosure.
As shown in fig. 5, the method for acquiring the first identification information of this embodiment includes operations S512 to S513, which may be a specific embodiment of operation S210.
According to the embodiment of the present disclosure, the first identification information includes the piling position information of the target code, and thus, the piling state of the target code needs to be determined before the first identification information of the target code is acquired.
In operation S511, in a case where it is determined that the piling state of the object code is not started, piling is performed on the branch position in the object code, resulting in updated first identification information of the object code.
In operation S512, in a case where it is determined that the piling state of the target code is ended, first identification information of the target code is determined according to the historical first identification information of the target code in the historical piling process.
According to an embodiment of the present disclosure, the first identification information includes identification information of all pile driving positions in the object code. After piling is finished, under the condition that the line number of the code changes, the information of the piling position deviates, and the first identification information of the piling position is updated at any time, so that the accuracy of coverage rate calculation can be ensured. For example, when the piling state is already finished and the next test operation is started within a preset time period, the historical first identification information of target code piling is acquired, and the historical first identification information is determined as the first identification information of the current test operation.
Fig. 6 schematically illustrates a flowchart of a method of determining to update first identification information according to an embodiment of the present disclosure.
As shown in fig. 6, the method for determining to update the first identification information according to this embodiment includes operations S6111 to S6113, which may be a specific embodiment of operation S511.
In operation S6111, the target code is parsed, and syntax tree structure data of the target code is determined.
According to the embodiment of the disclosure, the target code may be parsed into the syntax tree by using syntax parsing technology such as antlr 4.
In operation S6112, a branch position in the target code is determined according to the syntax tree structure data.
In operation S6113, the branch position is piled to obtain the first identification information of the target code.
According to the embodiment of the disclosure, the specific piling operation includes parsing the object code, and parsing the object code into the syntax tree structure data. According to the syntax tree structure data obtained by analysis, all the branch position information of the target code can be obtained. After the branch position information is obtained, piling is carried out on all branch positions, and then the first identification information in the target code can be obtained.
According to an embodiment of the present disclosure, piling the branch location includes dividing the branch location by inserting a piece of code that does not affect the target code logic for recording the execution of the target code.
According to the embodiment of the disclosure, before piling, the method further comprises obtaining second execution information according to the first execution information obtained before and the historical first execution information, and recording the test information before piling. Since the program code of the target program may be changed before the pile driving is started, the second execution information is acquired, so that the coverage loss caused by the change of the code line number can be prevented. For example, second execution information corresponding to the last test operation within a preset time period is recorded.
According to the embodiment of the disclosure, before the test coverage rate of the preset time period is counted, the first identification information, the first execution information and the second execution information before the preset time period are cleared, so that the influence of historical data on the calculation of the test coverage rate in the preset time period is prevented.
According to the method and the device, under the condition that the piling state of the target code is determined to be not started, the target code is analyzed, piling is carried out on the target code, piling is carried out without adopting a tool kit DBMS _ PROFILE provided by the oracle, and the applicability of obtaining piling position information is expanded.
Fig. 7 schematically shows a flowchart of a method of updating second execution information according to an embodiment of the present disclosure.
As shown in fig. 7, the method for updating the second execution information of this embodiment includes operations S7121 to S7123, which may be a specific embodiment of operation S512.
In operation S7121, after the current piling process of the branch position in the target code is completed, second identification information of the target code is determined.
In operation S7122, historical second identification information of the object code is obtained, the historical second identification information being second identification information of a previous piling process of the current piling process.
In operation S7123, in case that the second identification information is different from the historical second identification information, the second execution information is updated according to the second identification information.
According to the embodiment of the present disclosure, the second identification information is unique identification information of each line of code in the target code. The second identification information comprises line code text, a storage process to which the line code belongs and same line code position information. In the process of piling the branch position of the target code, the whole target code needs to be traversed. After the piling process is finished, the traversing process of the target code is also finished, and correspondingly, the information of each line of the target code is recorded to obtain the line code text, the storage process to which the line code belongs and the position information of the same line code.
For example, in the case where the line 3 code of the stored procedure 1 is the same as the line 1 code text, the same line code position information of the line 3 code can be represented as 1-1-2, i.e., the 2 nd same line of the line 1 code in the stored procedure 1.
According to the embodiment of the disclosure, the unique identification information of each line code in the object code can be obtained according to the line code text, the storage process to which the line code belongs, and the position information of the same line code. For example, by the Message-Digest Algorithm 5 (MD 5), a unique MD5 identification for each row is calculated.
According to an embodiment of the present disclosure, the second identification information of the object code may be stored in the database in the form of an identification record table, so as to record the second identification information obtained each time.
According to the embodiment of the disclosure, since the second identification information includes the position information of each line of the object code, the historical second identification information is compared with the second identification information, and whether the position information of each line is changed in the piling process can be obtained. For example, when the object code is changed, the target code is "line 1, pile, unique identifier a", "line 2, unique identifier B", "line 3, pile, unique identifier C", and the historical second identification information is A, B, C, respectively, before the change. After piling, "line 1, piling, unique identification a", "line 2, unique identification B", "line 3, unique identification D", "line 4, piling, unique identification C", and second identification information is A, B, C, D. According to the comparison between the historical second identification information and the second identification information, it can be obtained that the target code is changed by adding the existing 3 rd line D before the original 2 nd line B and the original 3 rd line C. And updating the second execution information according to the changed second identification information. The code of the 3 rd line, i.e. C, is executed 1 time in the second execution information that is not updated, the code of the 4 th line, i.e. C, is executed once in the test after piling, and the second execution information is updated to the code line C2 times by comparing the historical second identification information with the second identification information.
According to the method and the device, the unique second identification information is recorded, the historical second identification information is compared with the second identification information, and the second execution information is updated, so that the coverage rate of the last test operation in the preset time period can be inherited, and the coverage rate is prevented from being lost under the condition that the target code is changed.
Fig. 8 schematically shows a block diagram of a code coverage determination apparatus according to an embodiment of the present disclosure.
As shown in fig. 8, the apparatus 800 for determining code coverage of this embodiment includes an obtaining module 810, a first determining module 820, a second obtaining module 830, a second determining module 840, and a third determining module 850.
The first obtaining module 810 is configured to obtain first identification information of the target code, where the first identification information includes identification information of a position where the target code is piled. In an embodiment, the first obtaining module 810 may be configured to perform the operation S210 described above, which is not described herein again.
A first determining module 820, configured to determine, in response to the test operation within the preset time period, first execution information corresponding to the test operation, where the first execution information includes an execution record of a piling position corresponding code in the target code. In an embodiment, the first determining module 820 may be configured to perform the operation S220 described above, and is not described herein again.
The second obtaining module 830 is configured to obtain historical first execution information in a preset time period. In an embodiment, the second obtaining module 830 may be configured to perform the operation S230 described above, and is not described herein again.
A second determining module 840, configured to determine second execution information according to the first execution information and the historical first execution information, where the second execution information includes the execution times of the code corresponding to the piling position in the target code within a preset time period. In an embodiment, the second determining module 840 may be configured to perform the operation S240 described above, which is not described herein again.
And a third determining module 850, configured to determine the code coverage of the target code according to the first identification information and the second execution information. In an embodiment, the third determining module 850 may be configured to perform the operation S250 described above, and is not described herein again.
According to an embodiment of the present disclosure, the first determination module 820 includes a first determination unit and a second determination unit.
The first determination unit is used for responding to a preset test operation in a preset time period and determining a preset branch test code. In an embodiment, the first determining unit may be configured to perform the operation S321 described above, which is not described herein again.
The second determining unit is used for determining an execution record corresponding to the piling position code in the preset branch test code based on the preset branch test code. In an embodiment, the second determining unit may be configured to perform the operation S322 described above, which is not described herein again.
According to an embodiment of the present disclosure, the third determining module 850 includes a third determining unit, a fourth determining unit, and a fifth determining unit.
The third determining unit is used for determining the total branch number of the target code according to the first identification information. In an embodiment, the third determining unit may be configured to perform the operation S451 described above, and is not described herein again.
The fourth determining unit is used for determining the number of the test branches of the target code according to the second execution information. In an embodiment, the fourth determining unit may be configured to perform the operation S452 described above, and is not described herein again.
And the fifth determining unit is used for determining the code coverage rate of the target code according to the ratio of the total branch number to the test branch number. In an embodiment, the fifth determining unit may be configured to perform operation S453 described above, which is not described herein again.
According to an embodiment of the present disclosure, the first obtaining module 810 includes a first obtaining unit and a second obtaining unit.
The first obtaining unit is used for piling the branch position in the target code to obtain the updated first identification information of the target code under the condition that the piling state of the target code is determined to be not started. In an embodiment, the first obtaining unit may be configured to perform the operation S511 described above, which is not described herein again.
The second acquisition unit is used for determining the first identification information of the target code according to the historical first identification information of the target code in the historical piling process under the condition that the piling state of the target code is determined to be finished. In an embodiment, the second obtaining unit may be configured to perform the operation S512 described above, which is not described herein again.
According to an embodiment of the present disclosure, the first acquisition unit includes a first determination subunit, a second determination subunit, and a third determination subunit.
The first determining subunit is used for analyzing the target code and determining the syntax tree structure data of the target code. In an embodiment, the first determining subunit may be configured to perform operation S6111 described above, which is not described herein again.
The second determining subunit is configured to determine a branch position in the object code according to the syntax tree structure data. In an embodiment, the second determining subunit may be configured to perform operation S6112 described above, which is not described herein again.
And the third determining subunit is used for piling the branch position to obtain the first identification information of the target code. In an embodiment, the third determining subunit may be configured to perform operation S6113 described above, which is not described herein again.
According to an embodiment of the present disclosure, the second acquisition unit includes a fourth determination subunit, a fifth determination subunit, and a sixth determination subunit.
The fourth determining subunit is configured to determine the second identification information of the target code after the current piling process of the branch position in the target code is completed. In an embodiment, the fourth determining subunit may be configured to perform operation S7121 described above, and details are not described herein.
The fifth determining subunit is configured to obtain historical second identification information of the target code, where the historical second identification information is second identification information of a previous piling process of the current piling process. In an embodiment, the fifth determining subunit may be configured to perform operation S7122 described above, and is not described herein again.
The sixth determining subunit is configured to update the second execution information according to the second identification information when the second identification information is different from the historical second identification information. In an embodiment, the sixth determining subunit may be configured to perform operation S7123 described above, and details are not described herein.
Fig. 9 schematically shows a block diagram of an electronic device adapted to a method of code coverage determination according to an embodiment of the present disclosure.
As shown in fig. 9, an electronic apparatus 900 according to an embodiment of the present disclosure includes a processor 901 which can perform various appropriate actions and processes in accordance with a program stored in a Read Only Memory (ROM)902 or a program loaded from a storage portion 908 into a Random Access Memory (RAM) 903. Processor 901 may comprise, for example, a general purpose microprocessor (e.g., a CPU), an instruction set processor and/or associated chipset, and/or a special purpose microprocessor (e.g., an Application Specific Integrated Circuit (ASIC)), among others. The processor 901 may also include on-board memory for caching purposes. The processor 901 may comprise a single processing unit or a plurality of processing units for performing the different actions of the method flows according to embodiments of the present disclosure.
In the RAM903, various programs and data necessary for the operation of the electronic apparatus 900 are stored. The processor 901, ROM 902, and RAM903 are connected to each other by a bus 904. The processor 901 performs various operations of the method flows according to the embodiments of the present disclosure by executing programs in the ROM 902 and/or the RAM 903. Note that the programs may also be stored in one or more memories other than the ROM 902 and the RAM 903. The processor 901 may also perform various operations of the method flows according to the embodiments of the present disclosure by executing programs stored in the one or more memories.
Electronic device 900 may also include input/output (I/O) interface 905, input/output (I/O) interface 905 also connected to bus 904, according to an embodiment of the present disclosure. The electronic device 900 may also include one or more of the following components connected to the I/O interface 905: an input portion 906 including a keyboard, a mouse, and the like; an output portion 907 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage portion 908 including a hard disk and the like; and a communication section 909 including a network interface card such as a LAN card, a modem, or the like. The communication section 909 performs communication processing via a network such as the internet. A drive 910 is also connected to the I/O interface 905 as needed. A removable medium 911 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 910 as necessary, so that a computer program read out therefrom is mounted into the storage section 908 as necessary.
The present disclosure also provides a computer-readable storage medium, which may be embodied in the device/apparatus/system described in the above embodiments; or may exist separately and not be assembled into the device/apparatus/system. The computer-readable storage medium carries one or more programs which, when executed, implement a method according to an embodiment of the disclosure.
According to embodiments of the present disclosure, the computer-readable storage medium may be a non-volatile computer-readable storage medium, which may include, for example but is not limited to: a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present disclosure, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. For example, according to embodiments of the present disclosure, a computer-readable storage medium may include the ROM 902 and/or RAM903 described above and/or one or more memories other than the ROM 902 and RAM 903.
Embodiments of the present disclosure also include a computer program product comprising a computer program containing program code for performing the method illustrated in the flow chart. When the computer program product runs in a computer system, the program code is used for causing the computer system to implement the code coverage determination method provided by the embodiment of the disclosure.
The computer program performs the above-described functions defined in the system/apparatus of the embodiments of the present disclosure when executed by the processor 901. The systems, apparatuses, modules, units, etc. described above may be implemented by computer program modules according to embodiments of the present disclosure.
In one embodiment, the computer program may be hosted on a tangible storage medium such as an optical storage device, a magnetic storage device, and the like. In another embodiment, the computer program may also be transmitted in the form of a signal over a network medium, distributed, and downloaded and installed via the communication section 909 and/or installed from the removable medium 911. The computer program containing program code may be transmitted using any suitable network medium, including but not limited to: wireless, wired, etc., or any suitable combination of the foregoing.
In such an embodiment, the computer program may be downloaded and installed from a network through the communication section 909, and/or installed from the removable medium 911. The computer program, when executed by the processor 901, performs the above-described functions defined in the system of the embodiment of the present disclosure. The systems, devices, apparatuses, modules, units, etc. described above may be implemented by computer program modules according to embodiments of the present disclosure.
In accordance with embodiments of the present disclosure, program code for executing computer programs provided by embodiments of the present disclosure may be written in any combination of one or more programming languages, and in particular, these computer programs may be implemented using high level procedural and/or object oriented programming languages, and/or assembly/machine languages. The programming language includes, but is not limited to, programming languages such as Java, C + +, python, the "C" language, or the like. The program code may execute entirely on the user computing device, partly on the user device, partly on a remote computing device, or entirely on the remote computing device or server. In situations involving remote computing devices, the remote computing devices may be connected to the user computing device through any kind of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to external computing devices (e.g., through the internet using an internet service provider).
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems that perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
It will be appreciated by a person skilled in the art that various combinations or/and combinations of features recited in the various embodiments of the disclosure and/or in the claims may be made, even if such combinations or combinations are not explicitly recited in the disclosure. In particular, various combinations and/or combinations of the features recited in the various embodiments of the present disclosure and/or the claims may be made without departing from the spirit and teachings of the present disclosure. All such combinations and/or associations are within the scope of the present disclosure.
The above-described embodiments, objects, technical solutions and advantages of the present disclosure are further described in detail, it should be understood that the above-described embodiments are only examples of the present disclosure, and should not be construed as limiting the present disclosure, and any modifications, equivalent substitutions, improvements and the like made within the spirit and principle of the present disclosure should be included in the protection scope of the present disclosure.

Claims (10)

1. A method of code coverage determination, comprising:
acquiring first identification information of a target code, wherein the first identification information comprises identification information of a piling position in the target code;
responding to a test operation in a preset time period, and determining first execution information corresponding to the test operation, wherein the first execution information comprises an execution record of a piling position corresponding code in the target code;
acquiring historical first execution information in the preset time period;
determining second execution information according to the first execution information and the historical first execution information, wherein the second execution information comprises the execution times of the corresponding code of the piling position in the target code in the preset time period;
and determining the code coverage rate of the target code according to the first identification information and the second execution information.
2. The method of claim 1, wherein the target code comprises a plurality of branch test codes, and wherein the determining, in response to the test operation within the preset time period, first execution information corresponding to the test operation comprises:
responding to a preset test operation in a preset time period, and determining a preset branch test code; and
and determining an execution record corresponding to the piling position code in the preset branch test code based on the preset branch test code.
3. The method of claim 1, the determining code coverage of the object code from the first identifying information and the second executing information comprising:
determining the total branch number of the target code according to the first identification information;
determining the number of test branches of the target code according to the second execution information;
and determining the code coverage rate of the target code according to the ratio of the total branch number to the test branch number.
4. The method of claim 1, wherein the obtaining first identification information of an object code comprises:
when the piling state of the target code is determined to be not started, piling a branch position in the target code to obtain updated first identification information of the target code;
and under the condition that the piling state of the target code is determined to be finished, determining first identification information of the target code according to historical first identification information of the target code in a historical piling process.
5. The method of claim 4, wherein said piling branch locations in the object code, resulting in updated first identification information for the object code, comprises:
analyzing the target code and determining syntax tree structure data of the target code;
determining branch positions in the object code according to the syntax tree structure data;
and piling the branch position to obtain first identification information of the target code.
6. The method of claim 4, further comprising:
after the current piling process of the branch position in the target code is completed, determining second identification information of the target code, wherein the second identification information is unique identification information of each line of codes in the target code;
acquiring historical second identification information of the target code, wherein the historical second identification information is second identification information of a previous piling process of the current piling process;
and under the condition that the second identification information is different from the historical second identification information, updating the second execution information according to the second identification information.
7. A code coverage determination apparatus, comprising:
the device comprises a first acquisition module, a second acquisition module and a display module, wherein the first acquisition module is used for acquiring first identification information of a target code, and the first identification information comprises identification information of a piling position in the target code;
the first determining module is used for responding to a test operation in a preset time period and determining first execution information corresponding to the test operation, wherein the first execution information comprises an execution record of a piling position corresponding code in the target code;
the second acquisition module is used for acquiring historical first execution information in the preset time period;
the second determining module is used for determining second execution information according to the first execution information and the historical first execution information, wherein the second execution information comprises the execution times of the corresponding code of the piling position in the target code in the preset time period;
and the third determining module is used for determining the code coverage rate of the target code according to the first identification information and the second execution information.
8. An electronic device, comprising:
one or more processors;
a memory to store one or more instructions that,
wherein the one or more instructions, when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-6.
9. A computer readable storage medium having stored thereon executable instructions which, when executed by a processor, cause the processor to carry out the method of any one of claims 1 to 6.
10. A computer program product comprising computer executable instructions for implementing the method of any one of claims 1 to 6 when executed.
CN202210491782.8A 2022-05-07 2022-05-07 Method, device and equipment for determining code coverage rate and storage medium Pending CN114780429A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210491782.8A CN114780429A (en) 2022-05-07 2022-05-07 Method, device and equipment for determining code coverage rate and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210491782.8A CN114780429A (en) 2022-05-07 2022-05-07 Method, device and equipment for determining code coverage rate and storage medium

Publications (1)

Publication Number Publication Date
CN114780429A true CN114780429A (en) 2022-07-22

Family

ID=82435429

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210491782.8A Pending CN114780429A (en) 2022-05-07 2022-05-07 Method, device and equipment for determining code coverage rate and storage medium

Country Status (1)

Country Link
CN (1) CN114780429A (en)

Similar Documents

Publication Publication Date Title
US10394705B2 (en) Regression testing of SQL execution plans for SQL statements
US10983789B2 (en) Systems and methods for automating and monitoring software development operations
US10885000B2 (en) Repairing corrupted references
CN109992498B (en) Test case generation method and system and computer system
CN110888817B (en) Code coverage rate report generation method, device and readable storage medium
CN112799940A (en) Regression testing method, device, computer system and computer readable storage medium
CN107291835B (en) Search term recommendation method and device
CN114281663A (en) Test processing method, test processing device, electronic equipment and storage medium
CN111221727B (en) Test method, test device, electronic equipment and computer readable medium
US20190197193A1 (en) Automated tagging application for maintaining up-to-date web analytics
CN110866031B (en) Database access path optimization method and device, computing equipment and medium
CN112954056A (en) Monitoring data processing method and device, electronic equipment and storage medium
CN114780429A (en) Method, device and equipment for determining code coverage rate and storage medium
CN114116480A (en) Method, device, medium and equipment for determining application program test coverage rate
CN114693358A (en) Data processing method and device, electronic equipment and storage medium
CN109697141B (en) Method and device for visual testing
US8321844B2 (en) Providing registration of a communication
CN110704320A (en) Control operation method and device
CN114331116A (en) Data assessment method, equipment, medium and product for business system
CN114637689A (en) Application evaluation method, device, equipment and storage medium
CN113761418A (en) Cache hit rate determination method and device
CN113360380A (en) Method and device for generating data case based on flow chart
CN115658541A (en) Hierarchical regression testing method, apparatus, device, storage medium, and program product
CN115629983A (en) Test case set generation method, device, equipment and medium
CN113760694A (en) Method and device for calculating code coverage rate

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