CN116610551A - Code coverage rate calculation method, device, equipment and medium - Google Patents

Code coverage rate calculation method, device, equipment and medium Download PDF

Info

Publication number
CN116610551A
CN116610551A CN202210122768.0A CN202210122768A CN116610551A CN 116610551 A CN116610551 A CN 116610551A CN 202210122768 A CN202210122768 A CN 202210122768A CN 116610551 A CN116610551 A CN 116610551A
Authority
CN
China
Prior art keywords
coverage
version
code
rate data
coverage rate
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
CN202210122768.0A
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.)
Guangzhou Shizhen Information Technology Co Ltd
Original Assignee
Guangzhou Shizhen Information Technology 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 Guangzhou Shizhen Information Technology Co Ltd filed Critical Guangzhou Shizhen Information Technology Co Ltd
Priority to CN202210122768.0A priority Critical patent/CN116610551A/en
Publication of CN116610551A publication Critical patent/CN116610551A/en
Pending legal-status Critical Current

Links

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/368Test management for test version control, e.g. updating test cases to a new software version
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

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 discloses a code coverage rate calculation method, which comprises the following steps: acquiring first coverage rate data corresponding to a first version of target software and second coverage rate data corresponding to a second version of target software; calculating the row coverage information of the first version according to the first coverage rate data; calculating code differences between the first version and the second version according to the version information corresponding to the first version and the version information corresponding to the second version; and according to the row coverage information and the code difference, obtaining an accumulation mode of the first coverage rate data and the second coverage rate data, and according to the accumulation mode, superposing the first coverage rate data to the second coverage rate data to obtain the current accumulated coverage rate data of the target software, so that the coverage condition of the software code is calculated during version updating, and the stability of version updating is improved.

Description

Code coverage rate calculation method, device, equipment and medium
Technical Field
The present application relates to the field of computer technologies, and for example, to a method, an apparatus, a device, and a medium for calculating code coverage.
Background
At present, when the code coverage rate is calculated, only a full test is carried out on each software version, and the coverage condition of the test case on the code can be comprehensively observed. However, when a company adopts an agile development model to develop software, the code coverage rate calculation period is shortened, the stock code is increased, and finally, enough test time is difficult to be distributed for full test when the software version is released, so that whether a new test case fully covers old software code cannot be known.
Disclosure of Invention
The application aims at: a code coverage rate calculating method, device, equipment and medium are provided, which can calculate the coverage condition of software codes during version updating and improve the stability of version updating.
In order to achieve the above purpose, the application adopts the following technical scheme:
provided herein is a code coverage calculating method including:
acquiring first coverage rate data corresponding to a first version of target software and second coverage rate data corresponding to a second version, wherein the first version is a historical version, and the second version is a version obtained by updating the historical version;
calculating the row coverage information of the first version according to the first coverage rate data;
calculating code differences between the first version and the second version according to the version information corresponding to the first version and the version information corresponding to the second version;
and according to the row coverage information and the code difference, obtaining an accumulation mode of the first coverage rate data and the second coverage rate data, and according to the accumulation mode, superposing the first coverage rate data into the second coverage rate data to obtain the current accumulated coverage rate data of the target software.
The application also provides a code coverage rate calculating device, which comprises:
the data acquisition unit is used for acquiring first coverage rate data corresponding to a first version of target software and second coverage rate data corresponding to a second version, wherein the first version is a historical version, and the second version is a version obtained by updating the historical version;
a line coverage information calculation unit configured to calculate line coverage information of the first version according to the first coverage data;
a code difference calculating unit, configured to calculate a code difference between the first version and the second version according to version information corresponding to the first version and version information corresponding to the second version;
and the coverage rate accumulation unit is used for obtaining an accumulation mode of the first coverage rate data and the second coverage rate data according to the row coverage information and the code difference, and overlapping the first coverage rate data into the second coverage rate data according to the accumulation mode to obtain the current accumulated coverage rate data of the target software.
The application also provides a computer device comprising a memory and a processor, wherein the memory stores a computer program, and the processor realizes the steps of a code coverage rate calculation method according to any one of the above and/or the code coverage rate calculation method according to any one of the above when executing the computer program.
The present application also provides a computer-readable storage medium having stored thereon a computer program which, when executed by a processor, implements a code coverage calculation method as described in any one of the above and/or the steps of the code coverage calculation method as described in any one of the above.
According to the code coverage rate calculation method, the first coverage rate data of the old version of test cases and the second coverage rate data of the new version of test cases are respectively obtained, the line coverage information calculation is carried out on the old version of target software, and the code difference calculation is carried out on different versions of the target software to obtain different accumulation modes, so that the coverage rate data of different versions are overlapped according to the obtained accumulation modes to obtain the accumulated coverage rate data of the current version, the comprehensiveness of the coverage of the new version can be observed without full test on each new version of target software, the defect and the leakage of the test cases can be helped by testers, the quality controllability of the target software is improved, and the coverage rate data of the new version of codes can be obtained under the condition that the original test modes are not interfered.
Drawings
FIG. 1 is a flowchart of a code coverage calculating method according to an embodiment;
FIG. 2 is a block diagram of a computer device of an embodiment;
FIG. 3 is a schematic diagram of a code coverage calculating device according to an embodiment.
The achievement of the objects, functional features and advantages of the present application will be further described with reference to the accompanying drawings, in conjunction with the embodiments.
Detailed Description
The present application will be described in further detail with reference to the drawings and examples, in order to make the objects, technical solutions and advantages of the present application more apparent. It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the scope of the application.
As used herein, the singular forms "a", "an", "the" and "the" are intended to include the plural forms as well, unless expressly stated otherwise, as understood by those skilled in the art. It will be further understood that the terms "comprises" and/or "comprising," when used in this specification, specify the presence of stated features, integers, steps, operations, elements, modules, and/or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, modules, components, and/or groups thereof. It will be understood that when an element is referred to as being "connected" or "coupled" to another element, it can be directly connected or coupled to the other element or intervening elements may also be present. Further, "connected" or "coupled" as used herein may include wirelessly connected or wirelessly coupled. The term "and/or" as used herein includes all or any module and all combination of one or more of the associated listed items.
It will be understood by those skilled in the art that all terms (including technical and scientific terms) used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs unless defined otherwise. It will be further understood that terms, such as those defined in commonly used dictionaries, should be interpreted as having a meaning that is consistent with their meaning in the context of the prior art and will not be interpreted in an idealized or overly formal sense unless expressly so defined herein.
In the existing software development process, a developer usually develops a plurality of versions of software codes according to actual demands, and adopts a new version of software code to iteratively update an old version, and after updating, the software code needs to be tested to judge whether the new version of software code can meet the demands. In the code test process, the code is covered by the test case generally, but the current technical scheme can only carry out full test on the code of each version, so that the problem that the test result of partial new version code cannot be obtained due to incomplete code coverage by the test case can be avoided. However, the total test is relatively long, and in order to determine the coverage of the test case, the unmodified code needs to be tested, and meanwhile, most companies are turning to the agile development model from the waterfall development model, so that the version period is short, the increment requirement is low, the stock code is more, and finally, when the software code of a new version is tested, the main test time is difficult to be input into the newly-increased requirement and the increment code part by a tester, and the unmodified stock code part which has already been tested is consumed. Therefore, the embodiment provides a code coverage rate calculating method, so that the coverage condition of the software code is calculated when the version is updated, and the stability of the version is improved.
Referring to fig. 1, a flow chart of a code coverage rate calculating method disclosed in the present embodiment includes:
s11: acquiring first coverage rate data corresponding to a first version of target software and second coverage rate data corresponding to a second version, wherein the first version is a historical version, and the second version is a version obtained by updating the historical version;
s12: calculating the row coverage information of the first version according to the first coverage rate data;
s13: calculating code differences between the first version and the second version according to the version information corresponding to the first version and the version information corresponding to the second version;
s14: and according to the row coverage information and the code difference, obtaining an accumulation mode of the first coverage rate data and the second coverage rate data, and according to the accumulation mode, superposing the first coverage rate data into the second coverage rate data to obtain the current accumulated coverage rate data of the target software.
As described in step S11, the target software refers to the software to be tested, which generally corresponds to at least two versions of code, in this embodiment, the version to be replaced is the first version, i.e. the history version, and the version of the code used for replacing the first version is the second version, where "first" and "second" in the first version and the second version do not directly refer to the development sequence of the software code, and if the current version of the target software is V5, but the version used for replacing the V5 is V3, then V5 is the first version, V3 is the second version, and the remaining versions are not described herein. The coverage data refers to the coverage condition of the test case on the code of the corresponding version, that is, the ratio of the number of covered codes to the total number of codes in the corresponding version, and in this embodiment, the coverage condition of the code of the first version covered by the test case is used as the first coverage data, and the coverage condition of the code of the second version covered by the test case is used as the second coverage data.
In a specific embodiment, after performing a software test and generating a test case, the first coverage rate data and the second coverage rate data may be collected by a jacoco tool, where the jacoco tool is a technical tool that provides a standard for code coverage rate analysis in an environment based on a Java VM, and is capable of performing code detection immediately by using an ASM, and in the process, receiving an event from JVM Tool Interface, and finally generating a code coverage rate report. Specifically, firstly, stake-inserting is performed by a jacoco tool, a tester performs a target software test by using the application program after stake-inserting, and coverage rate data of the current test case on the current version code can be generated in the test process, specifically, the step of generating the coverage rate data can be as follows: performing./ gradlew jacocoInit initialization engineering; the normal test is carried out to obtain a test report; after the test is finished, an ec file in the sdcard directory is pulled out through an adb (android debug bridge ) command and is put into a/app/build/output/code-coverage/custom directory; execution/gradlew jacocoTestReport; the relevant report of coverage data is viewed in the catalog/app/build/reports. In a specific embodiment, in addition to the coverage rate data of the test cases of the two versions, version information such as version numbers of the two versions can be obtained, and corresponding coverage rate data files are named according to the version numbers, so that version distinction and coverage rate accumulation in a subsequent test process are facilitated.
As described in step S12, the first coverage data may be an xml-format coverage report, which is generally as follows:
the Sourcefile element generally includes a plurality of line elements, coverage rate of the line elements in the coverage rate report is judged one by traversing the coverage rate report, when a certain line element is not covered by the test case, the line element is regarded as an uncovered line, when a certain line element is covered by the test case, the line element is regarded as a covered line, and positions of the uncovered line and the covered line are counted, so that total line coverage information is obtained, wherein the line coverage information represents a condition that each line is covered by the test case in the code of the current version.
As described in the above step S13, in the iterative process of the software code, there are often cases where the code is increased, decreased, and changed, and the code difference generally refers to a file difference or a line difference between two versions, and if the first version is an old version, the second version is a new version, for example. The code difference between the first and second versions may be: (1) In the second version, x.txt files are more, y.txt files are less, and z.txt files are changed than in the first version; (2) In the z.txt file, line 1 of the first version becomes lines 1-5 of the second version (i.e., indicating that the second version is added 4 lines to the first version), lines 10-14 of the first version becomes lines 14-18 of the second version, and so on. In a specific embodiment, the code differences may be caused by version name replacement, addition or reduction of functions, modification of functions existing in old versions, and so on, which are not specifically described in this embodiment.
Specifically, the code differences between the first version and the second version may be calculated by a Git tool. The Git tool can treat the code as a series of snapshots of the small file system, each time the update is submitted or a new version state is saved, the Git tool creates a snapshot of all files at that time and saves the index of the snapshot, and in addition, a link pointing to the old version can be reserved, so that the code difference calculation between the two versions can be performed locally.
After the line coverage information and the code difference are obtained in the step S14, the coverage condition of the test case of the first version on the code of the first version can be obtained according to the line coverage information, and then the update conditions of the code addition, modification, deletion and the like between the first version and the second version are obtained according to the code difference between the first version and the second version, so that the coverage rate data is accumulated according to the update conditions of the addition, modification, deletion and the like; for example, for codes that exist in the first version and do not exist in the second version, the first coverage data of the portion of codes may be directly deleted, for codes that do not exist in the first version and exist in the second version, the second coverage data of the portion of codes may be directly added to the current accumulated coverage data, and for codes that exist in the first version and have been modified in the second version, the first coverage data of the portion of codes may be replaced with the corresponding second coverage data; the coverage rate data of the first and second versions of software can be accumulated through the whole superposition flow to obtain the ACC (accumulated coverage rate data) of the current version. At the same time, the ACC can continue to participate in the coverage data accumulation of the next version because the format of the ACC is consistent with the format of the coverage data.
In summary, the first coverage rate data of the old version of test cases and the second coverage rate data of the new version of test cases are respectively obtained, line coverage information calculation is performed on the old version of target software, and code difference calculation is performed on different versions of the target software to obtain different accumulation modes, so that the coverage rate data of different versions are overlapped according to the obtained accumulation modes, the comprehensiveness of the coverage of each new version of target software can be observed without full test, thereby helping testers to perform defect and leak detection on the test cases, improving the controllability of the quality of the target software, and obtaining the coverage rate data of new version codes under the condition of not interfering with the original test modes.
In one embodiment, the first version of line coverage information includes a first mapping array, and the calculating the first version of line coverage information from the first coverage data includes:
traversing the first coverage data, identifying a first coverage row in the first coverage data;
and adding the first coverage row into the first mapping array to obtain the row coverage information.
As described above, the mapping M from the coverage report file path in the xml format corresponding to the first coverage data to the first coverage line is created, the coverage report file is traversed, and whether the line element in the file is the first coverage line is judged line by line, that is, whether the line element is changed compared with the line element of the previous version is judged, if yes, the line element is considered to be the first coverage line, if not, the line element is considered to be the same as the previous version and not belong to the first coverage line, thereby improving the accuracy of coverage calculation.
In one embodiment, the adding the first coverage line to a mapping array includes:
when a first package element which is not accessed exists in the first coverage rate data, accessing the first package element in the first coverage rate data, extracting a first path attribute of the first source file element if the first source file element exists in the first package element, and taking the first path attribute as a key of the first mapping array;
and adding the first coverage line in the first source file element into the first mapping array to serve as a first mapping value of the first mapping array.
As described above, for the coverage report in the xml format, the first Package element is the Package element in the first coverage data, and the first source file element is the Sourcefile element in the first coverage data. In order to avoid omission of line elements, after traversing first coverage rate data, performing line element identification from the first line of the first coverage rate data, accessing a first package element in the first coverage rate data, judging whether a next first source file element exists in the first package element, if so, extracting a first path attribute (path attribute) of the first source file element, taking the first path attribute as a key of a first mapping array, creating a first mapping array A as a value of a mapping M, judging whether line elements exist in the first source file element at the moment, performing primary coverage condition judgment on each line element, taking the line element meeting coverage conditions as a first coverage line, and adding the line element into the mapping array A; if not, the first source file element in the first package element is accessed, the first package element is jumped out at the moment, whether the next first package element exists or not is judged, and if so, the process is executed again until the next first package element does not exist.
In one embodiment, the accumulating mode of the first coverage rate data and the second coverage rate data according to the row coverage information and the code difference, and the first coverage rate data is overlapped in the second coverage rate data according to the accumulating mode, so as to obtain the current accumulated coverage rate data of the target software, which includes:
accessing a second packet element in the second coverage rate data when the second packet element which is not accessed exists in the second coverage rate data, and judging whether a second path attribute of the second source file element belongs to the first mapping array or not if a second source file element exists in the second packet element;
if the second path attribute belongs to the first mapping array, judging whether the second path attribute belongs to the code difference, if so, performing first code coverage accumulation, and if not, performing second code coverage accumulation;
if the second path attribute does not belong to the first mapping array, performing first code addition and accumulation;
and when the second coverage rate data does not contain the second packet element which is not accessed, storing the accumulated coverage result to obtain the current accumulated coverage rate data of the target software.
As described above, for the coverage report in the xml format, the second packet element is the Package element in the second coverage data, and the second source file element is the Sourcefile element in the second coverage data. After traversing the second coverage rate data, performing line element identification from the first line of the second coverage rate data, so as to avoid missing line elements, accessing a first second packet element in the second coverage rate data, judging whether two second source file elements exist in the second packet element, if so, judging whether a second path attribute (path attribute) of the second source file element belongs to a first mapping array A, if so, judging whether the second path attribute belongs to a code difference obtained in the steps, if so, entering a first code coverage accumulation, namely, the second source file element is a modified element, entering a modified file processing flow, and if not, performing second code coverage accumulation, namely, the second source file element is not modified, and entering a non-modified file processing flow; if the second path attribute does not belong to the first mapping array, taking the second source file element as a newly added file, and performing first code addition accumulation, namely, a newly added file processing flow, so as to respectively perform coverage rate accumulation on the modified, unmodified and newly added codes.
In one embodiment, the performing the first code coverage accumulation includes:
judging whether the second line element is a newly added line element or not when the second line element which is not accessed exists in the second source file element;
if the second line element is not the newly added line element, judging whether the second line element is the first coverage line through the first mapping array, if so, accumulating first coverage information of the second line element under the first version, and if not, accumulating second coverage information of the second line element under the second version;
and if the second row element is the newly added row element, accumulating third coverage information of the second row element.
As described above, the first code coverage accumulation is a modified file processing flow, for the second source file element whose second path attribute belongs to the first mapping array a and also belongs to the code difference, performing the second line element traversal, that is, the line element traversal in the second source file element, if the line element does not belong to the newly added line in the second version, judging whether the line element is the first coverage line through the first mapping array a, if yes, considering that the line element inherits the covered state of the first version, accumulating the coverage rate of the line element under the ACC of the first version, and saving the covered state of the line element as the first coverage information, if not, considering that the covered state of the line element is determined by the second version, so that the coverage rate of the line element is accumulated under the ACC of the second version, and saving the covered state of the line element as the second coverage information of the second version; if the line element belongs to the new addition in the second version, the coverage information of the line element is reserved as third coverage information, so that the first coverage information, the second coverage information and the third coverage information obtained in the first code coverage accumulation link are accumulated into the current accumulation coverage data of the target software.
In one embodiment, the performing the second code coverage accumulation includes:
judging whether the second line element is the first coverage line or not through the first mapping array when the second line element which is not accessed exists in the second source file element;
if yes, accumulating first coverage information of the second row element under the first version;
if not, accumulating second coverage information of the second row element under the second version.
As described above, if the second path attribute belongs to the first mapping array a and does not belong to the code difference, the second code coverage is accumulated as a non-change file processing flow, which indicates that the code in the second source file element is in a non-change state, and at this time, the second line element is traversed to determine whether the second line element in the second source file element belongs to the first version or the second version; specifically, whether the line element is the first coverage line is judged through the first mapping genus group A, if yes, the line element is considered to inherit the coverage state of the first version, the coverage rate of the line element is accumulated under the ACC of the first version and is stored as first coverage information, if no, the coverage state of the line element is considered to be determined by the second version, therefore, the coverage rate of the line element is accumulated under the ACC of the second version and is stored as second coverage information of the second version, and the first coverage information and the second coverage information obtained by the second code coverage accumulation link are accumulated into the current accumulated coverage rate data of the target software again.
In one embodiment, the performing the first code addition accumulation includes:
judging whether a second line element which is not accessed exists in the second source file element or not;
if yes, accumulating third coverage information of the second row element;
if not, the accumulation is ended.
As described above, the first code is newly added and accumulated into the newly added file processing flow, it can be understood that if the second path attribute does not belong to the first mapping array a and does not belong to the code difference, it means that the code in the second source file element is not the code in the first version, nor the code obtained by overlaying the first version in the second version, but is the newly added code without history record, so that it is not necessary to distinguish whether the second code belongs to the first version or the second version, traverse the second line element in the second source file element, and separately accumulate the second line element to obtain the third coverage information, so that the third coverage information obtained in the newly added and accumulated link of the first code is accumulated into the current accumulated coverage data of the target software again, and the current accumulated coverage data after the new addition judgment, the modification judgment and the no change judgment is obtained, and under the condition that the original test mode is not interfered, the coverage condition of the target software code is obtained.
Referring to fig. 2, a block diagram of a code coverage rate calculating device disclosed in the present embodiment is provided, where the device includes:
the data acquisition unit 100 is configured to acquire first coverage rate data corresponding to a first version of the target software, and second coverage rate data corresponding to a second version of the target software, where the first version is a historical version, and the second version is a version updated by the historical version;
a line coverage information calculation unit 200, configured to calculate line coverage information of the first version according to the first coverage data;
a code difference calculating unit 300, configured to calculate a code difference between the first version and the second version according to version information corresponding to the first version and version information corresponding to the second version;
and the coverage rate accumulating unit 400 is configured to obtain an accumulating mode of the first coverage rate data and the second coverage rate data according to the line coverage information and the code difference, and superimpose the first coverage rate data onto the second coverage rate data according to the accumulating mode to obtain current accumulated coverage rate data of the target software.
In one embodiment, the row coverage information calculation unit 200 is specifically configured to:
traversing the first coverage data, identifying a first coverage row in the first coverage data;
and adding the first coverage row into the first mapping array to obtain the row coverage information.
In one embodiment, the row coverage information calculation unit 200 is specifically configured to:
when a first package element which is not accessed exists in the first coverage rate data, accessing the first package element in the first coverage rate data, extracting a first path attribute of the first source file element if the first source file element exists in the first package element, and taking the first path attribute as a key of the first mapping array;
and adding the first coverage line in the first source file element into the first mapping array to serve as a first mapping value of the first mapping array.
In one embodiment, the coverage accumulating unit 400 is specifically configured to:
accessing a second packet element in the second coverage rate data when the second packet element which is not accessed exists in the second coverage rate data, and judging whether a second path attribute of the second source file element belongs to the first mapping array or not if a second source file element exists in the second packet element;
if the second path attribute belongs to the first mapping array, judging whether the second path attribute belongs to the code difference, if so, performing first code coverage accumulation, and if not, performing second code coverage accumulation;
if the second path attribute does not belong to the first mapping array, performing first code addition and accumulation;
and when the second coverage rate data does not contain the second packet element which is not accessed, storing the accumulated coverage result to obtain the current accumulated coverage rate data of the target software.
In one embodiment, the coverage accumulating unit 400 is specifically configured to:
judging whether the second line element is a newly added line element or not when the second line element which is not accessed exists in the second source file element;
if the second line element is not the newly added line element, judging whether the second line element is the first coverage line through the first mapping array, if so, accumulating first coverage information of the second line element under the first version, and if not, accumulating second coverage information of the second line element under the second version;
and if the second row element is the newly added row element, accumulating third coverage information of the second row element.
In one embodiment, the coverage accumulating unit 400 is specifically configured to:
judging whether the second line element is the first coverage line or not through the first mapping array when the second line element which is not accessed exists in the second source file element;
if yes, accumulating first coverage information of the second row element under the first version;
if not, accumulating second coverage information of the second row element under the second version.
In one embodiment, the coverage accumulating unit 400 is specifically configured to:
judging whether a second line element which is not accessed exists in the second source file element or not;
if yes, accumulating third coverage information of the second row element;
if not, the accumulation is ended.
Referring to fig. 3, a computer device is further provided in an embodiment of the present application, and the internal structure of the computer device may be as shown in fig. 3. The computer device includes a processor, a memory, a network interface, and a database connected by a system bus. Wherein the processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The nonvolatile storage medium stores an operating device, a computer program, and a database. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage media. The database of the computer device is used for storing code coverage rate calculation data and the like. The network interface of the computer device is used for communicating with an external terminal through a network connection. The computer program is executed by a processor to implement a code coverage calculation method.
It will be appreciated by those skilled in the art that the architecture shown in fig. 3 is merely a block diagram of a portion of the architecture in connection with the present inventive arrangements and is not intended to limit the computer devices to which the present inventive arrangements are applicable.
An embodiment of the present application also provides a computer-readable storage medium having stored thereon a computer program which, when executed by a processor, implements a code coverage calculating method. It is understood that the computer readable storage medium in this embodiment may be a volatile readable storage medium or a nonvolatile readable storage medium.
According to the method, the device, the equipment and the medium for calculating the code coverage rate, the first coverage rate data of the old version of test cases and the second coverage rate data of the new version of test cases are respectively obtained, the old version of target software is subjected to line coverage information calculation, and different versions of the target software are subjected to code difference calculation to obtain different accumulation modes, so that the coverage rate data of different versions are overlapped according to the obtained accumulation modes to obtain the accumulated coverage rate data of the current version, the purpose that the coverage integrity of the new version can be observed without full test for each new version of target software is achieved, the test cases are helped to be subjected to the defect checking and the leakage checking by a tester, the quality controllability of the target software is improved, and the coverage rate data of the new version of code is obtained under the condition that the original test mode is not interfered.
Those skilled in the art will appreciate that implementing all or part of the above described methods may be accomplished by way of a computer program stored on a non-transitory computer readable storage medium, which when executed, may comprise the steps of the embodiments of the methods described above. Any reference to memory, storage, database, or other medium provided by the present application and used in embodiments may include non-volatile and/or volatile memory. The nonvolatile memory can include Read Only Memory (ROM), programmable ROM (PROM), electrically Programmable ROM (EPROM), electrically Erasable Programmable ROM (EEPROM), or flash memory. Volatile memory can include Random Access Memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms such as Static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual speed data rate SDRAM (SSRSDRAM), enhanced SDRAM (ESDRAM), synchronous Link DRAM (SLDRAM), memory bus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), among others.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, apparatus, article, or method that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, apparatus, article, or method. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, apparatus, article or method that comprises the element.
The foregoing description is only of the preferred embodiments of the present application and is not intended to limit the scope of the application, and all equivalent structures or equivalent processes using the descriptions and drawings of the present application or directly or indirectly applied to other related technical fields are included in the scope of the application.

Claims (10)

1. A code coverage calculation method, comprising:
acquiring first coverage rate data corresponding to a first version of target software and second coverage rate data corresponding to a second version, wherein the first version is a historical version, and the second version is a version obtained by updating the historical version;
calculating the row coverage information of the first version according to the first coverage rate data;
calculating code differences between the first version and the second version according to the version information corresponding to the first version and the version information corresponding to the second version;
and according to the row coverage information and the code difference, obtaining an accumulation mode of the first coverage rate data and the second coverage rate data, and according to the accumulation mode, superposing the first coverage rate data into the second coverage rate data to obtain the current accumulated coverage rate data of the target software.
2. The code coverage calculation method of claim 1, wherein the first version of line coverage information includes a first mapping array, the calculating the first version of line coverage information from the first coverage data comprising:
traversing the first coverage data, identifying a first coverage row in the first coverage data;
and adding the first coverage row into the first mapping array to obtain the row coverage information.
3. The code coverage calculation method of claim 2, wherein the adding the first coverage line to a mapping array comprises:
when a first package element which is not accessed exists in the first coverage rate data, accessing the first package element in the first coverage rate data, extracting a first path attribute of the first source file element if the first source file element exists in the first package element, and taking the first path attribute as a key of the first mapping array;
and adding the first coverage line in the first source file element into the first mapping array to serve as a first mapping value of the first mapping array.
4. The code coverage calculating method according to claim 3, wherein the accumulating manner of the first coverage data and the second coverage data according to the row coverage information and the code difference is obtained, the first coverage data is superimposed into the second coverage data according to the accumulating manner, the current accumulated coverage data of the target software is obtained, comprising:
accessing a second packet element in the second coverage rate data when the second packet element which is not accessed exists in the second coverage rate data, and judging whether a second path attribute of the second source file element belongs to the first mapping array or not if a second source file element exists in the second packet element;
if the second path attribute belongs to the first mapping array, judging whether the second path attribute belongs to the code difference, if so, performing first code coverage accumulation, and if not, performing second code coverage accumulation;
if the second path attribute does not belong to the first mapping array, performing first code addition and accumulation;
and when the second coverage rate data does not contain the second packet element which is not accessed, storing the accumulated coverage result to obtain the current accumulated coverage rate data of the target software.
5. The code coverage calculation method of claim 4, wherein the performing the first code coverage accumulation comprises:
judging whether the second line element is a newly added line element or not when the second line element which is not accessed exists in the second source file element;
if the second line element is not the newly added line element, judging whether the second line element is the first coverage line through the first mapping array, if so, accumulating first coverage information of the second line element under the first version, and if not, accumulating second coverage information of the second line element under the second version;
and if the second row element is the newly added row element, accumulating third coverage information of the second row element.
6. The code coverage calculation method of claim 4, wherein the performing the second code coverage accumulation comprises:
judging whether the second line element is the first coverage line or not through the first mapping array when the second line element which is not accessed exists in the second source file element;
if yes, accumulating first coverage information of the second row element under the first version;
if not, accumulating second coverage information of the second row element under the second version.
7. The code coverage calculating method of claim 4, wherein said performing the first code addition accumulation comprises:
judging whether a second line element which is not accessed exists in the second source file element or not;
if yes, accumulating third coverage information of the second row element;
if not, the accumulation is ended.
8. A code coverage calculating apparatus, comprising:
the data acquisition unit is used for acquiring first coverage rate data corresponding to a first version of target software and second coverage rate data corresponding to a second version, wherein the first version is a historical version, and the second version is a version obtained by updating the historical version;
a line coverage information calculation unit configured to calculate line coverage information of the first version according to the first coverage data;
a code difference calculating unit, configured to calculate a code difference between the first version and the second version according to version information corresponding to the first version and version information corresponding to the second version;
and the coverage rate accumulation unit is used for obtaining an accumulation mode of the first coverage rate data and the second coverage rate data according to the row coverage information and the code difference, and overlapping the first coverage rate data into the second coverage rate data according to the accumulation mode to obtain the current accumulated coverage rate data of the target software.
9. A computer device comprising a memory and a processor, the memory having stored therein a computer program, characterized in that the processor, when executing the computer program, implements the steps of the code coverage calculation method of any of claims 1 to 7.
10. A computer-readable storage medium, on which a computer program is stored, characterized in that the computer program, when being executed by a processor, implements the steps of the code coverage calculation method of any one of claims 1 to 7.
CN202210122768.0A 2022-02-09 2022-02-09 Code coverage rate calculation method, device, equipment and medium Pending CN116610551A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210122768.0A CN116610551A (en) 2022-02-09 2022-02-09 Code coverage rate calculation method, device, equipment and medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210122768.0A CN116610551A (en) 2022-02-09 2022-02-09 Code coverage rate calculation method, device, equipment and medium

Publications (1)

Publication Number Publication Date
CN116610551A true CN116610551A (en) 2023-08-18

Family

ID=87673431

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210122768.0A Pending CN116610551A (en) 2022-02-09 2022-02-09 Code coverage rate calculation method, device, equipment and medium

Country Status (1)

Country Link
CN (1) CN116610551A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117349150A (en) * 2023-09-22 2024-01-05 乾升利信息技术(上海)有限公司 Coverage rate data processing method and device, electronic equipment and storage medium

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117349150A (en) * 2023-09-22 2024-01-05 乾升利信息技术(上海)有限公司 Coverage rate data processing method and device, electronic equipment and storage medium

Similar Documents

Publication Publication Date Title
US6305010B2 (en) Test, protection, and repair through binary code augmentation
EP3265916B1 (en) A method for identifying a cause for a failure of a test
US8347271B1 (en) Software testing
US7096339B2 (en) System and method for detecting memory management programming errors
CN111897727A (en) Software testing method and device, computer equipment and storage medium
CN112363937B (en) Differential coverage rate testing method, differential coverage rate testing device, computer equipment and storage medium
CN116610551A (en) Code coverage rate calculation method, device, equipment and medium
CN110597710B (en) Test coverage rate statistical method, device, computer equipment and storage medium
CN113282513B (en) Interface test case generation method and device, computer equipment and storage medium
CN114924737A (en) Battery management system source code integration test method and device and electronic equipment
CN110633213B (en) Unit test method, unit test device, computer equipment and storage medium
CN113051582B (en) Computer software technology development and debugging system
CN115185821A (en) Version labeling method, system, equipment and storage medium in program test
Sandgren et al. Software safety analysis to support iso 26262-6 compliance in agile development
US11740895B2 (en) Generation of software program repair explanations
CN113821213A (en) Front-end code detection and restoration method, device and equipment based on artificial intelligence
CN112416781A (en) Cross-system interface determination method and device, computer equipment and storage medium
CN107885663B (en) Method and device for automatically generating test case, computer equipment and storage medium
CN116430835B (en) Fault storage and analysis method of Cortex-M microcontroller
CN111367816B (en) Mobile test method and device, computer equipment and storage medium
CN115934157A (en) Software dependency range automatic inference method, device, computer equipment and memory
CN117520147A (en) Code coverage rate statistical method, device, computer equipment and storage medium
CN116225889A (en) Test position marking method and device, electronic equipment and storage medium
CN116594871A (en) Memory leak detection method
CN112363930A (en) Software development testing method, device, equipment and medium

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