A method and device for obtaining coverage information

By obtaining information on whether each line of code in the software project has been executed, and directly determining the execution status of the differential code based on the version code differences, the problem of low efficiency in obtaining differential code in the existing technology is solved, and efficient differential code coverage between versions is achieved. Information acquisition.

CN110262966BActive Publication Date: 2024-10-29WEBANK (CHINA)
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN201910477036.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2019-06-03
Publication Date
2024-10-29
Estimated Expiration
2039-06-03

AI Technical Summary

Technical Problem

In the existing technology, when obtaining the coverage information of the differential code between two different versions of a software project, the calculation amount is huge and error-prone, resulting in a long and inefficient process.

Method used

By obtaining the first coverage information, indicating whether each line of code corresponding to the line number has been executed, and determining the difference code based on the first version code and the second version code, directly obtaining whether each line of code in the difference code has been executed in the first version code. The execution information reduces the amount of calculation and error rate and improves efficiency.

Benefits of technology

It greatly reduces the calculation amount and error rate, shortens the process time, and improves the efficiency of obtaining coverage information of difference codes between versions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN110262966B_ABST
    Figure CN110262966B_ABST
Patent Text Reader

Abstract

The present invention discloses a method and device for obtaining coverage information, wherein the method comprises: obtaining first coverage information; the first coverage information is used to indicate whether each line of code corresponding to line numbers 1 to K is executed, wherein when a line of code corresponding to line number i is executed in N version codes, it indicates that the line of code corresponding to line number i is executed, otherwise, it indicates that the line of code corresponding to line number i is not executed; K is the number of lines of code included in the first version code; according to the first version code and the second version code, determining a difference code in the first version code that is different from the second version code; determining second coverage information according to the difference code and the first coverage information; the second coverage information is used to indicate whether each line of code in the difference code is executed in the first version code, and the method can be applied to financial technology (Fintech).
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology of financial technology (Fintech), and in particular to a method and device for obtaining coverage information. Background Art

[0002] With the development of computer technology, more and more technologies (big data, distributed, blockchain, artificial intelligence, etc.) are applied in the financial field, and the traditional financial industry is gradually transforming to financial technology (Fintech). At present, in the field of financial technology, the code of a software project will be frequently modified during a development cycle, so a software project will produce multiple versions during a development cycle. In order to characterize the changes between different versions of the code and the optimization after the code changes, it is often necessary to obtain the coverage information of the difference code between two different versions, that is, the execution of the code in the difference code during the operation of the newer version of the code, such as the number of lines of difference code executed during the operation, the proportion of the number of lines of difference code executed to the total number of lines of difference code, etc.

[0003] In the prior art, when it is necessary to obtain coverage information of the difference codes between two different versions of a software project within a development cycle, the coverage information and code change information of the difference codes between every two adjacent versions of all versions between the two different versions are obtained in sequence, and then the information is deduced one version at a time until the coverage information of the difference codes between the two different versions is obtained.

[0004] Obviously, the methods in the prior art require frequent fetching of codes of various versions, which requires huge computation and is prone to errors. Moreover, it will make the entire process longer. The efficiency of obtaining coverage information of the difference codes between two different versions is low, which is a problem that needs to be solved urgently. Summary of the invention

[0005] The embodiments of the present application provide a method and device for obtaining coverage information, which solves the problems in the prior art that the amount of calculation required for obtaining coverage information is huge, errors are prone to occur, the entire process is relatively long, and the efficiency of obtaining coverage information of difference codes between versions is low.

[0006] An embodiment of the present application provides a coverage information acquisition method, including: acquiring first coverage information; the first coverage information is used to indicate whether each line of code corresponding to line numbers 1 to K is executed, wherein when a line of code corresponding to line number i is executed in N version codes, it means that the line of code corresponding to line number i is executed, otherwise, it means that the line of code corresponding to line number i is not executed; K is the number of lines of code included in the first version code; i is an integer greater than or equal to 1 and less than or equal to K; the first version code is the last submitted code among the N version codes; according to the first version code and the second version code, determine the difference code in the first version code that is different from the second version code; the second version code is the first submitted code among the N version codes; determine the second coverage information according to the difference code and the first coverage information; the second coverage information is used to indicate whether each line of code in the difference code is executed in the first version code.

[0007] In the above method, the first coverage information is obtained, and the first coverage information indicates whether each line of code corresponding to line numbers 1 to K is executed. The method does not need to frequently pull each version code in N version codes to determine the difference code after each version code is submitted. The difference code in the second version code that is different from the first version code can be determined directly based on the first version code and the second version code, thereby greatly reducing the amount of calculation and the error rate, thereby reducing the entire process time, and then according to the difference code and the first coverage information, the second coverage information is obtained, that is, the marking information of whether each line of code in the difference code is executed when the second version code is running. Therefore, this method improves the efficiency of obtaining coverage information of difference codes between versions.

[0008] In an optional implementation, obtaining the first coverage information includes: obtaining N groups of third coverage information; wherein each group of the N groups of third coverage information uniquely corresponds to a version code among the N version codes, and the group of third coverage information is used to indicate whether each line of code in the version code is executed; and merging the N groups of third coverage information into the first coverage information.

[0009] In an optional implementation, each group of the N groups of third coverage information and the first coverage information are both an array, and for the value of any subscript of the array, if the value is a first preset value, it indicates that the code corresponding to the subscript has been executed in the version code corresponding to the group of coverage information, and if the value is a second preset value, it indicates that the code corresponding to the subscript has not been executed in the version code corresponding to the group of coverage information; merging the N groups of third coverage information into the first coverage information includes: according to each subscript in the array of the first coverage information, performing operations on the value of the subscript in the N arrays of the N groups of third coverage information according to a preset operation rule, and using the operation result as the value of the subscript in the array of the first coverage information.

[0010] In an optional implementation, the determining, based on the first version code and the second version code, difference codes in the first version code that differ from the second version code includes: if the first version code contains new codes relative to the second version code, taking the new codes as the first code set; if the first version code contains code blocks that are deleted relative to the second version code, taking a line of code before the first line and a line of code after the last line of the deleted code blocks in the second version code as the second code set; if the first version code contains code blocks whose annotations have changed relative to the second version code, taking the code blocks whose annotations have changed as the third code set; and taking the first code set, the third code set, and all codes in the third code set as the difference codes.

[0011] In an optional implementation, determining the second coverage information based on the difference code and the first coverage information includes: for each line of code in the difference code, if the first coverage information indicates that the line of code is executed, determining that the line of code is executed in the first version code; otherwise, determining that the line of code is not executed in the first version code; and determining the second coverage information based on whether each line of code in the difference code is executed in the first version code.

[0012] An embodiment of the present application provides a coverage information acquisition device, including: an acquisition module, used to acquire first coverage information; the first coverage information is used to indicate whether each line of code corresponding to line numbers 1 to K is executed, wherein when a line of code corresponding to line number i is executed in N version codes, it means that the line of code corresponding to line number i is executed, otherwise, it means that the line of code corresponding to line number i is not executed; K is the number of lines of code included in the first version code; i is an integer greater than or equal to 1 and less than or equal to K; the first version code is the last submitted code among the N version codes; a processing module is used to determine, based on the first version code and the second version code, a difference code in the first version code that is different from the second version code; the second version code is the first submitted code among the N version codes; second coverage information is determined based on the difference code and the first coverage information; the second coverage information is used to indicate whether each line of code in the difference code is executed in the first version code.

[0013] In an optional implementation, the acquisition module is specifically used to: acquire N groups of third coverage information; wherein each group of third coverage information of the N groups of third coverage information uniquely corresponds to a version code among the N version codes, and the group of third coverage information is used to indicate whether each line of code in the version code is executed; and merge the N groups of third coverage information into the first coverage information.

[0014] In an optional implementation, each group of third coverage information of the N groups of third coverage information and the first coverage information are both an array, and for the value of any subscript of the array, if the value is a first preset value, it indicates that the code corresponding to the subscript has been executed in the version code corresponding to the group of coverage information, and if the value is a second preset value, it indicates that the code corresponding to the subscript has not been executed in the version code corresponding to the group of coverage information; the acquisition module is specifically used to: according to each subscript in the array of the first coverage information, perform operations on the value of the subscript in the N arrays of the N groups of third coverage information according to a preset operation rule, and use the operation result as the value of the subscript in the array of the first coverage information.

[0015] In an optional implementation, the processing module is specifically used to: if the first version code contains new code relative to the second version code, use the new code as the first code set; if the first version code contains a code block that is deleted relative to the second version code, use a line of code before the first line and a line of code after the last line of the deleted code block in the second version code as the second code set; if the first version code contains a code block whose annotation has changed relative to the second version code, use the code block whose annotation has changed as the third code set; use the first code set, the third code set, and all codes in the third code set as the difference code.

[0016] In an optional implementation, the processing module is specifically used to: for each line of code in the difference code, if the first coverage information indicates that the line of code is executed, determine that the line of code is executed in the first version code; otherwise, determine that the line of code is not executed in the first version code; and determine the second coverage information based on whether each line of code in the difference code is executed in the first version code.

[0017] An embodiment of the present application provides a computer device, including a program or an instruction. When the program or the instruction is executed, a coverage information acquisition method and an optional method provided in the embodiment of the present application are executed.

[0018] An embodiment of the present application provides a storage medium, including a program or an instruction. When the program or the instruction is executed, a coverage information acquisition method and an optional method provided in the embodiment of the present application are executed. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] Figure 1 This is a schematic diagram of the steps of a method for obtaining coverage information in an embodiment of the present application;

[0020] Figure 2 A system architecture diagram to which a coverage information acquisition method in an embodiment of the present application can be applied;

[0021] Figure 3 A flowchart of the steps of automatically injecting a coverage information agent in a system architecture diagram applicable to a coverage information acquisition method in an embodiment of the present application;

[0022] Figure 4 It is a structural schematic diagram of a coverage information acquisition device in an embodiment of the present application. DETAILED DESCRIPTION

[0023] In order to better understand the above-mentioned technical scheme, the above-mentioned technical scheme will be described in detail below in combination with the accompanying drawings and specific implementation methods of the specification. It should be understood that the embodiments of the present application and the specific features in the embodiments are detailed descriptions of the technical scheme of the present application, rather than limitations on the technical scheme of the present application. In the absence of conflict, the embodiments of the present application and the technical features in the embodiments may be combined with each other.

[0024] With the development of computer technology, more and more technologies (big data, distributed, blockchain, artificial intelligence, etc.) are being applied in the financial field, and the traditional financial industry is gradually transforming into Fintech. At present, in the field of Fintech, it is often necessary to develop software projects. During a development cycle of a software project, the code will be frequently modified. Each modified code can be submitted to an open source distributed version control system for storage. For example, Jenkins is an open source software project. It is a continuous integration tool developed based on Java. It is used to monitor continuous and repetitive work. It aims to provide an open and easy-to-use software platform to make continuous integration of software possible. git is an open source distributed version control system. git is designed to handle all matters from small to large projects quickly and efficiently.

[0025] Since the code of a software project will be modified frequently, a software project will produce multiple versions in a development cycle. In order to characterize the changes between different versions of the code and the optimization after the code changes, it is often necessary to obtain the coverage information of the difference code between two different versions, that is, the execution status of the code in the difference code during the operation of the newer version of the code, such as the number of lines of difference code executed during the operation, the proportion of the number of lines of difference code executed to the total number of lines of difference code, etc.

[0026] In the prior art, when a financial institution (banking institution, insurance institution or securities institution) needs to obtain the coverage information of the difference code between two different versions of a software project within a development cycle during the process of developing business (such as bank loan business, deposit business, etc.), the coverage information and code change information of the difference code between every two adjacent versions of the code in all versions between the two different versions are obtained in turn, and then the version is deduced one by one until the coverage information of the difference code between the two different versions is obtained. Obviously, the method in the prior art needs to frequently pull each version code, which has a huge amount of calculation, is prone to errors, and will cause the entire process to be longer. The efficiency of obtaining the coverage information of the difference code between two different versions is low. This situation does not meet the needs of financial institutions such as banks and cannot guarantee the efficient operation of various businesses.

[0027] To this end, the embodiment of the present application provides a method for obtaining first coverage information, the steps of the method are as follows: Figure 1 shown.

[0028] Step 101: Obtain first coverage information.

[0029] It should be noted that coverage information refers to the information about the code executed in a program file during runtime. During the execution of a program file, each line of code in the program file may have been executed or may have never been executed from the beginning to the end of the execution of the program file. If a line of code is executed, it is said that the line of code is covered, otherwise, it is said that the line of code is not covered. The coverage information can be the proportion information, line number information, etc. of the code covered in the program file, which is not limited in the embodiments of the present application. In addition, in some programming environments, when editing the code in the program file, there are some blank lines without code in the program file. Deleting or not deleting these blank lines does not affect the operation of the program, and these blank lines are not considered when obtaining the coverage information.

[0030] The first coverage information is used to indicate whether each line of code corresponding to line numbers 1 to K is executed, wherein when a line of code corresponding to line number i is executed in all N version codes, it means that the line of code corresponding to line number i is executed, otherwise, it means that the line of code corresponding to line number i is not executed; K is the number of lines of code included in the first version code; i is an integer greater than or equal to 1 and less than or equal to K, and the first version code is the last submitted code among the N version codes. The N version codes are codes submitted N times in a row in a preset order in a development cycle. For example, a software project submits 10 codes in chronological order, and the N version codes are the codes submitted 4 to 8 times, and N=5 at this time.

[0031] Step 102: Determine, according to the first version code and the second version code, a difference code in the first version code that is different from the second version code.

[0032] The second version code is the code submitted for the first time among the N version codes.

[0033] Step 103: Determine second coverage information according to the difference code and the first coverage information. The second coverage information is used to indicate whether each line of code in the difference code is executed in the first version code.

[0034] In step 101, an optional implementation of obtaining the first coverage information is as follows:

[0035] Obtain N groups of third coverage information; wherein each group of third coverage information of the N groups of third coverage information uniquely corresponds to a version code among the N version codes, and the group of third coverage information is used to indicate whether each line of code in the version code is executed; merge the N groups of third coverage information into the first coverage information.

[0036] In this optional implementation, the forms of the N groups of third coverage information and the first coverage information are not limited. For example, each group of third coverage information of the N groups of third coverage information and the first coverage information are both an array. For the value of any subscript of the array, if the value is a first preset value, it indicates that the code corresponding to the subscript has been executed in the version code corresponding to the group of coverage information; if the value is a second preset value, it indicates that the code corresponding to the subscript has not been executed in the version code corresponding to the group of coverage information. Based on this, the N groups of third coverage information can be merged into the first coverage information in the following manner:

[0037] According to each subscript in the array of the first coverage information, the value of the subscript in the N arrays of the N groups of third coverage information is calculated according to a preset calculation rule, and the calculation result is used as the value of the subscript in the array of the first coverage information.

[0038] For example, each of the N arrays is a Boolean array, the first preset value is 0, the second preset value is 1, and the preset operation rule is an AND operation. The result of the AND operation on the N Boolean arrays is also a Boolean array, and this Boolean array is used as the first coverage information.

[0039] In step 102, the difference code refers to the code that is different between versions. The embodiment of the present application only illustrates the determination rule of the difference code. The determination rule of the difference code can be adjusted according to the specific implementation scenario, and is not limited to this. The specific determination rules are as follows:

[0040] Difference codes are divided into file differences and file content differences. File differences: if the file path or file name has changed, it means there is a file difference; file content differences: the file path and file name have not changed, but the file content has changed. In the following description, files refer to program files. The code content can be changed by adding or reducing a series of files, and adding or reducing certain lines of content in a file, as shown in:

[0041] (1) Compared with the second version of the code, the first version of the code adds a new file. For the newly added file, all the code lines of the entire file are included in the difference code. For the files that are reduced in the first version of the code compared with the second version of the code, the reduced code is not included in the difference code. It should be noted that the code line refers to the edited line of the code in the file. For example, a blank line is not considered a code line.

[0042] (2) If the first version of the code has the same file name and storage path as the second version of the code, but the file contents are different, the following situations apply:

[0043] The first case: some new lines of code are added. The new lines of code are directly included in the difference code.

[0044] The second case: However, the reduced file lines may affect the upper and lower code lines function, so here the upper and lower lines of the deleted code block are included in the difference code. For the deleted code block, the code block refers to a group of consecutive lines of code lines, and the line before the first line of the deleted code block and the line after the last line are included in the difference code. For example, the second version code program file one has lines 1 to 10, and the first version code program file one has lines 1 to 8, wherein lines 1 to 6 of the first version code program file one are the same as lines 1 to 6 of the second version code program file one, and lines 7 to 8 of the first version code program file one are the same as lines 9 to 10 of the second version code program file one, that is, relative to the second version code program file one, the first version code program file one deletes lines 7 to 8 of the second version code program file one, which are the deleted code blocks. Therefore, the line before the first line of the deleted code block, that is, line 6 of the first version code program file one, and the line after the last line of the deleted code block, that is, line 7 of the first version code program file one (corresponding to line 9 of the second version code program file one), are included in the difference code.

[0045] In the third case, for code annotations in files, since annotations themselves do not have coverage information, but annotations may affect the execution of the annotated code block, so here for the same code block in the same file, if the annotation of the code block is modified, the code lines set for the entire code block can be included in the difference code. It should be noted that annotations are a mechanism provided in the Java programming language, which allows programmers to directly write metadata while writing code. The annotated code is not directly affected by the annotations, which only provides information about itself to the third system for different needs.

[0046] Based on the above situations, an optional implementation method for determining the difference code in step 102 is as follows:

[0047] If the first version code contains new code relative to the second version code, the new code is taken as the first code set; if the first version code contains a code block deleted relative to the second version code, the line of code before the first line and the line of code after the last line of the deleted code block in the second version code are taken as the second code set; if the first version code contains a code block with a changed annotation relative to the second version code, the code block with a changed annotation is taken as the third code set; the first code set, the third code set and all the codes in the third code set are taken as the difference code.

[0048] In addition, it should be noted that blank lines in program files are not counted in the difference code. For example, in program file A, the first line is 1, the second line is 2, and the third line is 3. In program file B, the first line is 1, the second line is blank, the third line is 2, and the fourth line is 3. It is considered that there is no difference between program file A and program file B.

[0049] Step 102 obtains the difference code between the first version code and the second version code, and step 103 further obtains second coverage information according to the difference code obtained in step 102. The second coverage information is information about whether each line of code in the difference code is executed during the execution of the first version code.

[0050] In step 103, an optional implementation of obtaining the second coverage information is as follows:

[0051] For each line of code in the difference code, if the first coverage information indicates that the line of code is executed, it is determined that the line of code is executed in the first version of the code; otherwise, it is determined that the line of code is not executed in the first version of the code; and the second coverage information is determined based on whether each line of code in the difference code is executed in the first version of the code.

[0052] That is, the above-mentioned implementation mode uses the executed code line in the difference code and recorded in the first coverage information as the covered code line in the second coverage information.

[0053] The following takes the combination of Jenkins and git as an example. Figure 2 Further explain a coverage information acquisition method proposed in an embodiment of the present application, such as Figure 2 , which is a system architecture diagram applicable to a coverage information acquisition method proposed in an embodiment of the present application.

[0054] exist Figure 2In the system architecture diagram shown, through the combination of Jenkins and git, git's submission information can be automatically collected, the coverage information of N versions of code can be merged in advance, the first coverage information can be obtained, and the difference code between the first version code and the second version code can be combined to quickly obtain the second coverage information. Among them, Jenkins is deployed on the application machine and git is deployed on the server. The application machine is the machine for project development, and the application machine submits each modified code to the server. There are several commonly used tool marks in git as follows: git commit, which is a modification submission in git; git tag, which is a snapshot of the git version library, a pointer to a modification submission; git commit id, which is a unique string used to identify each submitted modification in git. The file differences between each modification submission of Jenkins can be recorded through git commit, and git tag can be used to point to each submitted modification of Jenkins, and git commit id can be used to identify each submitted modification of Jenkins. The following introduces each module separately:

[0055] Commit id information collection module: The commit id information collection module is a module in the application machine. The commit id information collection module will automatically collect the commit id of the current version code and output the result to the release package of the application. The application is the software application when writing the program. The release package of the application is a software package that is loaded when instrumentation is used to add additional functions. In this system architecture, the release package is Jenkins. After the version is compiled, the version information is output to the specified directory and specified file name under the application package. The version information includes: git branch name, and the corresponding git commit id when building the release package.

[0056] Coverage information agent injection module: The coverage information agent injection module will automatically connect to the coverage information agent to avoid misoperation and operation delays caused by manual access. The module will monitor the relationship between the application name of the current application and its corresponding process identification (pid) on the machine where the application is running. By judging whether the pid of the application exists, it determines whether the application has been connected to the coverage information agent, and automatically connects the coverage information agent to the application. Among them, pid refers to the process identification number in the operating system, that is, the process identifier. A pid is created for each program opened in the operating system. This module will also combine the output results of the commit id information collection module. After connecting to the coverage information agent, it will send a heartbeat to the coverage information collection module through the network for data synchronization, and will also send the coverage information of the application from startup to the current period to the coverage information collection module.

[0057] Coverage information collection module: The coverage information collection module is used to periodically receive the heartbeat information of the coverage agent, determine the online status of the coverage information agent, and also periodically or manually send instructions to collect coverage information to the online coverage information agent to collect the coverage information of the application. The collected coverage information will be merged with the previously existing coverage information. For example, N groups of third coverage information are merged to obtain the first coverage information accumulated over a period of time, and stored on the local disk.

[0058] like Figure 3 As shown, it is a flowchart of the steps of automatically injecting coverage information agent by the coverage information agent injection module provided in the embodiment of the present application, and application A is used as an example for illustration.

[0059] Step 301: Get pid_1 of application A through a command called Process Status (ps).

[0060] It should be noted that the ps command is used to list the processes currently running in the system. The ps command lists the snapshots of the current processes, that is, the processes at the time when the ps command is executed.

[0061] Step 302: Request the coverage information collection module to obtain pid_2 reported by application A.

[0062] Step 303: Determine whether pid_1 of application A does not exist or pid_1 is not equal to pid_2.

[0063] If yes, execute step 304.

[0064] If application A has not reported pid1 or the pid2 returned by the query is inconsistent with the current pid1, it is determined that the application is not connected to the coverage information agent.

[0065] Step 304: Inject coverage information agent.

[0066] Step 304 uses the instrumentation application program interface provided by Java to inject the coverage agent.

[0067] Step 305: Report pid_1.

[0068] After application A successfully injects the coverage agent, it reports its own pid_1 to the coverage information collection module and updates its previously stored value.

[0069] Difference code comparison module: When receiving the instruction to generate coverage information, the difference code comparison module will obtain the version code corresponding to the most recent tag and the current commit id from git through the network, compare the difference files and difference lines between the two, and output the corresponding code line difference results. The instruction to trigger source code comparison can be automatic or manual.

[0070] Coverage information output module: The coverage information output module is used to combine the first coverage information and the difference code to generate the second coverage information.

[0071] In the above method, the first coverage information is obtained, and the first coverage information indicates whether each line of code corresponding to line numbers 1 to K is executed. The method does not need to frequently pull each version code in N version codes to determine the difference code after each version code is submitted. The difference code in the second version code that is different from the first version code can be determined directly based on the first version code and the second version code, thereby greatly reducing the amount of calculation and the error rate, thereby reducing the entire process time, and then according to the difference code and the first coverage information, the second coverage information is obtained, that is, the marking information of whether each line of code in the difference code is executed when the second version code is running. Therefore, this method improves the efficiency of obtaining coverage information of difference codes between versions.

[0072] like Figure 4 , which is a schematic diagram of the structure of a coverage information acquisition device in an embodiment of the present application.

[0073] The embodiment of the present application provides a coverage information acquisition device, including: an acquisition module 401, used to acquire first coverage information; the first coverage information is used to indicate whether each line of code corresponding to line numbers 1 to K is executed, wherein, when a line of code corresponding to line number i is executed in N version codes, it means that the line of code corresponding to line number i is executed, otherwise, it means that the line of code corresponding to line number i is not executed; K is the number of lines of code included in the first version code; i is an integer greater than or equal to 1 and less than or equal to K; the first version code is the last submitted code among the N version codes; a processing module 402 is used to determine, based on the first version code and the second version code, a difference code in the first version code that is different from the second version code; the second version code is the first submitted code among the N version codes; the second coverage information is determined based on the difference code and the first coverage information; the second coverage information is used to indicate whether each line of code in the difference code is executed in the first version code.

[0074] In an optional implementation, the acquisition module 401 is specifically used to: acquire N groups of third coverage information; wherein each group of third coverage information of the N groups of third coverage information uniquely corresponds to a version code among the N version codes, and the group of third coverage information is used to indicate whether each line of code in the version code is executed; and merge the N groups of third coverage information into the first coverage information.

[0075] In an optional implementation, each group of third coverage information of the N groups of third coverage information and the first coverage information are both an array, and for the value of any subscript of the array, if the value is a first preset value, it indicates that the code corresponding to the subscript has been executed in the version code corresponding to the group of coverage information, and if the value is a second preset value, it indicates that the code corresponding to the subscript has not been executed in the version code corresponding to the group of coverage information; the acquisition module 401 is specifically used to: according to each subscript in the array of the first coverage information, perform operations on the value of the subscript in the N arrays of the N groups of third coverage information according to a preset operation rule, and use the operation result as the value of the subscript in the array of the first coverage information.

[0076] In an optional implementation, the processing module 402 is specifically used to: if the first version code contains new code relative to the second version code, then the new code is used as the first code set; if the first version code contains a code block that is deleted relative to the second version code, then in the second version code, a line of code before the first line and a line of code after the last line of the deleted code block are used as the second code set; if the first version code contains a code block whose annotation has changed relative to the second version code, then the code block whose annotation has changed is used as the third code set; and the first code set, the third code set, and all codes in the third code set are used as the difference code.

[0077] In an optional implementation, the processing module 402 is specifically used to: for each line of code in the difference code, if the first coverage information indicates that the line of code is executed, determine that the line of code is executed in the first version code; otherwise, determine that the line of code is not executed in the first version code; and determine the second coverage information based on whether each line of code in the difference code is executed in the first version code.

[0078] Finally, it should be noted that: those skilled in the art should understand that the embodiments of the present application can be provided as methods, systems, or computer program products. Therefore, the present application can take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present application can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, optical storage, etc.) containing computer-usable program code.

[0079] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 Process or multiple and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0080] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0081] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.

Claims

1. A method for obtaining coverage information, characterized in that: include: Obtaining first coverage information; The first coverage information is used to indicate whether each line of code corresponding to line numbers 1 to K is executed, wherein when a line of code corresponding to line number i is executed in all N version codes, it means that the line of code corresponding to line number i is executed, otherwise, it means that the line of code corresponding to line number i is not executed; K is the number of lines of code included in the first version code; i is an integer greater than or equal to 1 and less than or equal to K; the first version code is the code last submitted in the N version codes; Determine, according to the first version code and the second version code, a difference code in the first version code that is different from the second version code; the second version code is a code submitted for the first time among the N version codes; Determine second coverage information according to the difference code and the first coverage information; the second coverage information is used to indicate whether each line of code in the difference code is executed in the first version code; Wherein, the obtaining of the first coverage information includes: obtaining N groups of third coverage information; wherein, each group of the N groups of third coverage information uniquely corresponds to a version code among the N version codes, and the group of third coverage information is used to indicate whether each line of code in the version code is executed; and merging the N groups of third coverage information into the first coverage information.

2. The method according to claim 1, characterized in that Each group of third coverage information of the N groups of third coverage information and the first coverage information are both an array, and for a value of any subscript of the array, if the value is a first preset value, it indicates that the code corresponding to the subscript has been executed in the version code corresponding to the group of coverage information, and if the value is a second preset value, it indicates that the code corresponding to the subscript has not been executed in the version code corresponding to the group of coverage information; The merging the N groups of third coverage information into the first coverage information includes: According to each subscript in the array of the first coverage information, the value of the subscript in the N arrays of the N groups of third coverage information is calculated according to a preset calculation rule, and the calculation result is used as the value of the subscript in the array of the first coverage information.

3. The method according to any one of claims 1-2, characterized in that: The determining, according to the first version code and the second version code, a difference code in the first version code that is different from the second version code includes: If the first version code has new codes relative to the second version code, the new codes are used as the first code set; If the first version of the code contains a code block that is deleted relative to the second version of the code, a line of code before the first line and a line of code after the last line of the deleted code block in the second version of the code are used as the second code set; If there is a code block in the first version code whose annotation is changed relative to the second version code, the code block with the changed annotation is used as the third code set; The first code set, the third code set and all codes in the third code set are used as the difference codes.

4. The method according to any one of claims 1-2, characterized in that: The determining, according to the difference code and the first coverage information, second coverage information includes: For each line of code in the difference code, if the first coverage information indicates that the line of code is executed, determining that the line of code is executed in the first version of the code; otherwise, determining that the line of code is not executed in the first version of the code; The second coverage information is determined according to whether each line of code in the difference code is executed in the first version code.

5. A coverage information acquisition device, characterized in that: include: An acquisition module, used for acquiring first coverage information; The first coverage information is used to indicate whether each line of code corresponding to line numbers 1 to K is executed, wherein when a line of code corresponding to line number i is executed in all N version codes, it means that the line of code corresponding to line number i is executed, otherwise, it means that the line of code corresponding to line number i is not executed; K is the number of lines of code included in the first version code; i is an integer greater than or equal to 1 and less than or equal to K; the first version code is the code last submitted in the N version codes; a processing module, configured to determine, according to the first version code and the second version code, a difference code in the first version code that is different from the second version code; the second version code is a code submitted for the first time among the N version codes; and determine second coverage information according to the difference code and the first coverage information; the second coverage information is used to indicate whether each line of code in the difference code is executed in the first version code; The acquisition module is specifically used to: acquire N groups of third coverage information; wherein each group of third coverage information of the N groups of third coverage information uniquely corresponds to a version code among the N version codes, and the group of third coverage information is used to indicate whether each line of code in the version code is executed; and merge the N groups of third coverage information into the first coverage information.

6. The device according to claim 5, characterized in that Each group of third coverage information of the N groups of third coverage information and the first coverage information are an array. For the value of any subscript of the array, if the value is a first preset value, it indicates that the code corresponding to the subscript has been executed in the version code corresponding to the group of coverage information; if the value is a second preset value, it indicates that the code corresponding to the subscript has not been executed in the version code corresponding to the group of coverage information; the acquisition module is specifically used to: According to each subscript in the array of the first coverage information, the value of the subscript in the N arrays of the N groups of third coverage information is calculated according to a preset calculation rule, and the calculation result is used as the value of the subscript in the array of the first coverage information.

7. The device according to any one of claims 5-6, characterized in that: The processing module is specifically used for: If the first version code has new codes relative to the second version code, the new codes are used as the first code set; If the first version of the code contains a code block that is deleted relative to the second version of the code, a line of code before the first line and a line of code after the last line of the deleted code block in the second version of the code are used as the second code set; If there is a code block in the first version code whose annotation is changed relative to the second version code, the code block with the changed annotation is used as the third code set; The first code set, the third code set and all codes in the third code set are used as the difference codes.

8. The device according to any one of claims 5-6, characterized in that: The processing module is specifically used for: For each line of code in the difference code, if the first coverage information indicates that the line of code is executed, determining that the line of code is executed in the first version of the code; Otherwise, determine that the line of code has not been executed in the first version of the code; The second coverage information is determined according to whether each line of code in the difference code is executed in the first version code.

9. A computer device, characterized in that: The method comprises a program or an instruction. When the program or the instruction is executed, the method according to any one of claims 1 to 4 is performed.

10. A storage medium, characterized in that: The method comprises a program or an instruction. When the program or the instruction is executed, the method according to any one of claims 1 to 4 is performed.

Citation Information

Patent Citations

  • Determination method and device for code testing coverage rate statistical results

    CN105608011A