[go: up one dir, main page]

CN114416546B - Code coverage rate determining method and device - Google Patents

Code coverage rate determining method and device

Info

Publication number
CN114416546B
CN114416546B CN202210014181.8A CN202210014181A CN114416546B CN 114416546 B CN114416546 B CN 114416546B CN 202210014181 A CN202210014181 A CN 202210014181A CN 114416546 B CN114416546 B CN 114416546B
Authority
CN
China
Prior art keywords
file
code
coverage
function
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.)
Active
Application number
CN202210014181.8A
Other languages
Chinese (zh)
Other versions
CN114416546A (en
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.)
Everbright Technology Co ltd
China Everbright Bank Co Ltd
Original Assignee
Everbright Technology Co ltd
China Everbright Bank 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 Everbright Technology Co ltd, China Everbright Bank Co Ltd filed Critical Everbright Technology Co ltd
Priority to CN202210014181.8A priority Critical patent/CN114416546B/en
Publication of CN114416546A publication Critical patent/CN114416546A/en
Application granted granted Critical
Publication of CN114416546B publication Critical patent/CN114416546B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Prevention of errors by analysis, debugging or testing of software
    • G06F11/3668Testing of software
    • G06F11/3672Test management
    • G06F11/3676Test management for coverage analysis
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Prevention of errors by analysis, debugging or testing of software
    • G06F11/3668Testing of software
    • G06F11/3672Test management
    • G06F11/3684Test management for test design, e.g. generating new test cases
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Prevention of errors by analysis, debugging or testing of software
    • G06F11/3668Testing of software
    • 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 present invention provides a method and device for determining code coverage, wherein the method comprises: querying multiple associated code versions according to the requirements of the software under test; determining the code impact range of the code involved in the requirement; accumulating the coverage of the multiple code versions to obtain the cumulative coverage of the requirement; and determining the coverage of the code under test according to the code impact range and the cumulative coverage. This method can solve the problem in the field of software testing in the related art that the existing coverage calculation has limitations and low testing value, supports testing scenarios that require multiple rounds and mid-term version changes, and improves the testing value of code coverage.

Description

Code coverage rate determining method and device
Technical Field
The invention relates to the field of data processing, in particular to a code coverage rate determining method and device.
Background
With the rapid development of software technology, software testing work is also evolving continuously, industry testing standards are gradually formed, new testing tool means are landed in a dispute, and testing is increasingly displayed as a basic guarantee function of software quality improvement and synergy and prevention and control risks. In the face of new requirements of national credit and creation strategy and new requirements of novel business modes such as open banks, the bank software test work is to grasp trends, strengthen capability construction, extend fields, innovation methods and form standards continuously, become supporters, guarding and leaders of financial and technological innovation, and embody greater self value in the digitalized conversion process of banks.
The code coverage rate of software test refers to the proportion or degree to which the code is executed during test, and the quality of the code can be measured to a certain degree through the code coverage rate.
In the prior art scheme or the open source scheme, for supporting the test coverage rate, the coverage rate or the increment coverage rate only of the full code is limited, and the application scene is simpler.
In the field of software testing, existing coverage calculation techniques have the following drawbacks:
The existing coverage technology only supports measuring the coverage index of the software of the same version. But cannot support test scenarios requiring multiple rounds and halfway replacement versions, such as system testing.
The test is low in value, the measurement result of the existing coverage rate technology is irrelevant to the functions and requirements of software, the coverage rate calculation is simply and indiscriminately carried out on all codes, and a tester never knows the actual coverage condition of the target function.
Aiming at the problems of limitation and low test value of the existing coverage rate calculation in the software test field in the related technology, no solution is proposed yet.
Disclosure of Invention
The embodiment of the invention provides a code coverage rate determining method and device, which at least solve the problems of limitation and low test value of the existing coverage rate calculation in the field of software test in the related technology.
According to an embodiment of the present invention, there is provided a code coverage rate determination method including:
Inquiring a plurality of associated code versions according to the requirements of the tested software;
determining a code impact range for the code for which the demand relates;
accumulating the coverage rates of the plurality of code versions to obtain the accumulated coverage rate of the requirement;
and determining the coverage rate of the tested codes according to the code influence range and the accumulated coverage rate.
Optionally, after determining the coverage of the tested code according to the code influence range and the accumulated coverage, the method further includes:
And according to the code influence range of the requirement, dyeing the code covered by the tested software.
Optionally, determining that the requirement relates to a code scope of influence of the code comprises:
Comparing the java codes of the initial version and the current version in the plurality of code versions related to the requirements by using a version comparison tool to obtain a change line number set DL [ line ] of the codes, and storing the change line number set DL [ line ] of the codes into a storage medium;
Analyzing the java code of the current version by utilizing an abstract syntax tree AST, and identifying a function set F [ function ];
And screening the function set F [ function ] according to the change line number set DL [ line ] to obtain a change function set DF [ function ] of the requirement, wherein the code influence range is the change function set DF [ function ].
Optionally, determining the coverage rate of the tested code according to the code influence range and the accumulated coverage rate includes:
and screening the accumulated coverage rate by using the changed function set DF [ function ] to obtain the required coverage rate.
Optionally, accumulating the coverage rates of the plurality of code versions, and obtaining the accumulated coverage rate of the requirement includes:
Inserting a single application program of the tested software by using a code coverage rate tool jacoco, collecting coverage rate information of the plurality of code versions at fixed frequency, and storing the coverage rate information in a storage medium in an xml file format;
acquiring a plurality of XML files from a storage medium;
Sequencing the plurality of XML files according to the time sequence to obtain File 1, file 2, file 3, & gt, file n;
sequentially merging File 1, file 2, file 3, file n-1 into File n with the latest Filen as a reference to obtain a merging result;
and determining the accumulated coverage rate according to the merging result.
Optionally, merging File1, file 2, file 3, and File n-1 into the File n in sequence with the latest File n as a reference, where obtaining the merging result includes:
The following steps are performed on each of the File 1, file 2, file 3,..once the merging of the File 1, file 2, file 3,..once, file n-1 into the File n is completed, the merging result is obtained, wherein the current File is the one being executed:
The current File is subjected to coverage details COVa of the unique signature KEYa of the function;
analyzing Filen to obtain coverage details COVan of the unique signature KEYan of the function;
If KEYa corresponding to the current File is equal to KEYan, merging the coverage details COVa corresponding to the current File and the coverage details COVan corresponding to Filen;
If KEYa corresponding to the current File is not equal to KEYan, discarding COVa corresponding to the current File, and only COVan corresponding to Filen is reserved.
According to another embodiment of the present invention, there is also provided a code coverage rate determination apparatus including:
the query module is used for querying a plurality of associated code versions according to the requirements of the tested software;
A first determining module for determining a code impact range of the code related to the demand;
The accumulation module is used for accumulating the coverage rates of the plurality of code versions to obtain the accumulated coverage rate of the requirement;
And the second determining module is used for determining the coverage rate of the tested codes according to the code influence range and the accumulated coverage rate.
Optionally, the apparatus further comprises:
And the dyeing module is used for dyeing the codes covered by the tested software according to the code influence range of the requirement.
Optionally, the first determining module includes:
the comparison sub-module is used for comparing the java codes of the initial version and the current version in the plurality of code versions related to the requirements by utilizing a version comparison tool to obtain a change line number set DL [ line ] of the codes, and storing the change line number set DL [ line ] into a storage medium;
The analysis submodule is used for analyzing the java code of the current version by utilizing an abstract syntax tree AST and identifying a function set F [ function ];
And the screening submodule is used for screening the function set F [ function ] according to the change line number set DL [ line ] to obtain a change function set DF [ function ] of the requirement, wherein the code influence range is the change function set DF [ function ].
Optionally, the second determining module is further configured to:
and screening the accumulated coverage rate by using the changed function set DF [ function ] to obtain the required coverage rate.
Optionally, the accumulating module includes:
The instrumentation sub-module is used for instrumentation of a single application program of the tested software by using a code coverage rate tool jacoco, collecting coverage rate information of the plurality of code versions at fixed frequency and storing the coverage rate information in a storage medium in an xml file format;
An acquisition sub-module for acquiring a plurality of XML files from the storage medium;
The sequencing sub-module is used for sequencing the XML files according to the time sequence to obtain File 1, file 2, file 3, the.
The merging sub-module is used for merging the latest File 1, the latest File 2, the latest File 3 and the latest File n into the File n in sequence to obtain a merging result;
and determining the accumulated coverage rate according to the merging result.
Optionally, the merging sub-module is further configured to:
The following steps are performed on each of the File 1, file 2, file 3,..once the merging of the File 1, file 2, file 3,..once, file n-1 into the File n is completed, the merging result is obtained, wherein the current File is the one being executed:
The current File is subjected to coverage details COVa of the unique signature KEYa of the function;
Analyzing the File n to obtain coverage details COVan of the unique signature KEYan of the function;
If KEYa corresponding to the current File is equal to KEYan, merging the coverage details COVa corresponding to the current File and the coverage details COVa n corresponding to the File n;
if KEYa corresponding to the current File is not equal to KEYan, discarding the coverage details COVa corresponding to the current File, and only reserving the coverage details COVan corresponding to the File n.
According to a further embodiment of the invention, there is also provided a computer-readable storage medium having stored therein a computer program, wherein the computer program is arranged to perform the steps of any of the method embodiments described above when run.
According to a further embodiment of the invention, there is also provided an electronic device comprising a memory having stored therein a computer program and a processor arranged to run the computer program to perform the steps of any of the method embodiments described above.
The method and the device for testing the code coverage rate of the software under test can solve the problems that in the related technology, the existing coverage rate calculation has limitation and low test value in the software testing field, support the testing scene of needing to replace the version in multiple rounds and midway and improve the test value of the code coverage rate.
Drawings
The accompanying drawings, which are included to provide a further understanding of the application and are incorporated in and constitute a part of this specification, illustrate embodiments of the application and together with the description serve to explain the application and do not constitute a limitation on the application. In the drawings:
fig. 1 is a block diagram of a hardware structure of a mobile terminal of a code coverage rate determination method of an embodiment of the present invention;
FIG. 2 is a flow chart of a code coverage determination method according to an embodiment of the present invention;
FIG. 3 is a flow chart of a test code analysis according to an embodiment of the invention;
FIG. 4 is a flow chart of coverage acquisition and merging according to an embodiment of the present invention;
FIG. 5 is a schematic diagram of a merging process of overlay details COVa1 and COVan according to an embodiment of the invention;
FIG. 6 is a flow chart of a demand coverage query in accordance with an embodiment of the present invention;
fig. 7 is a block diagram of a code coverage rate determination apparatus according to an embodiment of the present invention.
Detailed Description
The application will be described in detail hereinafter with reference to the drawings in conjunction with embodiments. It should be noted that, without conflict, the embodiments of the present application and features of the embodiments may be combined with each other.
It should be noted that the terms "first," "second," and the like in the description and the claims of the present invention and the above figures are used for distinguishing between similar objects and not necessarily for describing a particular sequential or chronological order.
The method according to the first embodiment of the present application may be implemented in a mobile terminal, a computer terminal or a similar computing device. Taking a mobile terminal as an example, fig. 1 is a block diagram of a hardware structure of the mobile terminal according to the code coverage rate determining method of the embodiment of the present application, as shown in fig. 1, the mobile terminal may include one or more (only one is shown in fig. 1) processors 102 (the processors 102 may include, but are not limited to, a microprocessor MCU or a processing device such as a programmable logic device FPGA) and a memory 104 for storing data, and optionally, the mobile terminal may further include a transmission device 106 for a communication function and an input/output device 108. It will be appreciated by those skilled in the art that the structure shown in fig. 1 is merely illustrative and not limiting of the structure of the mobile terminal described above. For example, the mobile terminal may also include more or fewer components than shown in fig. 1, or have a different configuration than shown in fig. 1.
The memory 104 may be used to store a computer program, for example, a software program of application software and a module, such as a computer program corresponding to a code coverage rate determination method in an embodiment of the present invention, and the processor 102 executes the computer program stored in the memory 104 to perform various functional applications and data processing, that is, to implement the above-described method. Memory 104 may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include memory remotely located relative to the processor 102, which may be connected to the mobile terminal via a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The transmission means 106 is arranged to receive or transmit data via a network. Specific examples of the network described above may include a wireless network provided by a communication provider of the mobile terminal. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, simply referred to as a NIC) that can connect to other network devices through a base station to communicate with the internet. In one example, the transmission device 106 may be a Radio Frequency (RF) module, which is used to communicate with the internet wirelessly.
In this embodiment, a method for determining code coverage of a mobile terminal or a network architecture is provided, and fig. 2 is a flowchart of a method for determining code coverage according to an embodiment of the present invention, as shown in fig. 2, where the flowchart includes the following steps:
step S202, inquiring a plurality of associated code versions according to the requirements of tested software;
Step S204, determining a code influence range of codes related to the requirements;
step S206, accumulating the coverage rates of the code versions to obtain the accumulated coverage rate of the requirement;
And step S208, determining the coverage rate of the tested codes according to the code influence range and the accumulated coverage rate.
The method comprises the steps of S202 to S208, inquiring a plurality of related code versions according to the requirements of tested software, determining the code influence range of codes related to the requirements, accumulating the coverage rates of the plurality of code versions to obtain the accumulated coverage rate of the requirements, and determining the coverage rate of the tested codes according to the code influence range and the accumulated coverage rate.
In an optional embodiment, after the step S208, the code covered by the tested software is dyed according to the required code influence range, so that the user can clearly see the code covered by the tested software, and the user experience is improved.
In the embodiment of the invention, the step S204 specifically comprises the steps of comparing the java codes of the initial version and the current version in the plurality of code versions related to the requirement by using a version comparison tool to obtain a modified line number set DL [ line ] of the codes, storing the modified line number set DL [ line ] of the codes in a storage medium, analyzing the java codes of the current version by using an abstract syntax tree AST to identify a function set F [ function ], and screening the function set F [ function ] according to the modified line number set DL [ line ] to obtain a modified function set DF [ function ] of the requirement, wherein the code influence range is the modified function set DF [ function ].
Correspondingly, the step S206 may specifically include screening the cumulative coverage by using the changed function set DF [ function ] to obtain the required coverage.
In the embodiment of the invention, the step S206 specifically includes the steps of performing instrumentation on a single application program of the tested software by using a code coverage tool jacoco, collecting coverage information of multiple code versions at fixed frequency, storing the coverage information in an XML File format in a storage medium, obtaining multiple XML files from the storage medium, sequencing the multiple XML files according to time sequence order to obtain File 1, file 2, file 3, the.
Further, merging the latest File n into the File n in sequence with the latest File n as a reference, wherein the merging result is called a current File in the process of merging the current File into a coverage detail COVa of a unique signature KEYa of a function, resolving the current File into a coverage detail COVan of a unique signature KEYan of a function, merging the coverage detail COVa corresponding to the current File and the coverage COVan corresponding to the Filen if KEYa corresponding to the current File is equal to KEYan, and discarding the coverage detail 3998 corresponding to the current File if KEYa corresponding to the current File is not equal to the coverage detail 3998.
According to the embodiment of the invention, the related code version is inquired according to the software requirement, the specific influence range (function and line number) of the code related to the requirement is calculated, and the coverage rate accumulation among different versions is realized under the condition that the tested software is issued and tested for multiple times. And dyeing the code covered by the test according to the code influence range of the requirement. The steps will be described in detail below
1, Inquiring the associated code version according to the software requirement.
The requirements are described as an identification, i.e., (EapsId), during code development, release, and testing.
During development, a developer of the tested software application uses a version management tool (such as git) to continuously submit new codes, and when the codes are submitted each time, mandatory specifications are required to be complied with, namely, specified requirement numbers are associated. Thus, after the code is pushed to the development branch (such as develop branch) of the remote repository, the version management platform (such as gitlab, gitee) can establish the mapping relationship between the submission (commit) and the requirements through the requirements number.
When an operator of the software under test submits a new version on an automated pipeline (CI/CD), one or more demand numbers may be specified, and the automated pipeline may simply pick (approach-pick) the commit (commit) associated with the selected demand from the development branch (e.g., develop branch) of the code warehouse, then merge into the test branch (e.g., baseline branch), and then generate a new version number.
And then, an operation and maintenance person can initiate the deployment of the version on an automatic pipeline (CI/CD) to complete the compiling, packing and deploying work of the tested software.
The embodiment of the invention is integrated with an automatic pipeline (CI/CD), and each time a new code version of the tested software is lifted/deployed, the embodiment of the invention receives corresponding notification and records the application identifier, the requirement number, the version number, the lifting time and the deployment time of the tested software into a storage medium so as to establish the mapping relation between the requirement and the lifting version.
2, Calculating the specific influence range (function, line number) of codes related to the requirements.
And comparing the java codes of the initial version and the current version of the requirement by using a version comparison tool to obtain a change line number set DL [ line ] of the codes, and storing the change line number set DL [ line ] into a storage medium.
Then, the java code of the current version is analyzed by utilizing an Abstract Syntax Tree (AST), and a function set F [ function ] is identified.
And screening the function set F [ function ] according to the change line number set DL [ line ] to obtain a change function set DF [ function ] of the requirement.
And 3, under the condition that the tested software issues and tests for multiple times, the coverage rate accumulation among different versions is realized.
And (3) utilizing a code coverage rate tool jacoco to perform instrumentation on a single application program of the tested software, collecting coverage rate information of a target application at fixed frequency, and storing the coverage rate information in an xml file format in a storage medium.
By modifying jacoco, each function running in the java virtual machine is uniquely signed during coverage rate collection, each function generates a unique signature (function key), and a coverage rate detail (function coverage) and is embodied in the stored xml file.
Typically, coverage information of 1 hour will be saved as a single xml. For example, coverage information of 9:00 to 10:00 is stored as cover_2021091409_1.Xml.
Specifically, when a version change occurs, xml within the hour is split into multiple copies to be saved. For example, coverage information of 10:00 to 11:00 is divided into cover_2021091410_1.Xml and cover_2021091410_2.Xml by replacing version 1 time (10:25 minutes).
Then, a plurality of xml files are sorted from old to new in time, file1, file2, file3.. Filen, and File1, file2, file3.. Filen-1 are sequentially incorporated into Filen based on the latest xml File Filen.
Taking File1 and Filen as an example, the specific process of combining the existing function a is as follows:
Resolving File1 to obtain unique signature KEYa1 coverage details COVa1 of the function
In parsing Filen, a unique signature KEYan coverage detail COVan of the function is obtained
If KEYa1 is equal to KEYan, it is stated that the method has not modified the code and the overlay details COVa and COVan can be combined directly, whereas if the method has been modified, it is necessary to discard COVa and only the overlay details of COVan are kept.
Further, for the detailed merging process of overlay details COVa and COVan, essentially the union of the code lines that both overlay. The aggregate coverage is an intermediate in the process of calculating the demand coverage.
And 4, calculating the coverage rate of the demand according to the code influence range of the demand.
The embodiment of the invention is provided with a switch, when a demand is deployed for the first time, the switch is triggered to accumulate coverage rate during testing, and when the state of the demand is set into a put-into-service state by an upstream system, the switch is closed to stop accumulation. The resulting coverage is thus accumulated as the accumulated coverage COV [ accumulate ] during the demand test.
The calculation process of the demand coverage rate is a process of screening the function contained in the accumulated coverage rate COV (accumulate) by utilizing the demand corresponding change function set DF [ function ].
From this, the demand coverage can be increased or decreased in two cases:
Under this demand, developers have submitted new code, causing the function to change (add or modify), resulting in the coverage of the function being emptied, which effect reduces the demand coverage.
With new tests covering the change function code involved in the demand, this effect will increase the demand coverage.
FIG. 3 is a flow chart of a proposed code analysis according to an embodiment of the present invention, as shown in FIG. 3, the proposed code analysis flow includes:
Step S301, a test notification sent by an automated pipeline (CI/CD platform) is received and processed.
When the interface device receives the code version test notification sent by the automatic pipeline (CI/CD platform), the test record of the code version is written into the data storage device, wherein the test record comprises a tested software application identifier, a test version number, a test requirement number and a version test time.
The interface device then sends a version update instruction to the code analysis device, the instruction comprising the software application identifier under test, the test version number, the test requirement number, the test branch, and the remote code repository address.
Step S302, updating a local code warehouse.
After the code analysis device receives the version updating instruction, the code updating module can pull the latest code from the test branch of the remote code warehouse and download and update the latest code to the local code warehouse.
After the updating is completed, the code updating module calls a code comparison module, and the parameters comprise the tested software application identifier, the tested version number, the tested requirement number and the test branch.
In step S303, a version code comparison is proposed.
After the calling code comparison module receives the calling request, the subsequent processing is executed, and the method is divided into two sub-steps.
First, the difference between the proposed version (Vn) and the previous version (Vn-1) is calculated.
First, the version comparison tool (jgitdiff) is used to compare the extracted version (Vn) of the local warehouse with the previous version (Vn-1) to obtain the line number set DL line of the difference. Then, the java code of the extracted version (Vn) is parsed by using an Abstract Syntax Tree (AST), and a function set F [ function ] is identified. And screening the function set F [ function ] according to the change line number set DL [ line ] to obtain a change function set DF [ function ].
And secondly, merging the obtained difference with the history record in the demand code change table.
And querying the change records with the inserted histories from a demand code change table by using the tested software application identification and the demand number as conditions to obtain a history change line number set HDL [ line ] and a history change function set HDF [ function ] of the demand, wherein if the demand is the first test, the HDL [ line ] and the HDF [ function ] are empty sets.
Traversing the elements in the DL [ line ] set one by one, if the elements exist in the HDL [ line ] set, not processing, and if the elements do not exist, adding the elements into the HDL [ line ] set.
Similarly, traversing elements in the DF function set one by one, if the elements exist in the HDF function set, not processing the elements, and if the elements do not exist, adding the elements into the HDF function set.
And updating the historical change line number set HDL [ line ] and the historical change function set HDF [ function ] set to the demand code change table.
FIG. 4 is a flow chart of coverage acquisition and merging according to an embodiment of the present invention, as shown in FIG. 4, the coverage acquisition and merging flow includes:
Step S401, receiving and processing deployment notification sent by an automation pipeline (CI/CD platform).
When the interface device receives a code version deployment notification sent by an automation pipeline (CI/CD platform), the interface device writes a deployment record of the code version into the data storage device, wherein the deployment record comprises a tested software application identifier, a tested version number, a tested requirement number, a tested application ip, a deployment package path and version deployment time.
And then the interface device sends a deployment package pulling instruction to the proxy device according to the tested application ip, wherein the instruction comprises a tested software application identifier, a deployment version number, a deployment requirement number, a test branch and a deployment package path.
Step S402, pull the latest deployment package of the tested software.
After receiving the deployment package pulling instruction, the proxy device can find the latest deployment package (containing javaclass after compiling) of the tested software according to the deployment package path because the proxy device and the tested software are in the same server, and then upload the deployment package to the file storage device of the embodiment of the invention, wherein the communication modes used for uploading include, but are not limited to, FTP, SFTP, SCP and the like.
After the deployment package pulling is completed, if the requirement is the first deployment, the state of the requirement is activated to be effective, and the requirement is written into the data storage device.
Specifically, when the code of the demand is put into production, the demand manager will set the status of the demand as invalid, which means that the testing period of the demand is ended.
Step S403, collecting coverage rate information from the tested software at fixed frequency.
The timing task device will communicate with the instrumentation device of the tested software with a certain frequency (such as 1 time per hour), pull coverage information (jacoco dump native instructions) and generate exec file. And then converting (jacoco report native instructions) the exec file by using the deployment package file (comprising the compiled java class) obtained in the previous step, and obtaining the xml file after conversion. File save forms such as:
/(tested software application identification }/coverage-YYYYMMDDHH _ { subscript }. Xml
Typically, coverage information of 1 hour will be saved as a single xml. For example, coverage information of 9:00 to 10:00 is stored as cover_2021091409_1.Xml.
Specifically, when a version change occurs, xml within the hour is split into multiple copies to be saved. For example, coverage information of 10:00 to 11:00 is divided into cover_2021091410_1.Xml and cover_2021091410_2.Xml by replacing version 1 time (10:25 minutes).
Step S404, counting and accumulating coverage rate for each requirement, and generating xml.
Since the start and end times of each demand test period are different, the cumulative coverage of each demand needs to be individually accumulated. The merging module of the timing task device processes the following requirements of all the effective tested software:
The xml files collected by the previous collection module every hour are ordered according to time from old to new every day, file1, file2, file3.. Filen, and File1, file2, file3.. Filen-1 are sequentially combined into Filen based on the latest xml File Filen.
Taking function a as an example, the specific process of merging File1 and Filen is as follows:
Resolving File1 to obtain unique signature KEYa1 coverage details COVa1 of the function
In parsing Filen, a unique signature KEYan coverage detail COVan of the function is obtained
If KEYa1 is equal to KEYan, it is stated that the method has not modified the code and the overlay details COVa and COVan can be combined directly, whereas if the method has been modified, it is necessary to discard COVa and only the overlay details of COVan are kept.
Further, for the detailed merging process of overlay details COVa and COVan, FIG. 5 is a schematic diagram of the merging process of overlay details COVa1 and COVan according to an embodiment of the present invention, as shown in FIG. 5, essentially taking the union of the code lines covered by both.
And finally, the integrated result is written into an integrated coverage rate file corresponding to the requirement.
File save forms such as:
/(software application identification under test }/requiment/cov _ { Requirements number }. Xml
FIG. 6 is a flow chart of a demand coverage query in accordance with an embodiment of the present invention, as shown in FIG. 6, the demand coverage query flow includes:
In step S601, the user initiates a demand coverage query from the front-end page.
And selecting the requirement number of the tested software on the page by the tester for inquiring. The front-end page can initiate a query request to the coverage rate device, and the request parameters comprise a tested software identifier and a demand number.
In step S602, the back end calculates the coverage rate of the demand and returns the result.
And after receiving the query request, the coverage rate device reads the accumulated coverage rate file corresponding to the requirement to obtain the accumulated coverage rate detail COV [ accumulate ] of the requirement.
The set of change functions DF [ function ] corresponding to the demand is then queried from the data store.
In principle, the calculation process of the demand coverage rate is described, namely, the process of screening the function contained in the accumulated coverage rate COV [ accumulate ] by utilizing the demand corresponding change function set DF [ function ]. If the function exists in DF function, the function is reserved, otherwise the coverage rate of the function is eliminated.
After the screening is completed, the coverage information of each function is summarized according to the formula of sigma (the number of lines covered by the change function under test)/sigma (the total number of lines of the change function), and the required coverage is obtained.
After the calculation is completed, the demand coverage Cov (requiment) (containing detailed coverage information and summary values for each row) is converted into json and returned to the front end.
Step S603, the user checks the code dyeing condition.
And selecting a single java source code file on the page by the tester for inquiring. The front-end page can initiate a code viewing request to the code analysis device, and the request parameters comprise a demand number, a tested code branch, a code version and a code full path.
In step S604, the backend downloads the specified code.
After the code analysis device receives the query request, the code downloading module downloads codes of a single source code file according to the tested code branches, the code version and the code full path, and returns the source code content to the front-end page.
In step S605, the front page dyes the source code.
After the front-end page receives the source code content, corresponding line coverage information is found out from json requiring coverage rate according to the code file name to be dyed, the source code is rendered line by line according to the line number, the covered line can be rendered green, uncovered content is rendered red, and finally the dyed source code content is displayed on an interface (not shown in the figure).
The embodiment of the invention has strong coverage rate cross-version merging capability. The result of each round of test of the tester can be accumulated, rather than being cleared directly. Even with the characteristic, after the tester completes multiple rounds of testing on the software, any time period can be selected, and the sum of the accumulated test coverage rates of multiple versions in the time period can be queried. So that a tester can pay attention to codes which are not actually tested in a limited time, thereby improving the overall efficiency of the test.
The embodiment of the invention also provides a query function of the demand coverage rate, so that a tester can gather a specific demand change code instead of checking a stack of coverage rate statistical results without difference. Therefore, a tester can pay attention to codes which are more required to be tested in a limited time, and the testing efficiency is improved.
According to another embodiment of the present invention, there is also provided a code coverage determining apparatus, fig. 7 is a block diagram of the code coverage determining apparatus according to an embodiment of the present invention, as shown in fig. 7, including:
a query module 72, configured to query the associated plurality of code versions according to requirements of the software under test;
A first determination module 74 for determining a code impact range for the code to which the demand relates;
an accumulating module 76, configured to accumulate coverage rates of the plurality of code versions to obtain an accumulated coverage rate of the requirement;
And a second determining module 78, configured to determine the coverage rate of the tested code according to the code influence range and the cumulative coverage rate.
Optionally, the apparatus further comprises:
And the dyeing module is used for dyeing the codes covered by the tested software according to the code influence range of the requirement.
Optionally, the first determining module 74 includes:
the comparison sub-module is used for comparing the java codes of the initial version and the current version in the plurality of code versions related to the requirements by utilizing a version comparison tool to obtain a change line number set DL [ line ] of the codes, and storing the change line number set DL [ line ] into a storage medium;
The analysis submodule is used for analyzing the java code of the current version by utilizing an abstract syntax tree AST and identifying a function set F [ function ];
And the screening submodule is used for screening the function set F [ function ] according to the change line number set DL [ line ] to obtain a change function set DF [ function ] of the requirement, wherein the code influence range is the change function set DF [ function ].
Optionally, the second determining module 78 is further configured to:
and screening the accumulated coverage rate by using the changed function set DF [ function ] to obtain the required coverage rate.
Optionally, the accumulating module includes:
The instrumentation sub-module is used for instrumentation of a single application program of the tested software by using a code coverage rate tool jacoco, collecting coverage rate information of the plurality of code versions at fixed frequency and storing the coverage rate information in a storage medium in an xml file format;
An acquisition sub-module for acquiring a plurality of XML files from the storage medium;
The sequencing sub-module is used for sequencing the XML files according to the time sequence to obtain File 1, file 2, file 3, the.
The merging sub-module is used for merging File1, file 2, file 3, and File n-1 into File n in sequence by taking the latest Filen as a reference to obtain a merging result;
and determining the accumulated coverage rate according to the merging result.
Optionally, the merging sub-module is further configured to:
The following steps are performed on each of the File 1, file 2, file 3,..once the merging of the File 1, file 2, file 3,..once, file n-1 into the File n is completed, the merging result is obtained, wherein the current File is the one being executed:
The current File is subjected to coverage details COVa of the unique signature KEYa of the function;
analyzing Filen to obtain coverage details COVan of the unique signature KEYan of the function;
If KEYa corresponding to the current File is equal to KEYan, merging the coverage details COVa corresponding to the current File and the coverage details COVa n corresponding to Filen;
if KEYa corresponding to the current File is not equal to KEYan, discarding the coverage details COVa corresponding to the current File, and only reserving the coverage details COVa n corresponding to the File n.
It should be noted that each of the above modules may be implemented by software or hardware, and the latter may be implemented by, but not limited to, the above modules all being located in the same processor, or each of the above modules being located in different processors in any combination.
Embodiments of the present invention also provide a computer readable storage medium having a computer program stored therein, wherein the computer program is arranged to perform the steps of any of the method embodiments described above when run.
Alternatively, in the present embodiment, the above-described storage medium may be configured to store a computer program for performing the steps of:
S1, inquiring a plurality of associated code versions according to the requirements of tested software;
s2, determining a code influence range of codes related to the requirements;
S3, accumulating the coverage rates of the code versions to obtain the accumulated coverage rate of the requirement;
S4, determining the coverage rate of the tested codes according to the code influence range and the accumulated coverage rate.
Alternatively, in the present embodiment, the storage medium may include, but is not limited to, a USB flash disk, a Read-Only Memory (ROM), a random access Memory (Random Access Memory, RAM), a removable hard disk, a magnetic disk, or an optical disk, etc. various media in which a computer program may be stored.
An embodiment of the invention also provides an electronic device comprising a memory having stored therein a computer program and a processor arranged to run the computer program to perform the steps of any of the method embodiments described above.
Optionally, the electronic apparatus may further include a transmission device and an input/output device, where the transmission device is connected to the processor, and the input/output device is connected to the processor.
Alternatively, in the present embodiment, the above-described processor may be configured to execute the following steps by a computer program:
S1, inquiring a plurality of associated code versions according to the requirements of tested software;
s2, determining a code influence range of codes related to the requirements;
S3, accumulating the coverage rates of the code versions to obtain the accumulated coverage rate of the requirement;
S4, determining the coverage rate of the tested codes according to the code influence range and the accumulated coverage rate.
Alternatively, specific examples in this embodiment may refer to examples described in the foregoing embodiments and optional implementations, and this embodiment is not described herein.
It will be appreciated by those skilled in the art that the modules or steps of the invention described above may be implemented in a general purpose computing device, they may be concentrated on a single computing device, or distributed across a network of computing devices, they may alternatively be implemented in program code executable by computing devices, so that they may be stored in a memory device for execution by computing devices, and in some cases, the steps shown or described may be performed in a different order than that shown or described, or they may be separately fabricated into individual integrated circuit modules, or multiple modules or steps within them may be fabricated into a single integrated circuit module for implementation. Thus, the present invention is not limited to any specific combination of hardware and software.
The above description is only of the preferred embodiments of the present invention and is not intended to limit the present invention, but various modifications and variations can be made to the present invention by those skilled in the art. Any modification, equivalent replacement, improvement, etc. made within the principle of the present invention should be included in the protection scope of the present invention.

Claims (8)

1. A code coverage rate determination method, comprising:
Inquiring a plurality of associated code versions according to the requirements of the tested software;
The method comprises the steps of comparing the java codes of an initial version and a current version in a plurality of code versions related to the requirements by utilizing a version comparison tool to obtain a change line number set DL [ line ] of the codes, storing the change line number set DL [ line ] of the codes in a storage medium, analyzing the java codes of the current version by utilizing an abstract syntax tree AST to identify a function set F [ function ];
accumulating the coverage rates of the plurality of code versions to obtain the accumulated coverage rate of the requirement;
The method comprises the steps of screening the accumulated coverage by utilizing a change function set DF [ function ], and summarizing coverage information of each function according to a formula sigma (the number of lines covered by a change function to be tested)/sigma (the total number of lines of the change function) after screening is completed to obtain the required coverage.
2. The method of claim 1, wherein after determining the coverage of the code under test from the code coverage and the cumulative coverage, the method further comprises:
And according to the code influence range of the requirement, dyeing the code covered by the tested software.
3. The method of any of claims 1-2, wherein accumulating coverage of the plurality of code versions to obtain an accumulated coverage of the demand comprises:
Inserting a single application program of the tested software by using a code coverage rate tool jacoco, collecting coverage rate information of the plurality of code versions at fixed frequency, and storing the coverage rate information in a storage medium in an xml file format;
acquiring a plurality of XML files from a storage medium;
Sequencing the plurality of XML files according to the time sequence to obtain File 1, file 2, file 3, & gt, file n;
Sequentially merging File 1, file 2, file 3, and File n-1 into the File n with the latest File n as a reference to obtain a merging result;
and determining the accumulated coverage rate according to the merging result.
4. A method according to claim 3, wherein combining File 1, file 2, file 3, and File n-1 into the File n in order, taking the latest File n as a reference, to obtain a combined result includes:
The following steps are performed on each of the File 1, file 2, file 3,..once the merging of the File 1, file 2, file 3,..once, file n-1 into the File n is completed, the merging result is obtained, wherein the current File is the one being executed:
The current File is subjected to coverage details COVa of the unique signature KEYa of the function;
Analyzing the File n to obtain coverage details COVa n of the unique signature KEYan of the function;
If KEYa corresponding to the current File is equal to KEYan, merging the coverage details COVa corresponding to the current File and the coverage details COVa n corresponding to the File n;
if KEYa corresponding to the current File is not equal to KEYan, discarding the coverage details COVa corresponding to the current File, and only reserving the coverage details COVa n corresponding to the File n.
5. A code coverage rate determination apparatus, comprising:
the query module is used for querying a plurality of associated code versions according to the requirements of the tested software;
The first determining module is used for determining a code influence range of codes related to the requirements, and comprises the steps of comparing the java codes of an initial version and a current version in a plurality of code versions related to the requirements by using a version comparison tool to obtain a change line number set DL [ line ] of the codes, and storing the change line number set DL [ line ] of the codes in a storage medium;
The accumulation module is used for accumulating the coverage rates of the plurality of code versions to obtain the accumulated coverage rate of the requirement;
And the second determining module is used for determining the required coverage rate of the tested code according to the code influence range and the accumulated coverage rate, and comprises the step of screening the accumulated coverage rate by utilizing the change function set DF [ function ] to obtain the required coverage rate.
6. The apparatus of claim 5, wherein the apparatus further comprises:
And the dyeing module is used for dyeing the codes covered by the tested software according to the code influence range of the requirement.
7. A computer-readable storage medium, characterized in that the storage medium has stored therein a computer program, wherein the computer program is arranged to execute the method of any of the claims 1 to 4 when run.
8. An electronic device comprising a memory and a processor, characterized in that the memory has stored therein a computer program, the processor being arranged to run the computer program to perform the method of any of the claims 1 to 4.
CN202210014181.8A 2022-01-06 2022-01-06 Code coverage rate determining method and device Active CN114416546B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210014181.8A CN114416546B (en) 2022-01-06 2022-01-06 Code coverage rate determining method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210014181.8A CN114416546B (en) 2022-01-06 2022-01-06 Code coverage rate determining method and device

Publications (2)

Publication Number Publication Date
CN114416546A CN114416546A (en) 2022-04-29
CN114416546B true CN114416546B (en) 2025-08-05

Family

ID=81272065

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210014181.8A Active CN114416546B (en) 2022-01-06 2022-01-06 Code coverage rate determining method and device

Country Status (1)

Country Link
CN (1) CN114416546B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115309640A (en) * 2022-08-03 2022-11-08 平安银行股份有限公司 Test case code location method and system based on requirements management
CN116303106A (en) * 2023-05-26 2023-06-23 江苏博云科技股份有限公司 A GitFlow-based software version rapid rollback method and system applicable to the financial industry

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109002395A (en) * 2018-07-06 2018-12-14 北京京东金融科技控股有限公司 A kind of code coverage management method and device
CN110413532A (en) * 2019-08-08 2019-11-05 上海新炬网络技术有限公司 More process version change code coverage acquisition methods suitable for agility test
CN110727602A (en) * 2019-10-23 2020-01-24 网易(杭州)网络有限公司 Coverage rate data processing method and device and storage medium

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR101667262B1 (en) * 2014-08-18 2016-10-19 슈어소프트테크주식회사 Method for measuring code coverage and computer readable recording medium having program the same
CN108829580B (en) * 2018-05-07 2022-09-23 百度在线网络技术(北京)有限公司 Multi-version test data processing method, device, equipment and storage medium
CN109388566B (en) * 2018-09-27 2022-07-29 北京城市网邻信息技术有限公司 Code coverage rate analysis method, device, equipment and storage medium
CN111831549B (en) * 2020-06-04 2023-04-14 深圳手回科技集团有限公司 Incremental code coverage determination method, device, equipment and storage medium
CN112181812A (en) * 2020-09-16 2021-01-05 北京三快在线科技有限公司 Version testing method and device

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109002395A (en) * 2018-07-06 2018-12-14 北京京东金融科技控股有限公司 A kind of code coverage management method and device
CN110413532A (en) * 2019-08-08 2019-11-05 上海新炬网络技术有限公司 More process version change code coverage acquisition methods suitable for agility test
CN110727602A (en) * 2019-10-23 2020-01-24 网易(杭州)网络有限公司 Coverage rate data processing method and device and storage medium

Also Published As

Publication number Publication date
CN114416546A (en) 2022-04-29

Similar Documents

Publication Publication Date Title
US11775416B2 (en) System and method for continuous testing and delivery of software
US8180762B2 (en) Database tuning methods
KR100990777B1 (en) How to Collect Debug Information and Debug Information Collection System
CN114416546B (en) Code coverage rate determining method and device
US11385898B2 (en) Task orchestration method for data processing, orchestrator, device and readable storage medium
CN111158741B (en) Method and device for monitoring dependency relationship change of service module on third party class library
CN113448854A (en) Regression testing method and device
CN111522728A (en) Method for generating automatic test case, electronic device and readable storage medium
CN110134583A (en) Software test and data processing method and device
CN115630857A (en) Research and development quality evaluation method, device, equipment and medium
CN110503297B (en) Service scene acquisition method and device, electronic equipment and medium
CN113515546B (en) Data processing method, device and server
CN113721950A (en) Resource loss prevention and control processing method and device
KR101039874B1 (en) Information Communication Integrated Platform Test System
CN110825609B (en) Service testing method, device and system
CN117743148A (en) Interface testing method and device, storage medium and electronic device
CN115587048A (en) Regression testing method, terminal device and computer readable storage medium
CN115576831A (en) Test case recommendation method, device, equipment and storage medium
CN112346994B (en) A test information association method, device, computer equipment and storage medium
CN117785644A (en) Distributed service testing method and device, electronic equipment and storage medium
CN114218073A (en) Interface testing method, device, server and medium
CN110781161B (en) Service data processing method and device
CN117421245A (en) Test method and device suitable for changing tested program
CN119782133A (en) Test task processing method, device and electronic equipment
CN118796845A (en) Data consistency analysis method, device, equipment and storage 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
GR01 Patent grant
GR01 Patent grant