CN114253850A - Code incremental coverage rate statistical method, device, equipment and storage medium - Google Patents

Code incremental coverage rate statistical method, device, equipment and storage medium Download PDF

Info

Publication number
CN114253850A
CN114253850A CN202111564563.XA CN202111564563A CN114253850A CN 114253850 A CN114253850 A CN 114253850A CN 202111564563 A CN202111564563 A CN 202111564563A CN 114253850 A CN114253850 A CN 114253850A
Authority
CN
China
Prior art keywords
code
incremental
file
line
tested
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
CN202111564563.XA
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.)
Ping An Securities Co Ltd
Original Assignee
Ping An Securities Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Ping An Securities Co Ltd filed Critical Ping An Securities Co Ltd
Priority to CN202111564563.XA priority Critical patent/CN114253850A/en
Publication of CN114253850A publication Critical patent/CN114253850A/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/3668Software testing
    • G06F11/3672Test management
    • G06F11/3684Test management for test design, e.g. generating new test cases
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3688Test management for test execution, e.g. scheduling of test suites

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The application is applicable to the technical field of system testing, and provides a code incremental coverage rate statistical method, a device, equipment and a storage medium, wherein the method comprises the following steps: acquiring a source code file to be tested and a reference source code file; comparing the code content of the source code file to be tested with that of the reference source code file to identify an incremental code line in the source code file to be tested; extracting a method code containing an increment code line from a source code file to be tested according to the line number of the increment code line; acquiring the coverage rate information of the full code of the source code file to be tested, counting the dimension traversal coverage rate information of the full code by taking the method code containing the incremental code line as the coverage rate, and counting the incremental coverage rate information based on the method dimension from the coverage rate information of the full code. The method simultaneously considers the coverage rate of the increment code line and the front and back logics of the increment code line, radiates the incremental code line to the corresponding method, solves the problem of test missing caused by small test range, and improves the test accuracy.

Description

Code incremental coverage rate statistical method, device, equipment and storage medium
Technical Field
The present application relates to the field of system testing technologies, and in particular, to a method, an apparatus, a device, and a storage medium for counting incremental coverage of a code.
Background
In the software product development process, in order to ensure the quality of the product, the codes of the developed and finished product need to be tested, wherein the test includes incremental coverage rate statistics. With the accelerated development of the internet, the iteration cycle of a software product is accelerated, the testing time is shorter and shorter, the testing range is wider and wider, effective testing and accurate testing become the problems concerned by the software product industry in recent years. In the existing software product testing technology, a common incremental coverage rate statistical method is row coverage rate statistics of incremental code rows, however, incremental information obtained by the existing row coverage rate statistical method cannot accurately reflect a range influenced by product code modification, and test missing and accuracy of code testing are easily influenced due to an excessively small testing range.
Disclosure of Invention
In view of this, embodiments of the present application provide a method, an apparatus, a device, and a storage medium for counting incremental coverage of a code, which can solve a situation of missing test caused by a small test range, and improve test accuracy.
A first aspect of an embodiment of the present application provides a method for counting incremental coverage of a code, including:
acquiring a source code file to be tested and a reference source code file, wherein the source code file to be tested is a source code file with a modified version, and the reference source code file is a source code file with a pre-modified version;
comparing the code content of the source code file to be tested with that of the reference source code file to obtain incremental information in the source code file to be tested, and identifying an incremental code line in the source code file to be tested based on the incremental information;
positioning in the source code file to be tested based on the incremental code line to obtain the line number of the incremental code line, and obtaining a method code containing the incremental code line from the source code file to be tested according to the line number of the incremental code line;
and acquiring the coverage rate information of the full code of the source code file to be tested, traversing the coverage rate information of the full code according to the method code containing the incremental code line, and counting incremental coverage rate information based on the method dimension from the coverage rate information of the full code.
With reference to the first aspect, in a first possible implementation manner of the first aspect, the step of obtaining incremental information in the source code file to be tested by comparing code contents of the source code file to be tested with that of the reference source code file includes:
and comparing the contents of the source code file to be tested and the reference source code file by adopting a preset text comparison tool, extracting class file information with code change from the source code file to be tested, and determining the class file information with the code change as incremental information in the source code file to be tested, wherein the class file information comprises class name information, class library information and class path information.
With reference to the first aspect, in a second possible implementation manner of the first aspect, the step of extracting, according to the line number of the incremental code line, a method code including the incremental code line from the source code file to be tested includes:
respectively matching the line number of the incremental code line with the line number range of each method code recorded in a preset method code line number distribution table, and identifying a target line number range in which the line number of the incremental code line falls;
and according to all line numbers contained in the target line number range, extracting code lines corresponding to all line numbers contained in the target line number range from the source code file to be tested, and collecting all code lines to form a method code containing the incremental code lines.
With reference to the first aspect or the first or second possible implementation manner of the first aspect, in a third possible implementation manner of the first aspect, before the step of obtaining, from the source code file to be tested, the method code including the incremental code line according to the line number of the incremental code line, the method further includes:
judging whether the incremental code line is a blank line or an annotation line based on the content of the incremental code line;
and if so, deleting the incremental code line, otherwise, acquiring a method code containing the incremental code line from the source code file to be tested according to the line number of the incremental code line.
With reference to the first aspect, in a fourth possible implementation manner of the first aspect, the step of obtaining full code coverage information of the source code file to be tested, traversing the full code coverage information according to the method code including the incremental code line, and counting incremental coverage information based on a method dimension from the full code coverage information includes:
in the source code file to be tested, obtaining all class files corresponding to the method codes containing the incremental code lines, and generating a mapping relation table between the method names and the class files according to the class files;
screening out first coverage rate information from the full-amount code coverage rate information according to the mapping relation table, wherein the first coverage rate information is characterized by the coverage rate information corresponding to the method code comprising the incremental code line;
according to the first coverage rate information, marking processing of coverage rate information is carried out in the full code coverage rate information, and marked coverage rate information is counted into increment coverage rate information based on method dimensionality.
With reference to the fourth possible implementation manner of the first aspect, in a fifth possible implementation manner of the first aspect, the screening, according to the mapping relationship table, first coverage information from the full-size code coverage information, where the first coverage information is characterized by a step of coverage information corresponding to a method code including the incremental code row, further includes:
acquiring a class file of the method code;
performing file comparison on the class file of the method code and a corresponding backup class file on a server, and judging whether the class file is consistent with the backup class file on the server or not;
and if the class file is consistent with the backup class file on the server, setting the first coverage rate information of the method code to be zero.
With reference to the fourth or fifth possible implementation manner of the first aspect, in a sixth possible implementation manner of the first aspect, after the step of performing, according to the first coverage information, a marking process on incremental method coverage information in the full-size code coverage information, and counting the marked incremental method coverage information as incremental coverage information based on a method dimension, the method further includes:
and generating an increment coverage rate display report corresponding to the source code file to be tested according to the marked increment method coverage rate information in the full code coverage rate information.
A second aspect of the embodiments of the present application provides an incremental coverage rate statistics apparatus for a code, where the incremental coverage rate statistics apparatus for a code includes:
the system comprises an acquisition module, a comparison module and a comparison module, wherein the acquisition module is used for acquiring a source code file to be tested and a reference source code file, the source code file to be tested is a source code file with a modified version, and the reference source code file is a source code file with a pre-modified version;
the comparison module is used for comparing the code content of the source code file to be tested with that of the reference source code file to obtain incremental information in the source code file to be tested and identifying an incremental code line in the source code file to be tested based on the incremental information;
the extracting module is used for positioning in the source code file to be tested based on the incremental code line, obtaining the line number of the incremental code line, and extracting a method code containing the incremental code line from the source code file to be tested according to the line number of the incremental code line;
and the counting module is used for acquiring the coverage rate information of the full code of the source code file to be tested, traversing the coverage rate information of the full code by taking the method code containing the incremental code line as a coverage rate counting dimension, and counting the incremental coverage rate information based on the method dimension from the coverage rate information of the full code.
A third aspect of embodiments of the present application provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the electronic device, where the processor implements the steps of the incremental coverage statistical method of codes provided in the first aspect when executing the computer program.
A fourth aspect of embodiments of the present application provides a computer-readable storage medium, which stores a computer program that, when executed by a processor, implements the steps of the incremental coverage statistical method of the code provided in the first aspect.
The incremental coverage rate statistical method and device for the codes, the electronic equipment and the storage medium have the following beneficial effects:
according to the method and the device for identifying the incremental code lines, the source code file to be tested and the reference source code file are obtained, and the code content of the source code file to be tested is compared with that of the reference source code file, so that the incremental code lines in the source code file to be tested are identified. Positioning in a source code file to be tested based on an incremental code line to obtain a line number of the incremental code line, and extracting a method code containing the incremental code line from the source code file to be tested according to the line number of the incremental code line; acquiring the coverage rate information of the full code of the source code file to be tested, counting the dimension traversal coverage rate information of the full code by taking the method code containing the incremental code line as the coverage rate, and counting the incremental coverage rate information based on the method dimension from the coverage rate information of the full code. Based on the dimension of the method, the coverage rate of the incremental code line and the front and back logics of the incremental code line are considered at the same time, the method corresponding to the incremental code line is radiated, the condition that the test is missed due to the small test range is solved, and the test accuracy is improved.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed to be used in the embodiments or the prior art descriptions will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without inventive exercise.
Fig. 1 is a flowchart illustrating an implementation of a method for counting incremental coverage of a code according to an embodiment of the present application;
fig. 2 is a flowchart of a method for extracting method codes including incremental code lines in an incremental coverage statistical method for codes according to an embodiment of the present disclosure;
fig. 3 is a flowchart of a method for denoising an incremental code line in the incremental coverage statistical method for codes according to the embodiment of the present application;
fig. 4 is a schematic flowchart of a method for counting incremental coverage based on method dimensions in the incremental coverage statistical method for code according to the embodiment of the present application;
FIG. 5 is a flowchart of a method for screening out valid first coverage information in an incremental coverage statistics method for codes according to an embodiment of the present disclosure;
FIG. 6 is a block diagram of an infrastructure of an incremental coverage statistics apparatus for a code according to an embodiment of the present application;
FIG. 7 is a block diagram of a first refinement structure in an incremental coverage statistic apparatus for codes according to an embodiment of the present application;
FIG. 8 is a block diagram of a second refinement structure in an incremental coverage statistic apparatus for codes provided in an embodiment of the present application;
FIG. 9 is a block diagram of a third refinement structure in an incremental coverage statistic apparatus for codes provided in an embodiment of the present application;
FIG. 10 is a block diagram illustrating a fourth refinement structure in an incremental coverage statistic apparatus for codes according to an embodiment of the present application;
fig. 11 is a block diagram of a basic structure of an electronic device according to an embodiment of the present application.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the present application is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the present application and are not intended to limit the present application.
The iteration cycle of software product development is fast, and in order to ensure the quality of the software product, the incremental coverage rate statistical method of the codes provided by the embodiment of the application is applied to the process of testing the codes generated by the software product iteration, so that the codes generated by the software product iteration are accurately tested, the test missing is avoided, and the test accuracy is improved.
Referring to fig. 1, fig. 1 is a flowchart illustrating an implementation of a method for counting incremental coverage of a code according to an embodiment of the present disclosure. The details are as follows:
s11: the method comprises the steps of obtaining a source code file to be tested and a reference source code file, wherein the source code file to be tested is a source code file with a changed version, and the reference source code file is a source code file with a not changed version.
In this embodiment, the source code file is a code file recorded in the software product and used for running the software product. In this embodiment, the source code file to be tested is a new source code file generated by current iteration of the software product, that is, a source code file with a modified version. The reference source code file is a source code file of the original version of the software product or a source code file generated in the previous iteration of the software product, that is, a source code file before version change (a source code file of a history update version). Illustratively, the code of a software product is tested based on a Jenkins implementation. Jenkins is a Java-based development, Continuous Integration (CI) tool. After the developer submits the new source code file of iteration, download the new source code file from the code server as the source code file to be tested by the continued integration tool. After each iteration of the software product, the source code file corresponding to the originally operated code is stored in the history database as the source code file of the history update version. When performing code testing, the persistent integration tool may obtain the reference source code files needed for testing from the historical database.
S12: and comparing the code content of the source code file to be tested with that of the reference source code file to obtain incremental information in the source code file to be tested, and identifying an incremental code line in the source code file to be tested based on the incremental information.
In this embodiment, after the software product is iterated, the code information in the source code file used by the software product may be changed. In this embodiment, the code content of the source code file to be tested obtained by software product iteration is compared with the code content of the reference source code file corresponding to the source code file to be tested, so that the codes of the software product with difference in the iteration can be identified from the source code file to be tested. And obtaining incremental information in the source code file to be tested according to the codes with the differences. Illustratively, the incremental information is characterized by class file information of a source code file to be tested, where a code change occurs, and includes information such as a class name, a class library, and a class path of the class file. In this embodiment, a text comparison tool (diff tool) may be used to compare the difference in code content between the source code file to be tested and the reference source code file corresponding to the source code file to be tested, so as to obtain the class file information of the source code file to be tested, where the code has been changed. Therefore, the class file information of the code change in the obtained source code file to be tested is determined as the incremental information in the source code file to be tested. It is understood that code changes include, but are not limited to, code deletion, code modification, code addition, and the like. After the incremental information is obtained, the corresponding class can be positioned in the source code file to be tested according to the information of the class name, the class library, the class path and the like of the class file in the incremental information, and after the class is positioned in the source code file to be tested, the incremental code line in the source code file to be tested can be identified in the positioned class.
S13: and positioning the incremental code line in the source code file to be tested based on the incremental code line to obtain the line number of the incremental code line, and extracting a method code containing the incremental code line from the source code file to be tested according to the line number of the incremental code line.
In this embodiment, after the incremental code line of the source code file to be tested is identified, based on the incremental code line, the source code file to be tested is positioned, and the position of the incremental code line in the source code file to be tested is determined, that is, the line number of the incremental code line is obtained. And matching the line number of the incremental code line with line number information corresponding to each method code of the source code file to be tested, wherein the method code of the line number information containing the incremental code line number is the method code containing the incremental code line. And further, extracting the method code containing the incremental code line from the source code file to be tested based on the line number information of the method code.
S14: and acquiring the coverage rate information of the full code of the source code file to be tested, traversing the coverage rate information of the full code according to the method code containing the incremental code line, and counting incremental coverage rate information based on the method dimension from the coverage rate information of the full code.
In this embodiment, Jacoco is an open source code coverage tool, which is integrated in Jenkins. In this embodiment, the information of the coverage rate of the full code of the source code file to be tested is obtained through Jacoco tool statistics. Illustratively, the incremental coverage rate service is set through a Jacoco tool, and the latest full code coverage rate is obtained from the application server according to the IP address of the code server and the port number of the Jacoco configured by the incremental coverage rate service. After the coverage rate of the full-size codes is obtained, traversing the coverage rate information of the full-size codes according to the previously obtained method codes containing the incremental code lines, screening the coverage rate information of the method codes containing the incremental code lines from the coverage rate information of the full-size codes, and counting the coverage rate information of the method codes containing the incremental code lines as the incremental coverage rate information based on the method dimensions.
As can be seen from the above, in the code incremental coverage statistical method provided by this embodiment, the incremental coverage of the code line is obtained based on the method dimension in the test process, and not only the coverage of the incremental code line is concerned, but also the front and back logical influence of the incremental code line is considered, and the range influenced by the modification of the product code is reflected more accurately by the method corresponding to the incremental code line irradiated by the incremental code line, so that the condition of missing test is avoided, and the test accuracy is improved.
In some embodiments of the present application, please refer to fig. 2, and fig. 2 is a flowchart of a method for extracting a method code including an incremental code line from an incremental coverage statistical method of a code according to an embodiment of the present application. The details are as follows:
s21: respectively matching the line number of the incremental code line with the line number range of each method code recorded in a preset method code line number distribution table, and identifying a target line number range in which the line number of the incremental code line falls;
s22: and extracting code lines corresponding to all line numbers contained in the target line number range from the source code file to be tested according to all line numbers contained in the target line number range, and collecting the code lines corresponding to all line numbers contained in the target line number range to form the method code containing the incremental code lines.
In this embodiment, a preset method code line number distribution table is generated for a source code file to be tested, and the method code line number distribution table records a line number range corresponding to each method code in the source code file to be tested. Specifically, the method code line number distribution table is characterized as a correspondence table between a method name and a line number range, and illustratively, for each method code recorded in a source code file to be tested, the code line position where the method code is located may be obtained according to a java project builder (open source class library). The method comprises a starting line position (startindex) and an ending line position (endindex) of a method code, a line number range of the method code can be obtained by collecting line numbers contained between the starting line position (startindex) and the ending line position (endindex) of the method code, and a corresponding relation between the method name and the line number range is formed by associating and binding the method name of the method code and the line number range.
In this embodiment, based on the preset method code line number distribution table, when the line number of the incremental code line is matched with the line number ranges of each method code recorded in the preset method code line number distribution table, whether the line number of the incremental code line falls within the line number range of the method code is determined by the condition of "startindex < line number of the incremental code line < endindex". After the line number of the incremental code line is respectively matched and judged with the line number range of each method code, if the line number of the incremental code line meets the condition that 'startindex < the line number of the incremental code line < endindex' of a certain method code, the line number of the incremental code line falls into the line number range of the method code, and therefore the line number range of the incremental code line is identified. And then, taking the line number range in which the line number of the incremental code line falls as a target line number range, extracting the code lines corresponding to all the line numbers contained in the target line number range from the source code file to be tested according to all the line numbers contained in the target line number range, and further collecting the extracted code lines to form the method code containing the incremental code lines.
In some embodiments of the present application, please refer to fig. 3, and fig. 3 is a flowchart of a method for denoising an incremental code line in an incremental coverage statistical method of a code provided in the embodiments of the present application. The details are as follows:
s31: judging whether the incremental code line is a blank line or an annotation line based on the content of the incremental code line;
s32: and if so, deleting the incremental code line, otherwise, acquiring a method code containing the incremental code line from the source code file to be tested according to the line number of the incremental code line.
In this embodiment, after the incremental code line in the source code file to be tested is identified, denoising processing may be performed on the incremental code line in the source code file to be tested. Specifically, all incremental code lines in the source code file to be tested are traversed, content identification is carried out on each incremental code line, whether the incremental code line belongs to a blank line or an annotation line is judged, if the incremental code line belongs to the blank line or the annotation line, the incremental code line is deleted, and otherwise, the method code containing the incremental code line is obtained from the source code file to be tested according to the line number of the incremental code line. The embodiment can improve the accuracy of the incremental code line through denoising processing, thereby improving the accuracy of code incremental coverage rate statistics.
In some embodiments of the present application, please refer to fig. 4, and fig. 4 is a schematic flow chart of a method for counting incremental coverage based on method dimensions in the incremental coverage counting method for codes according to the embodiments of the present application. The details are as follows:
s41: in the source code file to be tested, obtaining all class files corresponding to the method codes containing the incremental code lines, and generating a mapping relation table between the method names and the class files according to the class files;
s42: acquiring first coverage rate information from the full code coverage rate information according to the mapping relation table, wherein the first coverage rate information is characterized by incremental coverage rate information corresponding to method codes comprising the incremental code lines;
s43: according to the first coverage rate information, marking processing of method code coverage rate information is carried out in the full-amount code coverage rate information, and marked method code coverage rate information is counted into increment coverage rate based on method dimensionality.
In this embodiment, the source code file to be tested may be sequentially divided into a class dimension, a method dimension, a row dimension, and the like according to the dimension from large to small, where one class may include one or more methods. Moreover, each class dimension in the source code file to be tested corresponds to one class file. Therefore, after the method codes containing the incremental code lines in the source code file to be tested are obtained, the class dimension to which each method code containing the incremental code lines belongs can be identified according to the dimension of the source code file to be tested, and all the method codes containing the incremental code lines in the source code file to be tested are mapped and associated with the corresponding class files, so that a mapping relation table between the method names and the class files is generated. And then, acquiring first coverage rate information from the full code coverage rate information according to the corresponding relation between the method codes and the corresponding class files in the mapping relation table, wherein the first coverage rate information is characterized by the incremental coverage rate information corresponding to the method codes comprising the incremental code rows. Furthermore, after the first coverage rate information is obtained, the coverage rate information is marked in a mode of covering all method codes comprising the increment code line in the source code file to be tested according to the first coverage rate information, so that the influence before and after the increment line can be inspected together and all changed positions of the method of the increment line can be found out in the code detection process if the codes have logic statements, and the condition of missing test in the code test process is reduced.
In some embodiments of the present application, please refer to fig. 5, and fig. 5 is a flowchart illustrating a method for screening out valid first coverage information in the incremental coverage statistics method for codes according to the embodiments of the present application. The details are as follows:
s51: acquiring a class file of the method code;
s52: performing file comparison on the class file of the method code and a corresponding backup class file on a server, and judging whether the class file is consistent with the backup class file on the server or not;
s53: and if so, setting the first coverage rate information of the method code to be zero.
In this embodiment, each class file in the source code file to be tested corresponds to a class file, and the class file is a binary file that can be recognized by a computer and is obtained by compiling the class file. When the first coverage rate information is obtained, a class file compiled by a class file corresponding to a method code comprising an incremental code line is obtained, and the class file of the method code is compared with a backup class file corresponding to the server, so that whether the class file is consistent with the backup class file corresponding to the server or not is judged. If the coverage rate information of the code is consistent with the coverage rate information of the incremental coverage rate statistics, the code method is invalid information of the incremental coverage rate statistics, and the coverage rate information of the code of the method is set to be zero, so that the valid information of the incremental coverage rate statistics is obtained. In this embodiment, coverage information of a method code whose coverage information is not zero is acquired as first coverage information by traversing coverage information of a method code corresponding to an incremental code line. And screening out the effective increment coverage rate by judging whether the class file of the method code is consistent with the corresponding backup class file on the server.
In some embodiments of the application, after the incremental coverage information based on the method dimension is obtained, code lines related to the incremental coverage information may be labeled one by one in the source code file to be tested according to the incremental coverage information, and then the labeled source code file to be tested is generated into an incremental coverage display report corresponding to the source code file to be tested. The presentation report is an html report.
It should be understood that, the sequence numbers of the steps in the foregoing embodiments do not imply an execution sequence, and the execution sequence of each process should be determined by its function and inherent logic, and should not constitute any limitation to the implementation process of the embodiments of the present application.
In some embodiments of the present application, please refer to fig. 6, and fig. 6 is a block diagram of an infrastructure of an incremental coverage statistic apparatus for a code according to an embodiment of the present application. The apparatus in this embodiment comprises means for performing the steps of the method embodiments described above. The following description refers to the embodiments of the method. For convenience of explanation, only the portions related to the present embodiment are shown. As shown in fig. 6, the incremental coverage statistic device for codes comprises: an acquisition module 61, a comparison module 62, an extraction module 63, and a statistics module 64. Wherein: the obtaining module 61 is configured to obtain a source code file to be tested and a reference source code file, where the source code file to be tested is a source code file after version change, and the reference source code file is a source code file before version change. The comparison module 62 is configured to compare the code content of the source code file to be tested with the code content of the reference source code file, obtain incremental information in the source code file to be tested, and identify an incremental code line in the source code file to be tested based on the incremental information. The extracting module 63 is configured to locate in the source code file to be tested based on the incremental code line, obtain a line number of the incremental code line, and extract a method code including the incremental code line from the source code file to be tested according to the line number of the incremental code line. The counting module 64 is configured to obtain the coverage rate information of the full code of the source code file to be tested, traverse the coverage rate information of the full code by taking the method code including the incremental code line as a coverage rate counting dimension, and count incremental coverage rate information based on the method dimension from the coverage rate information of the full code.
In some embodiments of the present application, the apparatus for counting incremental coverage of the code further includes: the first comparison pair module is used for comparing the contents of the source code file to be tested and the reference source code file by adopting a preset text comparison tool, extracting class file information with code change from the source code file to be tested, and determining the class file information with the code change as incremental information in the source code file to be tested, wherein the class file information comprises class name information, class library information and class path information.
In some embodiments of the present application, please refer to fig. 7, and fig. 7 is a block diagram illustrating a first refinement structure of an incremental coverage statistic apparatus for codes according to an embodiment of the present application. As shown in fig. 7, the incremental coverage statistic device for the code further includes: a first matching submodule 71 and a first forming submodule 72. The first matching sub-module 71 is configured to match the line number of the incremental code line with the line number range of each method code recorded in the preset method code line number distribution table, and identify a target line number range in which the line number of the incremental code line falls. The first forming submodule 72 is configured to extract, according to all the line numbers included in the target line number range, code lines corresponding to all the line numbers included in the target line number range from the source code file to be tested, and aggregate the code lines to form a method code including the incremental code line.
In some embodiments of the present application, please refer to fig. 8, and fig. 8 is a block diagram of a second refinement structure in an incremental coverage statistics apparatus for codes provided in the embodiments of the present application. As shown in fig. 8, the incremental coverage statistic device for the code further includes: a first judgment sub-module 81 and a first acquisition sub-module 82. The first judging submodule 81 is configured to judge whether the delta code line is a blank line or an annotation line based on the content of the delta code line. The first obtaining submodule 82 is configured to delete the incremental code line if the incremental code line is determined to be the target code line, and otherwise, obtain a method code including the incremental code line from the source code file to be tested according to a line number of the incremental code line.
In some embodiments of the present application, please refer to fig. 9, and fig. 9 is a block diagram illustrating a third refinement structure of an incremental coverage statistics apparatus for codes provided in embodiments of the present application. As shown in fig. 9, the incremental coverage statistic device for the code further includes: a first generation submodule 91, a second acquisition submodule 92 and a first marking submodule 93. The first generating submodule 91 is configured to obtain, in the source code file to be tested, all class files corresponding to the method codes including the incremental code lines, and generate a mapping relationship table between the method name and the class file according to the class files. The second obtaining submodule 92 is configured to obtain first coverage information from the full-size code coverage information according to the mapping relation table, where the first coverage information is characterized by incremental coverage information corresponding to a method code including the incremental code row. The first labeling submodule 93 is configured to perform labeling processing on the method code coverage information in the full amount of code coverage information according to the first coverage information, and count the labeled method code coverage information into incremental coverage information based on a method dimension.
In some embodiments of the present application, please refer to fig. 10, where fig. 10 is a block diagram of a fourth refinement structure in an incremental coverage statistics apparatus for codes provided in embodiments of the present application. As shown in fig. 10, the incremental coverage statistic device for the code further includes: a third obtaining sub-module 101, a second judging sub-module 102 and a first setting sub-module 103. The third obtaining submodule 101 is configured to obtain a class file of the method code. The second judging submodule 102 is configured to perform file comparison on the class file of the method code and the corresponding backup class file on the server, and judge whether the class file is consistent with the backup class file on the server. The first setting sub-module 103 is configured to set the first coverage information of the method code to zero if the first coverage information is consistent with the first coverage information.
In some embodiments of the present application, the apparatus for counting incremental coverage of the code further includes: and the report generating module is used for generating an increment coverage rate display report corresponding to the source code file to be tested according to the marked increment method coverage rate information in the full code coverage rate information.
In some embodiments of the present application, please refer to fig. 11, and fig. 11 is a basic structural block diagram of an electronic device according to an embodiment of the present application. As shown in fig. 11, the electronic apparatus 11 of this embodiment includes: a processor 111, a memory 112 and a computer program 113, e.g. a program of an incremental coverage statistics method of a code, stored in said memory 112 and executable on said processor 111. The processor 111, when executing the computer program 113, implements the steps in the embodiments of the incremental coverage statistics method for each code described above. Alternatively, the processor 111 implements the functions of the modules in the embodiment corresponding to the incremental coverage rate statistic apparatus of the code when executing the computer program 113. Please refer to the description related to the embodiment, which is not repeated herein.
Illustratively, the computer program 113 may be divided into one or more modules (units) that are stored in the memory 112 and executed by the processor 111 to accomplish the present application. The one or more modules may be a series of computer program instruction segments capable of performing specific functions, which are used to describe the execution of the computer program 113 in the electronic device 11. For example, the computer program 113 may be divided into a chroma analysis module, a similarity comparison module, a tag obtaining module, and a first picture searching module, where the specific functions of the modules are as described above.
The electronic device may include, but is not limited to, a processor 111, a memory 112. Those skilled in the art will appreciate that fig. 11 is merely an example of an electronic device 11 and does not constitute a limitation of electronic device 11 and may include more or fewer components than shown, or some components may be combined, or different components, e.g., the electronic device may also include input-output devices, network access devices, buses, etc.
The Processor 111 may be a Central Processing Unit (CPU), other general purpose Processor, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), an off-the-shelf Programmable Gate Array (FPGA) or other Programmable logic device, discrete Gate or transistor logic device, discrete hardware component, etc. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
The storage 112 may be an internal storage unit of the electronic device 11, such as a hard disk or a memory of the electronic device 11. The memory 112 may also be an external storage device of the electronic device 11, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like, which are provided on the electronic device 11. Further, the memory 112 may also include both an internal storage unit and an external storage device of the electronic device 11. The memory 112 is used for storing the computer program and other programs and data required by the electronic device. The memory 112 may also be used to temporarily store data that has been output or is to be output.
It should be noted that, for the information interaction, execution process, and other contents between the above-mentioned devices/units, the specific functions and technical effects thereof are based on the same concept as those of the embodiment of the method of the present application, and specific reference may be made to the part of the embodiment of the method, which is not described herein again.
The embodiments of the present application further provide a computer-readable storage medium, where a computer program is stored, and when the computer program is executed by a processor, the computer program implements the steps in the above-mentioned method embodiments. In this embodiment, the computer-readable storage medium may be nonvolatile or volatile.
The embodiments of the present application provide a computer program product, which when running on a mobile terminal, enables the mobile terminal to implement the steps in the above method embodiments when executed.
It will be apparent to those skilled in the art that, for convenience and brevity of description, only the above-mentioned division of the functional units and modules is illustrated, and in practical applications, the above-mentioned function distribution may be performed by different functional units and modules according to needs, that is, the internal structure of the apparatus is divided into different functional units or modules to perform all or part of the above-mentioned functions. Each functional unit and module in the embodiments may be integrated in one processing unit, or each unit may exist alone physically, or two or more units are integrated in one unit, and the integrated unit may be implemented in a form of hardware, or in a form of software functional unit. In addition, specific names of the functional units and modules are only for convenience of distinguishing from each other, and are not used for limiting the protection scope of the present application. The specific working processes of the units and modules in the system may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
The integrated modules/units, if implemented in the form of software functional units and sold or used as separate products, may be stored in a computer readable storage medium. Based on such understanding, all or part of the flow in the method of the embodiments described above can be realized by a computer program, which can be stored in a computer-readable storage medium and can realize the steps of the embodiments of the methods described above when the computer program is executed by a processor. Wherein the computer program comprises computer program code, which may be in the form of source code, object code, an executable file or some intermediate form, etc. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, usb disk, removable hard disk, magnetic disk, optical disk, computer Memory, Read-Only Memory (ROM), Random Access Memory (RAM), electrical carrier wave signals, telecommunications signals, software distribution medium, and the like. It should be noted that the computer readable medium may contain other components which may be suitably increased or decreased as required by legislation and patent practice in jurisdictions, for example, in some jurisdictions, computer readable media which may not include electrical carrier signals and telecommunications signals in accordance with legislation and patent practice.
In the above embodiments, the descriptions of the respective embodiments have respective emphasis, and reference may be made to the related descriptions of other embodiments for parts that are not described or illustrated in a certain embodiment.
The above-mentioned embodiments are only used for illustrating the technical solutions of the present application, and not for limiting the same; although the present application has been described in detail with reference to the foregoing embodiments, it should be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; such modifications and substitutions do not substantially depart from the spirit and scope of the embodiments of the present application and are intended to be included within the scope of the present application.

Claims (10)

1. A method for counting incremental coverage of a code, comprising:
acquiring a source code file to be tested and a reference source code file, wherein the source code file to be tested is a source code file with a modified version, and the reference source code file is a source code file with a pre-modified version;
comparing the code content of the source code file to be tested with that of the reference source code file to obtain incremental information in the source code file to be tested, and identifying an incremental code line in the source code file to be tested based on the incremental information;
positioning in the source code file to be tested based on the incremental code line to obtain the line number of the incremental code line, and obtaining a method code containing the incremental code line from the source code file to be tested according to the line number of the incremental code line;
and acquiring the coverage rate information of the full code of the source code file to be tested, traversing the coverage rate information of the full code according to the method code containing the incremental code line, and counting incremental coverage rate information based on the method dimension from the coverage rate information of the full code.
2. The method for counting the incremental coverage of the codes according to claim 1, wherein the step of comparing the code content of the source code file to be tested with the code content of the reference source code file to obtain the incremental information in the source code file to be tested comprises:
and comparing the contents of the source code file to be tested and the reference source code file by adopting a preset text comparison tool, extracting class file information with code change from the source code file to be tested, and determining the class file information with the code change as incremental information in the source code file to be tested, wherein the class file information comprises class name information, class library information and class path information.
3. The method for counting the incremental coverage of codes according to claim 1, wherein the step of extracting the method codes containing the incremental code lines from the source code file to be tested according to the line numbers of the incremental code lines comprises:
respectively matching the line number of the incremental code line with the line number range of each method code recorded in a preset method code line number distribution table, and identifying a target line number range in which the line number of the incremental code line falls;
and according to all line numbers contained in the target line number range, extracting code lines corresponding to all line numbers contained in the target line number range from the source code file to be tested, and collecting all code lines to form a method code containing the incremental code lines.
4. The method for counting the incremental coverage of the codes according to any one of claims 1 to 3, wherein before the step of obtaining the method codes including the incremental code lines from the source code file to be tested according to the line numbers of the incremental code lines, the method further comprises:
judging whether the incremental code line is a blank line or an annotation line based on the content of the incremental code line;
and if so, deleting the incremental code line, otherwise, acquiring a method code containing the incremental code line from the source code file to be tested according to the line number of the incremental code line.
5. The method for counting incremental coverage of codes according to claim 1, wherein the step of obtaining full code coverage information of the source code file to be tested, traversing the full code coverage information according to the method code including the incremental code lines, and counting incremental coverage information based on method dimensions from the full code coverage information comprises:
in the source code file to be tested, obtaining all class files corresponding to the method codes containing the incremental code lines, and generating a mapping relation table between the method names and the class files according to the class files;
screening out first coverage rate information from the full-amount code coverage rate information according to the mapping relation table, wherein the first coverage rate information is characterized by the coverage rate information corresponding to the method code comprising the incremental code line;
according to the first coverage rate information, marking processing of coverage rate information is carried out in the full code coverage rate information, and marked coverage rate information is counted into increment coverage rate information based on method dimensionality.
6. The method of claim 5, wherein the step of screening out first coverage information from the full-size code coverage information according to the mapping table, wherein the first coverage information is characterized by the coverage information corresponding to the method code comprising the incremental code row, further comprises:
acquiring a class file of the method code;
performing file comparison on the class file of the method code and a corresponding backup class file on a server, and judging whether the class file is consistent with the backup class file on the server or not;
and if the class file is consistent with the backup class file on the server, setting the first coverage rate information of the method code to be zero.
7. The method according to claim 5 or 6, wherein the step of performing a labeling process of incremental method coverage information in the full-scale code coverage information according to the first coverage information, and counting the labeled incremental method coverage information into incremental coverage information based on method dimensions further comprises:
and generating an increment coverage rate display report corresponding to the source code file to be tested according to the marked increment method coverage rate information in the full code coverage rate information.
8. An incremental coverage statistics apparatus for a code, the incremental coverage statistics apparatus for the code comprising:
the system comprises an acquisition module, a comparison module and a comparison module, wherein the acquisition module is used for acquiring a source code file to be tested and a reference source code file, the source code file to be tested is a source code file with a modified version, and the reference source code file is a source code file with a pre-modified version;
the comparison module is used for comparing the code content of the source code file to be tested with that of the reference source code file to obtain incremental information in the source code file to be tested and identifying an incremental code line in the source code file to be tested based on the incremental information;
the extracting module is used for positioning in the source code file to be tested based on the incremental code line, obtaining the line number of the incremental code line, and extracting a method code containing the incremental code line from the source code file to be tested according to the line number of the incremental code line;
and the counting module is used for acquiring the coverage rate information of the full code of the source code file to be tested, traversing the coverage rate information of the full code by taking the method code containing the incremental code line as a coverage rate counting dimension, and counting the incremental coverage rate information based on the method dimension from the coverage rate information of the full code.
9. An electronic device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that the steps of the method according to any of claims 1 to 7 are implemented when the computer program is executed by the processor.
10. A computer-readable storage medium, in which a computer program is stored which, when being executed by a processor, carries out the steps of the method according to any one of claims 1 to 7.
CN202111564563.XA 2021-12-20 2021-12-20 Code incremental coverage rate statistical method, device, equipment and storage medium Pending CN114253850A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111564563.XA CN114253850A (en) 2021-12-20 2021-12-20 Code incremental coverage rate statistical method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111564563.XA CN114253850A (en) 2021-12-20 2021-12-20 Code incremental coverage rate statistical method, device, equipment and storage medium

Publications (1)

Publication Number Publication Date
CN114253850A true CN114253850A (en) 2022-03-29

Family

ID=80796040

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111564563.XA Pending CN114253850A (en) 2021-12-20 2021-12-20 Code incremental coverage rate statistical method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN114253850A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115168110A (en) * 2022-09-05 2022-10-11 深圳市科力锐科技有限公司 Incremental data identification method, device, equipment and storage medium
CN116610577A (en) * 2023-05-25 2023-08-18 成都融见软件科技有限公司 Coverage rate acquisition method

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115168110A (en) * 2022-09-05 2022-10-11 深圳市科力锐科技有限公司 Incremental data identification method, device, equipment and storage medium
CN115168110B (en) * 2022-09-05 2022-11-29 深圳市科力锐科技有限公司 Incremental data identification method, device, equipment and storage medium
CN116610577A (en) * 2023-05-25 2023-08-18 成都融见软件科技有限公司 Coverage rate acquisition method
CN116610577B (en) * 2023-05-25 2024-01-26 成都融见软件科技有限公司 Coverage rate acquisition method

Similar Documents

Publication Publication Date Title
CN107622014B (en) Test report generation method and device, readable storage medium and computer equipment
CN114253850A (en) Code incremental coverage rate statistical method, device, equipment and storage medium
CN108459962B (en) Code normalization detection method and device, terminal equipment and storage medium
US20160292068A1 (en) Code coverage rate determination method and system
CN110706206A (en) Fluorescent cell counting method, fluorescent cell counting device, terminal equipment and storage medium
CN111881455B (en) Firmware security analysis method and device
CN111190807B (en) Buried point testing method and equipment
CN106557419B (en) Program testing method and device
CN113157731A (en) Symbol analysis method, device, equipment and storage medium
CN110287700B (en) iOS application security analysis method and device
CN115858831A (en) Data storage method for database
CN108469997B (en) Automatic identification method of user-defined heap management function based on dynamic characteristics
CN110134583B (en) Software testing and data processing method and device
CN112506897A (en) Method and system for analyzing and positioning data quality problem
CN113806231B (en) Code coverage rate analysis method, device, equipment and medium
CN115309661A (en) Application testing method and device, electronic equipment and readable storage medium
CN114579975A (en) Vulnerability management method, system, computer equipment and storage medium
CN114492324A (en) Component data statistical method and device
CN114637688A (en) Coverage rate statistical method and device based on version branches
CN112580334A (en) File processing method, file processing device, server and storage medium
CN113868137A (en) Method, device and system for processing buried point data and server
CN112416417A (en) Code amount statistical method and device, electronic equipment and storage medium
CN110580243A (en) file comparison method and device, electronic equipment and storage medium
CN115879665B (en) Method and equipment for determining inspection requirements of product configuration and identifying product configuration
CN112597008A (en) Function point marking method and device based on webpage code test

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