Code coverage rate statistical method and device

By embedding monitoring code into the software under test and using online traffic to obtain code execution information, the problem of low accuracy and reliability of code coverage in existing technologies is solved. This achieves accurate statistics of full code coverage and logical branch coverage, thus improving efficiency.

CN120994533APending Publication Date: 2025-11-21BEIJING WODONG TIANJUN INFORMATION TECH CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410606791.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-05-15
Publication Date
2025-11-21

AI Technical Summary

Technical Problem

现有的代码覆盖率统计方法依赖于测试用例,导致覆盖率的准确性和可靠性较低,且统计单元局限于方法代码级别,效率低下。

Method used

By embedding monitoring code into the software under test, the code is executed using real online traffic, and the execution status of each component code is obtained. The statistical unit is extended to the entire software code, including the coverage statistics of logical branches.

Benefits of technology

It achieves reliable and accurate code coverage statistics, ensuring the authenticity and accuracy of the results, eliminating the need for test cases, improving statistical efficiency, and being able to count the coverage of line code and logical branches.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120994533A_ABST
    Figure CN120994533A_ABST
Patent Text Reader

Abstract

The invention discloses a code coverage rate statistical method and device, and relates to the technical field of computers. A specific embodiment of the method comprises the following steps: in response to a received software code coverage rate statistical request, implanting a monitoring code into a code of to-be-tested software; obtaining pre-recorded online traffic of the to-be-tested software, performing analysis processing on the online traffic, and starting and executing a code of the to-be-tested software according to an analysis processing result; and obtaining the code execution condition of each component code of the to-be-tested software through the monitoring code, and obtaining the code coverage rate of the to-be-tested software according to the obtained code execution condition. According to the implementation mode, the code coverage rate is reliably and accurately counted, the code of the to-be-tested software is started and executed by using the real online flow, the accuracy and authenticity of the statistical result are ensured, a test case is omitted, and the statistical efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer technology, and in particular to a statistical method and apparatus for code coverage. Background Technology

[0002] Code coverage is an important indicator for measuring software quality. Coverage is calculated based on the number of executed lines of code and the number of unexecuted lines of code in the software code. Generally, existing code coverage statistics tools are used in conjunction with test cases to perform method code-level unit tests on the software code under test to obtain code coverage.

[0003] In the process of realizing this invention, the inventors discovered the following problems in the prior art:

[0004] Existing methods for calculating code coverage mainly rely on test cases, but test case coverage and reliability are low, and cannot guarantee the accuracy and reliability of code coverage. Summary of the Invention

[0005] In view of this, embodiments of the present invention provide a method and apparatus for statistical code coverage, which achieves reliable and accurate statistical code coverage. It uses real online traffic to start and execute the code of the software under test, and extends the statistical unit from method code to the entire software code. This not only ensures the accuracy, authenticity and reliability of the statistical results, but also eliminates test cases and improves statistical efficiency.

[0006] To achieve the aforementioned objective, according to one aspect of the present invention, a method for statistically analyzing code coverage is provided, comprising:

[0007] In response to receiving a software code coverage statistics request, listener code is injected into the code of the software under test.

[0008] The system acquires pre-recorded online traffic of the software under test, parses and processes the online traffic, and executes the code of the software under test based on the parsing and processing results.

[0009] The monitoring code obtains the code execution status of each component code of the software under test, and the code coverage of the software under test is obtained based on the obtained code execution status.

[0010] Optionally, embedding monitoring code into the code of the software under test includes: performing bytecode enhancement on each line of code of the software under test to generate software under test with embedded probe code, wherein the monitoring code includes the probe code.

[0011] Optionally, before acquiring the pre-recorded online traffic of the software under test, the method further includes: acquiring the online requests of the online software corresponding to the software under test, as well as the input parameters and return values ​​corresponding to the online requests; and saving the online requests, as well as the input parameters and return values ​​corresponding to the online requests, as the online traffic of the software under test.

[0012] Optionally, obtaining the online requests of the online software corresponding to the software under test, as well as the input parameters and return values ​​of the online requests, includes: performing bytecode enhancement on the online software corresponding to the software under test to generate online software with surround events; and capturing the input parameters and return values ​​of the online software when executing online requests through the surround events.

[0013] Optionally, the online traffic is parsed and processed. Based on the parsing result, the code of the software under test is executed. This includes: parsing the online traffic to obtain the recorded startup parameters of the online software corresponding to the software under test, as well as the input parameters and return values ​​of each interface code in the online software; performing bytecode enhancement on the external interaction interface code in the software under test based on the input parameters and return values ​​of each interface code in the online software to generate the software under test with independent execution capability; and using the startup parameters to trigger the execution of the code of the software under test with independent execution capability.

[0014] Optionally, the monitoring code can be used to obtain the code execution status of each component code of the software under test, including: monitoring the reporting information of the monitoring code, wherein the monitoring code has execution reporting code deployed in it so that the execution information of the monitoring code is reported when the monitoring code is executed; parsing the received execution information reported by the monitoring code to obtain the line information of the executed code in each component code of the software under test, the logical branch to which the executed code belongs, and the online request corresponding to the executed code.

[0015] Optionally, the code coverage of the software under test is obtained based on the obtained execution status of each code, including: based on the obtained line information of the executed code in each component code, the logical branch to which the executed code belongs, and the online request corresponding to the executed code, the line information of the executed code and the logical branch to which it belongs are counted for each online request; based on the line information of the executed code and the logical branch to which it belongs for each online request, at least one of the line code coverage and the logical branch code coverage of the software under test is calculated.

[0016] Optionally, before saving the online request, along with its corresponding input parameters and return values, as the online traffic of the software under test, the method further includes: serializing the input parameters and return values ​​corresponding to the online request; saving the online request, along with its corresponding input parameters and return values, as the online traffic of the software under test includes: saving the online request, along with its corresponding serialized input parameters and return values, as the online traffic of the software under test; before parsing the online traffic, the method further includes: deserializing the input parameters and return values ​​in the online traffic.

[0017] According to a second aspect of the present invention, a code coverage statistics apparatus is provided, comprising:

[0018] The monitoring code injection module is used to inject monitoring code into the code of the software under test in response to receiving a software code coverage statistics request.

[0019] The software code execution module is used to acquire pre-recorded online traffic of the software under test, parse and process the online traffic, and start executing the code of the software under test based on the parsing and processing results.

[0020] The coverage determination module is used to obtain the code execution status of each component code of the software under test through the monitoring code, and to obtain the code coverage of the software under test based on the obtained code execution status.

[0021] According to a third aspect of the present invention, an electronic device for code coverage is provided, comprising:

[0022] One or more processors;

[0023] Storage device for storing one or more programs.

[0024] When the one or more programs are executed by the one or more processors, the one or more processors implement the method provided in the first aspect of the embodiments of the present invention.

[0025] According to a fourth aspect of the present invention, a computer-readable medium is provided having a computer program stored thereon, which, when executed by a processor, implements the method provided in the first aspect of the present invention.

[0026] One embodiment of the invention has the following advantages or beneficial effects: by responding to a received software code coverage statistics request, listening code is injected into the code of the software under test; pre-recorded online traffic of the software under test is acquired, the online traffic is parsed and processed, and the code of the software under test is started and executed based on the parsing and processing results; by listening to the code execution status of each component code of the software under test through the listening code, the code coverage of the software under test is obtained based on the acquired execution status of each code, thus realizing a reliable and accurate code coverage statistics method. It uses real online traffic to start and execute the code of the software under test, extending the statistical unit from method code to the entire software code, which not only ensures the accuracy and authenticity of the statistical results but also eliminates the need for test cases and improves statistical efficiency. Attached Figure Description

[0027] The accompanying drawings are provided to better understand the invention and are not intended to unduly limit the scope of the invention. Wherein:

[0028] Figure 1 This is a schematic diagram of the main flow of the code coverage statistical method according to an embodiment of the present invention;

[0029] Figure 2 This is a statistical diagram illustrating the line code coverage and logical branch code coverage of an embodiment of the present invention;

[0030] Figure 3 This is a schematic diagram illustrating the principle of the code coverage statistical method according to an embodiment of the present invention;

[0031] Figure 4 This is a schematic diagram of the main modules of a code coverage statistics device according to an embodiment of the present invention;

[0032] Figure 5 This is an exemplary system architecture diagram in which embodiments of the present invention can be applied;

[0033] Figure 6 This is a schematic diagram of the structure of a computer system suitable for implementing terminal devices or servers of the present invention. Detailed Implementation

[0034] It should be noted that the acquisition, storage, and application of user personal information involved in the technical solution disclosed herein comply with the provisions of relevant laws and regulations and do not violate public order and good morals.

[0035] The following description, in conjunction with the accompanying drawings, illustrates exemplary embodiments of the present invention, including various details to aid understanding. These details should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the invention. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.

[0036] Existing methods for calculating code coverage using test cases rely heavily on the quality of those test cases to determine the accuracy of the coverage. If test cases are poorly designed and ignore boundary cases, those boundary cases may never be executed. Furthermore, the code coverage obtained through test cases cannot guarantee its accuracy, as there may be test cases designed to artificially inflate the coverage figure. Moreover, the statistical unit for coverage is limited to the method code level, resulting in low efficiency in calculating the coverage of the entire software code and failing to adequately meet the needs of practical applications.

[0037] To address the aforementioned problems in existing technologies, this invention proposes a code coverage statistical method. This method acquires pre-recorded online traffic of the software under test (SDT), uses this online traffic to initiate and execute the SDT's code, and then obtains the SDT's code coverage through listening code embedded within the SDT's code. This achieves a reliable and accurate code coverage statistical method, using real online traffic to initiate and execute the SDT's code. It expands the statistical unit from method code to the entire software code, ensuring not only the accuracy and authenticity of the statistical results but also eliminating the need for test cases and improving statistical efficiency.

[0038] In the description of the embodiments of the present invention, the terms involved and their meanings are as follows:

[0039] Java Agent: One of the extension mechanisms of the Java Virtual Machine, which allows developers to dynamically modify or enhance the behavior of Java applications at runtime.

[0040] Figure 1 This is a schematic diagram of the main flow of the code coverage statistical method according to an embodiment of the present invention, as shown below. Figure 1 As shown, the code coverage statistical method of this embodiment includes the following steps S101 to S103.

[0041] Step S101: In response to receiving a software code coverage statistics request, inject monitoring code into the code of the software under test.

[0042] Specifically, the system receives a software code coverage statistics request. By parsing this request, it determines the software under test and the statistical scope of the code coverage. By default, it performs full code coverage statistics, but the statistical scope can also be specified, such as specifying certain interface code, code from a specific module, or a range of lines of code. Based on the statistical scope of the code coverage, monitoring code is inserted into the corresponding code locations in the software under test. This monitoring can be achieved through annotations or by adding reporting code with specified return values ​​to check whether the monitoring code has been executed.

[0043] According to one embodiment of the present invention, implanting monitoring code into the code of software under test includes: performing bytecode enhancement on each line of code of the software under test to generate software under test with implanted probe code, wherein the monitoring code includes the probe code.

[0044] Specifically, in this embodiment of the invention, the software under test is connected to a perceptron plugin that uses Java Agent bytecode enhancement technology. After the perceptron plugin is connected to the software under test, the perceptron plugin uses bytecode enhancement technology to enhance the bytecode of each line of code in the software under test, automatically modifying the bytecode of each line of code and implanting a probe into each line of code.

[0045] For example, for the code snippet:

[0046]

[0047] The code after the probe is injected with bytecode enhancement is shown below. The probe is the code injected with bytecode enhancement. You can see that the probe will report which line of code has been executed without affecting the code execution logic.

[0048]

[0049] The method of enhancing each line of code in the software under test using the embodiments of the present invention to generate software under test with implanted probe code can conveniently, quickly and accurately implant monitoring code into each line of code in the software under test.

[0050] Step S102: Obtain the pre-recorded online traffic of the software under test, parse and process the online traffic, and start executing the code of the software under test based on the parsing and processing results.

[0051] Specifically, based on the software under test (SUBST) identified above, pre-recorded online traffic corresponding to the SUBST is retrieved from a designated storage space. In this embodiment of the invention, the online traffic originates from online software deployed in an online environment that uses the same code as the SUBST. The online traffic records the interaction data generated between the online software and the server each time the online software receives an online business request in the real online environment. After obtaining the recorded online traffic, it is parsed and replayed. The parsed results are used to provide the conditions for the SUBST to start execution, enabling the use of online traffic to start and execute the SUBST's code.

[0052] According to an embodiment of the present invention, before acquiring the pre-recorded online traffic of the software under test, the method further includes: acquiring the online requests of the online software corresponding to the software under test, as well as the input parameters and return values ​​corresponding to the online requests; and saving the online requests, as well as the input parameters and return values ​​corresponding to the online requests, as the online traffic of the software under test.

[0053] Specifically, before acquiring pre-recorded online traffic of the software under test, online requests from the corresponding online software can be obtained using network packet capture tools or proxy servers. These online requests, along with the input parameters and return values ​​that trigger the execution of corresponding business logic code by the online software, can be used. These online requests can be data exchanged between the client and server, such as page refresh requests. The acquired online requests, along with their corresponding input parameters and return values, are then recorded and saved as online traffic of the software under test to a designated storage space on the server. This allows the software under test to subsequently retrieve the recorded online traffic from the server.

[0054] According to another embodiment of the present invention, obtaining the online request of the online software corresponding to the software under test, as well as the input parameters and return values ​​corresponding to the online request, includes: performing bytecode enhancement on the online software corresponding to the software under test to generate online software with surround events; and capturing the input parameters and return values ​​of the online software when executing the online request through the surround events.

[0055] Specifically, considering the large volume of online traffic data, to improve efficiency and reduce complexity, this embodiment of the invention connects the online software running the software under test in the online environment to a recorder plugin. This recorder plugin is mainly used to collect online traffic through Java Agent bytecode enhancement technology. When the online software is connected to the recorder plugin, the plugin uses Java Agent bytecode enhancement technology to enhance the bytecode of the online software corresponding to the software under test, modifying the bytecode of specified interfaces and related sub-calls, adding surround events to the online software, and generating online software with surround events. Surround events are a type of notification in aspect-oriented programming, mainly used for interception and control before and after the execution of the target method code, similar to the concept of an interceptor. By adding surround events to the online software, the input parameters and return values ​​of the interfaces / sub-calls used by the online software when executing online requests are intercepted and captured. Simultaneously, the recorder plugin generates a Trace ID for each online request, binding the corresponding input parameters and return values ​​to this Trace ID.

[0056] According to another embodiment of the present invention, before saving the online request, and the corresponding input parameters and return values ​​as the online traffic of the software under test, the method further includes: performing serialization processing on the input parameters and return values ​​corresponding to the online request; saving the online request, and the corresponding input parameters and return values ​​as the online traffic of the software under test includes: saving the online request, and the corresponding serialized input parameters and return values ​​as the online traffic of the software under test.

[0057] Specifically, the code of the software under test in this embodiment of the invention mainly uses the Java language. The input parameters and return values ​​corresponding to the obtained online requests are all objects. In order to save these objects, the input parameters and return values ​​need to be serialized and encoded for transmission and storage. Accordingly, in subsequent storage, the online requests, as well as the serialized input parameters and return values ​​corresponding to the online requests, are persistently saved as online traffic to the designated storage space on the server.

[0058] According to another embodiment of the present invention, the online traffic is parsed and processed, and the code of the software under test is executed based on the result of the parsing and processing. The process includes: parsing the online traffic to obtain the recorded startup parameters of the online software corresponding to the software under test, as well as the input parameters and return values ​​of each interface code in the online software; performing bytecode enhancement on the external interaction interface code in the software under test based on the input parameters and return values ​​of each interface code in the online software to generate the software under test with independent execution capability; and using the startup parameters to trigger the execution of the code of the software under test with independent execution capability.

[0059] Specifically, in addition to the sensor plugin, the software under test (SDT) also integrates a replay plugin responsible for parsing online traffic, which also utilizes Java Agent bytecode enhancement technology. After acquiring the online traffic of the SDT, the replay plugin parses the traffic to obtain the recorded startup parameters of the online software, as well as the input parameters and return values ​​of various interface codes during the execution of online requests. It then searches for interface codes in the SDT code that involve external interactions, selects the input parameters and return values ​​of the external interaction interface codes from the parsed input and return values, and simulates the corresponding external interaction interface code using a MOCK based on the selected input parameters and return values. Using Java Agent technology, bytecode enhancement is performed on the external interaction interface code in the SDT, modifying and rewriting the external interaction interface code to achieve the ability to obtain consistent interaction data with the online environment even without external interaction, thus enabling independent execution of the SDT code. For example, if an online request queries a database, but the software under test (SDP) lacks access to that database in the test environment, the DDP's code will fail to execute. However, based on the recorded input parameters and return values ​​of the database query request, the replay function uses Java Agent technology to rewrite the DDP's database query code to retrieve the corresponding recorded database data, allowing the DDP's code to execute normally. Finally, the startup parameters are used to trigger the rewritten DDP, enabling the execution of the DDP's code using recorded real online traffic.

[0060] According to another embodiment of the present invention, before parsing the online traffic, the method further includes: deserializing the input parameters and return values ​​in the online traffic.

[0061] Specifically, based on the serialization and storage of input parameters and return values ​​described above, before parsing the online traffic, it is also necessary to perform corresponding deserialization on the input parameters and return values ​​in the online traffic to facilitate subsequent parsing and playback.

[0062] Step S103: Obtain the code execution status of each component code of the software under test through the monitoring code, and obtain the code coverage of the software under test based on the obtained code execution status.

[0063] Specifically, after the code for starting and executing the software under test is executed, the actual execution status of each code is obtained through the listening code embedded in the code. Based on the execution status of each code, the number of lines of executed code and the number of lines of unexecuted code, or the total number of lines, are counted, and then the code coverage of the software under test is calculated.

[0064] According to one embodiment of the present invention, the code execution status of each component code of the software under test is obtained through the monitoring code, including: monitoring the reporting information of the monitoring code, wherein the monitoring code is deployed with execution reporting code so that the execution information of the monitoring code is reported when the monitoring code is executed; parsing the received execution information reported by the monitoring code to obtain the line information of the executed code in each component code of the software under test, the logical branch to which the executed code belongs, and the online request corresponding to the executed code.

[0065] Specifically, considering that the code under test usually contains logical branch code, such as the common if...else..., switch, etc., existing line coverage-based statistical methods can only count the execution status of each line of code, and cannot calculate the branch code coverage with logical relationships, such as the branch code coverage of a switch for different judgment results. This invention enhances each line of code with bytecode, embedding a probe into each line. The probe acts as a monitoring tool to detect whether each line of code is executed. When the code under test is executed, the corresponding probe is also executed, and the probe reports the relevant execution information of the corresponding code to the server, such as the line information of the code, the logical branch to which the code belongs, and the corresponding online request. The specific details of the execution information generation are as follows: When the software under test is started by replaying online traffic, the Trace ID of the online request is obtained. When a probe is executed, the probe retrieves the Trace ID from the context of the current thread, which is the online request corresponding to the currently executing code, and traces back to the logical branch to which the code belongs, encapsulating it along with the code line information to construct the execution information. Furthermore, according to the preset parsing specifications, all execution information of the received software under test is parsed to obtain the line information of the executed code in the software under test, the logical branch to which it belongs, and the corresponding online request.

[0066] According to another embodiment of the present invention, the code coverage of the software under test is obtained based on the acquired execution status of each code, including: based on the acquired line information of the executed code in each component code, the logical branch to which the executed code belongs, and the online request corresponding to the executed code, the line information of the executed code and the logical branch to which it belongs are counted for each online request; based on the line information of the executed code and the logical branch to which it belongs for each online request, at least one of the line code coverage and the logical branch code coverage of the software under test is calculated.

[0067] Specifically, based on the obtained line information of each executed code, its corresponding logical branch, and the online request Trace ID, the line information of the executed code and its corresponding logical branch for each online request Trace ID are calculated. Furthermore, based on the line information and logical branch of the executed code for each online request, the proportion of executed code lines for this online request Trace ID to the total number of code lines can be directly calculated, yielding the line code coverage. The branch coverage of a specified logical branch of the software under test within this online request Trace ID can also be calculated. For example, if online request A calls the logical branch `if` code segment: `if(true){code1}; else{code2};` and executes code 1, then the branch coverage of the logical branch for this online request is 50%.

[0068] Understandably, code coverage is typically a comprehensive statistic based on multiple online requests. For logical branch coverage, for example, in a total of 5 online requests, using the `if` logical branch as an example again, if 4 of them execute the code that checks the `true` condition and 1 executes the code that checks the `else` condition, then the final statistical result shows that the `if` logical branch has a 100% code coverage. Logical branch code coverage helps developers understand the actual execution of logical branch code, allowing for code optimization. For instance, if an `if` logical branch has been executed thousands or even more times in online requests, and its code coverage is still only 50%, meaning the `else` condition has never been executed, then the purpose of the `else` branch can be questioned.

[0069] Figure 2 This is a statistical diagram illustrating line code coverage and logical branch code coverage in an embodiment of the present invention. Pre-recorded online traffic of the software under test is acquired. By parsing and replaying the online traffic, the code of the software under test is executed. The diagram illustrates the relevant method code segments of the logical branches (if) in the software under test. Dark areas in the method code segments represent executed lines of code, and light areas represent unexecuted lines of code. Line code coverage can be calculated based on the executed and unexecuted lines of code in each method code segment. Solid arrows represent executed branch code, and dashed arrows represent unexecuted branch code. As shown in the diagram, the branch code coverage of the logical branch (if) is 50%, meaning the code corresponding to the true condition in the if statement is executed.

[0070] Figure 3This is a schematic diagram illustrating the principle of the code coverage statistics method according to an embodiment of the present invention. Upon receiving a software code coverage statistics request, a perceptron plugin is used to implant probes into the software under test. The online software corresponding to the software under test records and collects online traffic through an integrated recorder plugin, and stores the recorded online traffic on the server. The playback plugin of the software under test obtains the pre-recorded online traffic from the server, parses the online traffic through the playback plugin, and starts executing the code of the software under test. Then, through the probes implanted in the code of the software under test, the code execution status of each piece of code in the software under test is obtained, thus obtaining the code coverage of the software under test.

[0071] This invention treats online traffic as test cases, eliminating test cases that only aim to improve code coverage. It implements a reliable and accurate method for calculating code coverage by using real online traffic to start and execute the code of the software under test. The statistical unit is expanded from method code to the entire software code. This not only ensures the accuracy, authenticity, and reliability of the statistical results and improves statistical efficiency, but also allows for the calculation of logical branch code coverage based on the logical branches to which the code belongs in the obtained code execution information. This enables the calculation of line code coverage and logical branch code coverage of the software under test, better meeting actual needs.

[0072] Figure 4 This is a schematic diagram of the main modules of a code coverage statistics device according to an embodiment of the present invention. Figure 4 As shown, the code coverage statistics device 400 mainly includes a code implantation monitoring module 401, a software code execution module 402, and a coverage determination module 403.

[0073] The monitoring code injection module 401 is used to inject monitoring code into the code of the software under test in response to receiving a software code coverage statistics request.

[0074] The software code execution module 402 is used to acquire the pre-recorded online traffic of the software under test, parse and process the online traffic, and start executing the code of the software under test based on the result of the parsing and processing.

[0075] The coverage determination module 403 is used to obtain the code execution status of each component code of the software under test through the monitoring code, and to obtain the code coverage of the software under test based on the obtained code execution status.

[0076] According to one embodiment of the present invention, the monitoring code implantation module 401 is further configured to: perform bytecode enhancement on each line of code of the software under test to generate software under test with implanted probe code, wherein the monitoring code includes the probe code.

[0077] According to another embodiment of the present invention, the code coverage statistics device 400 further includes an online traffic recording module (not shown in the figure), which is used to: before acquiring the pre-recorded online traffic of the software under test, acquire the online requests of the online software corresponding to the software under test, as well as the input parameters and return values ​​corresponding to the online requests; and save the online requests, as well as the input parameters and return values ​​corresponding to the online requests, as the online traffic of the software under test.

[0078] According to another embodiment of the present invention, the online traffic recording module (not shown in the figure) is further configured to: perform bytecode enhancement on the online software corresponding to the software under test to generate online software with surround events; and capture the input parameters and return values ​​of the online software when executing online requests through the surround events.

[0079] According to another embodiment of the present invention, the software code execution module 402 is further configured to: parse the online traffic, obtain the recorded startup input parameters of the online software corresponding to the software under test, and the input parameters and return values ​​of each interface code in the online software; perform bytecode enhancement on the external interaction interface code in the software under test according to the input parameters and return values ​​of each interface code in the online software, and generate the software under test with independent execution capability; and use the startup input parameters to trigger the execution of the code of the software under test with independent execution capability.

[0080] According to another embodiment of the present invention, the coverage determination module 403 is further configured to: monitor the reporting information of the monitoring code, wherein the monitoring code is configured with execution reporting code so that the execution information of the monitoring code is reported when the monitoring code is executed; parse the received execution information reported by the monitoring code to obtain the line information of the executed code in each component code of the software under test, the logical branch to which the executed code belongs, and the online request corresponding to the executed code.

[0081] According to another embodiment of the present invention, the coverage determination module 403 is further configured to: based on the obtained line information of the executable code in each component code, the logical branch to which the executable code belongs, and the online request corresponding to the executable code, to count the line information of the executable code corresponding to each online request and the logical branch to which it belongs; and based on the line information of the executable code corresponding to each online request and the logical branch to which it belongs, to calculate at least one of the line code coverage and the logical branch code coverage of the software under test.

[0082] According to another embodiment of the present invention, the code coverage statistics device 400 further includes a serialization module (not shown in the figure), configured to: serialize the input parameters and return values ​​corresponding to the online request before saving the online request and the corresponding input parameters and return values ​​as online traffic of the software under test; the online traffic recording module (not shown in the figure) is further configured to: save the online request and the corresponding serialized input parameters and return values ​​as online traffic of the software under test; the code coverage statistics device 400 further includes a deserialization module (not shown in the figure), configured to: deserialize the input parameters and return values ​​in the online traffic before parsing the online traffic.

[0083] Figure 5 This is an exemplary system architecture diagram in which embodiments of the present invention can be applied.

[0084] like Figure 5 As shown, system architecture 500 may include terminal devices 501, 502, and 503, a network 504, and a server 505. Network 504 serves as the medium for providing communication links between terminal devices 501, 502, and 503 and server 505. Network 504 may include various connection types, such as wired or wireless communication links, or fiber optic cables, etc.

[0085] Users can use terminal devices 501, 502, and 503 to interact with server 505 via network 504 to receive or send messages, etc. Various communication client applications, such as code coverage statistics applications, can be installed on terminal devices 501, 502, and 503 (for example only).

[0086] Terminal devices 501, 502, and 503 can be various electronic devices with displays that support web browsing, including but not limited to smartphones, tablets, laptops, and desktop computers.

[0087] Server 505 can be a server providing various services, such as a backend management server supporting code coverage analysis performed by users using terminal devices 501, 502, and 503 (for example only). The backend management server can, in response to receiving a software code coverage statistics request, inject monitoring code into the code of the software under test; acquire pre-recorded online traffic of the software under test, parse and process the online traffic, and, based on the parsing results, start executing the code of the software under test; through the monitoring code, obtain the code execution status of each component code of the software under test, and, based on the obtained code execution status, obtain the code coverage of the software under test, and feed back the processing results (e.g., code coverage, etc.) to the terminal device.

[0088] It should be noted that the code coverage statistics method provided in this embodiment of the invention is generally executed by server 505, and correspondingly, the code coverage statistics device is generally set in server 505.

[0089] It should be understood that Figure 5 The number of terminal devices, networks, and servers shown is merely illustrative. Depending on implementation needs, any number of terminal devices, networks, and servers can be included.

[0090] The following is for reference. Figure 6 It shows a schematic diagram of the structure of a computer system suitable for implementing terminal devices or servers of the present invention. Figure 6 The terminal device or server shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of the present invention.

[0091] like Figure 6 As shown, the computer system 600 includes a central processing unit (CPU) 601, which can perform various appropriate actions and processes based on programs stored in read-only memory (ROM) 602 or programs loaded from storage section 608 into random access memory (RAM) 603. The RAM 603 also stores various programs and data required for the operation of the system 600. The CPU 601, ROM 602, and RAM 603 are interconnected via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.

[0092] The following components are connected to I / O interface 605: an input section 606 including a keyboard, mouse, etc.; an output section 607 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and speakers, etc.; a storage section 608 including a hard disk, etc.; and a communication section 609 including a network interface card such as a LAN card, modem, etc. The communication section 609 performs communication processing via a network such as the Internet. A drive 610 is also connected to I / O interface 605 as needed. A removable medium 611, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., is installed on drive 610 as needed so that computer programs read from it can be installed into storage section 608 as needed.

[0093] In particular, according to the embodiments disclosed in this invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments disclosed in this invention include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication section 609, and / or installed from removable medium 611. When the computer program is executed by central processing unit (CPU) 601, it performs the functions defined above in the system of this invention.

[0094] It should be noted that the computer-readable medium shown in this invention can be a computer-readable signal medium or a computer-readable storage medium, or any combination of the two. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this invention, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In this invention, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media can also be any computer-readable medium other than computer-readable storage media, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wireless, wire, optical fiber, RF, etc., or any suitable combination thereof.

[0095] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram or flowchart, and combinations of blocks in a block diagram or flowchart, may be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.

[0096] The units described in the embodiments of the present invention can be implemented in software or in hardware. The described units can also be housed in a processor; for example, a processor can be described as including: a monitoring code injection module, a software code execution module, and a coverage determination module.

[0097] In some cases, the names of these modules do not constitute a limitation on the module itself. For example, the monitoring code injection module can also be described as "a module used to inject monitoring code into the code of the software under test in response to receiving a software code coverage statistics request".

[0098] On the other hand, the present invention also provides a computer-readable medium, which may be included in the device described in the embodiments; or it may exist independently and not assembled into the device. The computer-readable medium carries one or more programs, which, when executed by the device, cause the device to: in response to receiving a software code coverage statistics request, inject monitoring code into the code of the software under test; acquire pre-recorded online traffic of the software under test, parse the online traffic, and, based on the result of the parsing, initiate the execution of the code of the software under test; and, through the monitoring code, acquire the code execution status of each component code of the software under test, and, based on the acquired code execution status, obtain the code coverage of the software under test.

[0099] The technical solution of the present invention has the following advantages or beneficial effects: by responding to a received software code coverage statistics request, a listening code is injected into the code of the software under test; pre-recorded online traffic of the software under test is obtained, the online traffic is parsed and processed, and the code of the software under test is started and executed according to the parsing and processing results; by listening to the code, the code execution status of each component code of the software under test is obtained, and the code coverage of the software under test is obtained according to the obtained code execution status, a reliable and accurate code coverage statistics method is realized. Using real online traffic to start and execute the code of the software under test, the statistical unit is expanded from method code to the entire software code, which not only ensures the accuracy and authenticity of the statistical results, but also eliminates test cases and improves statistical efficiency.

[0100] The specific embodiments described herein do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can occur depending on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.

Claims

1. A statistical method for code coverage, characterized in that, include: In response to receiving a software code coverage statistics request, listener code is injected into the code of the software under test. The system acquires pre-recorded online traffic of the software under test, parses and processes the online traffic, and executes the code of the software under test based on the parsing and processing results. The monitoring code obtains the code execution status of each component code of the software under test, and the code coverage of the software under test is obtained based on the obtained code execution status.

2. The method according to claim 1, characterized in that, Injecting monitoring code into the code of the software under test, including: Each line of code in the software under test is bytecode enhanced to generate software under test with implanted probe code, and the listening code includes the probe code.

3. The method according to claim 1, characterized in that, Before acquiring pre-recorded online traffic of the software under test, the method further includes: Obtain the online requests of the online software corresponding to the software under test, as well as the input parameters and return values ​​of the online requests; The online request, along with its corresponding input parameters and return values, are saved as the online traffic of the software under test.

4. The method according to claim 3, characterized in that, Obtain the online requests of the online software corresponding to the software under test, as well as the input parameters and return values ​​of the online requests, including: The online software corresponding to the software under test is subjected to bytecode enhancement to generate online software with surround events; The surrounding event captures the input parameters and return values ​​of the online software when executing online requests.

5. The method according to claim 1, characterized in that, The online traffic is parsed and processed, and based on the parsing result, the code for executing the software under test is initiated, including: The online traffic is analyzed to obtain the startup input parameters of the online software corresponding to the software under test, as well as the input parameters and return values ​​of each interface code in the online software. Based on the input parameters and return values ​​of each interface code in the online software, the bytecode of the external interaction interface code in the software under test is enhanced to generate the software under test with independent execution capability. The startup parameters are used to trigger the execution of the code of the software under test, which has independent execution capabilities.

6. The method according to claim 1, characterized in that, The monitoring code obtains the code execution status of each component of the software under test, including: Monitor the reporting information of the listening code, which has execution reporting code deployed in it so that the execution information of the listening code is reported when the listening code is executed; The execution information reported by the received monitoring code is parsed to obtain the line information of the executed code in each component code of the software under test, the logical branch to which the executed code belongs, and the online request corresponding to the executed code.

7. The method according to claim 6, characterized in that, Based on the obtained execution data of each code segment, the code coverage of the software under test is obtained, including: Based on the obtained line information of the executed code in each component code, the logical branch to which the executed code belongs, and the online request corresponding to the executed code, the line information of the executed code and the logical branch to which it belongs for each online request are statistically analyzed. Based on the line information of the execution code corresponding to each online request and the logical branch to which it belongs, calculate at least one of the line code coverage and logical branch code coverage of the software under test.

8. The method according to claim 3, characterized in that, Before saving the online request, along with the corresponding input parameters and return values, as the online traffic of the software under test, the method further includes: serializing the input parameters and return values ​​corresponding to the online request. Saving the online request, along with the corresponding input parameters and return values, as the online traffic of the software under test includes: saving the online request, along with the corresponding serialized input parameters and return values, as the online traffic of the software under test. Before parsing the online traffic, the method further includes: deserializing the input parameters and return values ​​in the online traffic.

9. A statistical device for code coverage, characterized in that, include: The monitoring code injection module is used to inject monitoring code into the code of the software under test in response to receiving a software code coverage statistics request. The software code execution module is used to acquire pre-recorded online traffic of the software under test, parse and process the online traffic, and start executing the code of the software under test based on the parsing and processing results. The coverage determination module is used to obtain the code execution status of each component code of the software under test through the monitoring code, and to obtain the code coverage of the software under test based on the obtained code execution status.

10. A mobile electronic device terminal, characterized in that, include: One or more processors; Storage device for storing one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors implement the method as described in any one of claims 1-8.

11. A computer-readable medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the method as described in any one of claims 1-8.