Incremental code coverage rate acquisition device based on Java bytecode dynamic instrumentation technology

Through Java bytecode dynamic instrumentation technology combined with Git and JavaParser for incremental code difference analysis, the problems of accuracy and completeness of existing tools in incremental code coverage analysis are solved, row-level difference analysis and unified coverage reporting are realized, and the accuracy and visualization capabilities of coverage data are improved.

CN120407398APending Publication Date: 2025-08-01BEIJING BAIJU YIXING TECH CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202510423732.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-07
Publication Date
2025-08-01

AI Technical Summary

Technical Problem

Existing tools are difficult to achieve accurate to line-level difference analysis in incremental code coverage analysis, and they cannot display the coverage of full and incremental codes in one report, and lack support for comments, non-Java file changes and code deletion, resulting in incomplete and inaccurate coverage statistics.

Method used

Dynamic instrumentation technology based on Java bytecode is adopted, combined with Git and JavaParser to perform accurate incremental code differences analysis, syntax tree model is generated, and dynamic instrumentation is used to use ASM and Instrumentation technology to collect coverage data in real time, and a unified coverage report is generated.

Benefits of technology

It realizes accurate to line-level analysis of incremental code coverage, reduces test redundancy, improves the accuracy and visualization capabilities of coverage data, and optimizes the efficiency of test case design and code quality control.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120407398A_ABST
    Figure CN120407398A_ABST
Patent Text Reader

Abstract

The invention discloses an incremental code coverage rate acquisition device based on a Java bytecode dynamic instrumentation technology, and relates to the technical field of software testing and quality control. Comprising a code difference analysis module, a byte code instrumentation module, a coverage rate data acquisition module, a coverage rate data integration module, a coverage rate report generation module and a test trigger and threshold control module, and a syntax tree structure of incremental codes is generated based on a Java syntax analysis tool, so that line level analysis of code differences is realized. According to the method, incremental codes are accurately analyzed through Git and JavaParser, coverage rate data are collected through dynamic instrumentation, a unified report is generated in combination with path analysis, missing scenes are marked in a highlighted mode, and the test efficiency and the code quality control capacity are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of software testing and quality control, and particularly to an incremental code coverage acquisition device based on Java bytecode dynamic instrumentation technology. Background Art

[0002] In modern software development, with the rapid change of business requirements and the continuous introduction of new functions, frequent code changes have become the norm in development work. To ensure the functional stability and quality reliability of software, code coverage, as an important indicator to measure the integrity of testing, has been widely used. Code coverage quantifies the coverage of testing by analyzing which code in the program is executed by the test. Common types include method coverage, branch coverage, and line coverage, etc. These metrics not only help developers identify untested code areas but also guide the design and optimization of test cases. However, traditional coverage analysis tools usually focus on full-code coverage, that is, performing coverage statistics and analysis on the entire codebase. This approach often leads to waste of testing resources in a development environment with frequent code changes, and it is also difficult to meet the requirements for efficient and accurate coverage acquisition in incremental code scenarios. In continuous integration and distributed development environments, the acquisition and analysis of incremental code coverage are particularly crucial and have gradually become a necessary means to improve development quality.

[0003] The existing technologies have the following deficiencies:

[0004] Although there are already some tools in the existing technologies that attempt to solve the problem of incremental code coverage, such as calculating incremental code coverage through Git version differences, there are still obvious deficiencies. First, the analysis granularity of the code change range by existing tools is relatively coarse, unable to accurately perform dynamic statistics at the line level, and it is also difficult to display the coverage of full-code and incremental code in a single report. Second, when generating the coverage report, traditional tools often can only generate two independent reports for full-code and incremental code respectively, and cannot mark the changes in incremental code and the corresponding coverage in a unified report. In addition, for special scenarios such as code comments, changes to non-Java files, and code deletions in the code, existing tools lack effective support, resulting in incomplete and inaccurate coverage statistics results. The existence of the above problems seriously affects the efficiency and accuracy of incremental code coverage analysis. Therefore, there is an urgent need for an efficient and accurate incremental code coverage acquisition method to make up for these technical deficiencies.

[0005] The above information disclosed in the background art section is only used to enhance the understanding of the background of the present disclosure. Therefore, it may include information that does not constitute the prior art known to those of ordinary skill in the art. Summary of the Invention

[0006] The object of the present invention is to provide an incremental code coverage acquisition device based on Java bytecode dynamic instrumentation technology, which realizes accurate incremental code difference analysis through Git and JavaParser, accurate to the line level and generates a syntax tree model, reduces test redundancy and improves efficiency; uses ASM and Instrumentation technologies to perform dynamic instrumentation on incremental code to ensure real-time acquisition of coverage data during runtime, improves data accuracy and has the least impact on performance; combines dynamic path analysis to generate a unified coverage report, intuitively displays the full-scale and incremental code coverage, optimizes test case design by highlighting missing scenarios, and improves the efficiency of code quality control. This solution overall improves the accuracy, efficiency and visualization ability of coverage acquisition, provides strong support for code test quality, and solves the problems in the above-mentioned background technology.

[0007] To achieve the above object, the present invention provides the following technical solution: An incremental code coverage acquisition device based on Java bytecode dynamic instrumentation technology, comprising a code difference analysis module, a bytecode instrumentation module, a coverage data acquisition module, a coverage data integration module, a coverage report generation module, and a test trigger and threshold control module:

[0008] The code difference analysis module compares the current branch of the code repository with the target baseline branch through the Git version management tool, and generates a syntax tree structure of the incremental code based on the Java syntax parsing tool to realize line-level analysis of code differences;

[0009] The bytecode instrumentation module performs bytecode dynamic instrumentation on Java classes and methods within the scope of the differential code based on the ASM framework, and inserts coverage acquisition probes; uses the Instrumentation technology to perform real-time instrumentation on newly added classes and methods in the differential code during runtime to ensure that the probe insertion process is efficient and does not affect the program running logic;

[0010] The coverage data acquisition module, when running the program where the incremental code is located, uses the probes to acquire dynamic coverage data, generates a binary file recording the coverage execution path, and classifies the data at the line level, method level, and branch level;

[0011] The coverage data integration module combines the coverage data of the full-scale code and the incremental code, and merges the incremental code coverage data into the full-scale coverage model through the dynamic execution information marked by the probes, and filters the changes in code comments, deletions, and non-Java files to generate a unified coverage model;

[0012] The coverage report generation module generates a unified coverage report based on the coverage model. The report displays basic data on the full code coverage, highlights coverage paths and omission scenarios in incremental code, and supports dynamic path analysis.

[0013] The test trigger and threshold control module triggers the coverage collection task through GitWebHook. Based on the coverage data generated in the coverage report, it sets the threshold values for incremental code coverage and test pass rate. Code submissions that do not meet the standards will be automatically blocked from entering the testing process.

[0014] Preferably, the code change range between the current branch and the target baseline branch is obtained based on the JGit tool, and the specific change type of the code is further analyzed. The analysis results are marked with differences at the file and line level granularity.

[0015] Preferably, the Java syntax parsing tool adopts JavaParser, which analyzes the classes, methods, properties and control flow nodes involved in the code differences through the syntax tree structure, and generates an incremental code model with syntax node markers for subsequent instrumentation processing.

[0016] Preferably, a probe variable of Boolean type is added at a key position of the incremental code through probe insertion logic to record whether the code is executed, while ensuring that the bytecode structure after the insertion is compatible with the original structure.

[0017] Preferably, when the instrumentation technology loads the probe at runtime, it monitors the loaded classes in the JVM by defining the premain method, and dynamically inserts the unloaded incremental classes and methods in real time to ensure that the probe covers the execution path of all new codes.

[0018] Preferably, the step of generating a binary file recording the coverage execution path stores coverage data according to the following categories:

[0019] Line level: mark whether a specific line of code is executed;

[0020] Method level: mark the coverage of method calls;

[0021] Branch level: marks the execution path of the conditional branch structure;

[0022] The exec file contains detailed records of the corresponding incremental code path and probe status.

[0023] Preferably, a rule-based filtering algorithm is used to remove code comments, non-Java files, and changes to deleted code, and dynamic path analysis is used to repair missed scenarios in the full coverage data.

[0024] Preferably, the execution path of the incremental code is deeply analyzed through a dynamic path analysis algorithm, and the uncovered code paths are marked. At the same time, the coverage status of the incremental code is marked with symbol highlighting to visually distinguish the full - scale coverage rate and the incremental coverage rate.

[0025] Preferably, the platform dynamically sets the threshold values of the incremental code coverage rate and the unit test passing rate as thresholds based on historical data. The threshold values include:

[0026] The incremental code coverage rate reaches at least 60%;

[0027] The unit test passing rate reaches 100%;

[0028] Submissions that do not meet the above - mentioned threshold values will be automatically interrupted to prevent entry into the test process.

[0029] In the above - mentioned technical solution, the technical effects and advantages provided by the present invention are:

[0030] By combining the Git version management tool and the JavaParser syntax parsing tool, the present invention realizes the precise line - level analysis of incremental code. Using the JGit tool to obtain the change information between the current branch and the target baseline branch of the code repository, it can accurately distinguish the ranges of newly added, modified, and deleted code. Subsequently, a syntax tree model of the incremental code is generated through JavaParser, which not only marks the specific location of the incremental code but also clarifies the context syntax structure of the code, such as method entry points, control - flow nodes, etc. Compared with the traditional method of marking the code change range only based on line numbers or file markers, this solution can deeply understand the code logic, effectively reduce misjudgments or omissions, and lay a high - precision foundation for subsequent instrumentation operations.

[0031] The accuracy of this analysis method significantly improves the test efficiency. In a large - scale code repository, the changes in incremental code may only account for a very small proportion of the total code volume, but the monitoring of the coverage rate of these incremental codes is particularly crucial. This solution accurately locates the range of incremental code, avoiding instrumentation and coverage analysis of irrelevant code, which not only reduces the test time but also lowers the consumption of system resources. At the same time, this solution can effectively filter out non - functional changes such as comment changes and format adjustments, ensuring that the focus of testers always remains on the actually changed functional code, thereby improving the test coverage rate and test quality.

[0032] The present invention adopts ASM and Instrumentation technologies, and can achieve dynamic bytecode instrumentation within the scope of incremental code. Through the ASM framework, probes are inserted at the bytecode level for the classes and methods of the incremental code. The probes record the dynamic state of code execution, and through the Instrumentation technology, real-time instrumentation is performed on the newly added classes and methods at runtime to ensure that the instrumentation process covers all incremental code paths. This instrumentation method can accurately locate the actual execution of the code, avoid the redundant statistics problem caused by traditional static instrumentation for unexecuted code, and thus improve the accuracy of coverage data.

[0033] In addition, the dynamic instrumentation feature of this solution ensures minimal impact on the program's running logic. By inserting probes at key positions such as method entrances and branch nodes, the performance of the code running is maintained stable while collecting data. The dynamic instrumentation at runtime also supports the on-demand instrumentation strategy, which only processes the incremental code, avoiding the performance overhead of full-scale instrumentation. This flexible and efficient instrumentation method makes the collection of coverage data more targeted, providing a reliable basis for the design and optimization of test cases.

[0034] Through dynamic path analysis and coverage data integration, the present invention can generate a unified coverage report that includes the coverage of full-scale code and incremental code. The coverage report not only shows the basic coverage data of the full-scale code, but also highlights the covered paths and missing scenarios of the incremental code through colors or symbols. The dynamic path analysis algorithm further clarifies the actual coverage in the code execution path and repairs the missing parts in the full-scale code coverage model, making the report more complete and accurate. This unified report form significantly improves the visualization effect of the coverage data.

[0035] Highlighting and dynamic path analysis enable developers and testers to quickly identify the deficiencies in test coverage. Through the intuitive display of the covered paths and missing scenarios of the incremental code, the report effectively guides the supplementary design of test cases and helps testers focus on the key code segments that are not covered. In addition, the visualization ability of the report makes the evaluation of code quality more transparent, facilitating team members and managers to track the test progress in real time. This intuitive and comprehensive coverage analysis report improves the efficiency and accuracy of the testing work, and at the same time provides a solid technical guarantee for the continuous improvement of code quality. BRIEF DESCRIPTION OF THE DRAWINGS

[0036] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings required in the embodiments. Obviously, the drawings described below are only some embodiments recorded in the present invention. For those of ordinary skill in the art, other drawings can also be obtained according to these drawings.

[0037] Figure 1 This is a schematic diagram of the modules of an incremental code coverage acquisition device based on the Java bytecode dynamic instrumentation technology of the present invention. Detailed implementation manners

[0038] Example embodiments will now be described more fully with reference to the accompanying drawings. However, the example embodiments can be implemented in various forms and should not be construed as limited to the examples set forth herein; rather, these example embodiments are provided so that this disclosure will be more thorough and complete, and will fully convey the concept of the example embodiments to those skilled in the art.

[0039] The present invention provides an incremental code coverage acquisition device based on the Java bytecode dynamic instrumentation technology as shown in Figure 1 the following, and an incremental code coverage acquisition method based on the Java bytecode dynamic instrumentation technology, which is characterized by including a code difference analysis module, a bytecode instrumentation module, a coverage data acquisition module, a coverage data integration module, a coverage report generation module, and a test trigger and threshold control module:

[0040] The code difference analysis module compares the current branch of the code repository with the target baseline branch through a Git version management tool, and generates a syntax tree structure of the incremental code based on a Java syntax parsing tool to achieve line-level analysis of code differences.

[0041] Based on the JGit tool, obtain the code change range between the current branch and the target baseline branch, and further parse the specific change types of the code, including addition, modification, and deletion. The parsing results mark the differences at the granularity of files and lines.

[0042] The Java syntax parsing tool uses JavaParser to analyze classes, methods, attributes, and control flow nodes involved in code differences through the syntax tree structure, and generates an incremental code model with syntax node markings for subsequent instrumentation processing.

[0043] The bytecode instrumentation module performs bytecode dynamic instrumentation on Java classes and methods within the difference code range based on the ASM framework, and inserts coverage acquisition probes; uses the Instrumentation technology to perform real-time instrumentation on newly added classes and methods in the difference code during runtime to ensure efficient probe insertion without affecting the program running logic;

[0044] Add boolean-type probe variables at key positions (such as method entry and branch nodes) of the incremental code through the probe insertion logic to record whether the code is executed, while ensuring that the bytecode structure after instrumentation is compatible with the original structure.

[0045] When the Instrumentation technology loads probes at runtime, it monitors the classes loaded within the JVM by defining the premain method, and performs real-time dynamic instrumentation on unloaded incremental classes and methods to ensure that the probes cover the execution paths of all newly added code.

[0046] The coverage data collection module, when running the program where the incremental code is located, uses the probes to collect dynamic coverage data, generates a binary file (exec file) that records the coverage execution paths, and classifies the data at the line level, method level, and branch level;

[0047] The steps to generate a binary file (exec file) that records the coverage execution paths are as follows: Store the coverage data by the following classification:

[0048] Line level: Mark whether a specific code line is executed;

[0049] Method level: Mark the coverage of method calls;

[0050] Branch level: Mark the execution paths of conditional branch structures;

[0051] Among them, the exec file contains detailed records of the corresponding incremental code paths and probe status.

[0052] The coverage data integration module combines the coverage data of the full-scale code and the incremental code. Through the dynamic execution information marked by the probes, it merges the incremental code coverage data into the full-scale coverage model, and filters out changes to code comments, deletions, and non-Java files to generate a unified coverage model;

[0053] Adopt a rule-based filtering algorithm to eliminate changes to code comments, non-Java files, and deleted code, and repair missing scenarios in the full-scale coverage data through dynamic path analysis.

[0054] The coverage report generation module generates a unified coverage report based on the coverage model. The report shows the basic data of the full-scale code coverage, and at the same time highlights the coverage paths and missing scenarios of the incremental code, supporting dynamic path analysis;

[0055] Through the dynamic path analysis algorithm, deeply analyze the execution paths of the incremental code, mark the uncovered code paths, and at the same time use symbol highlighting to mark the coverage status of the incremental code to visually distinguish the full-scale coverage from the incremental coverage.

[0056] The test trigger and threshold control module triggers the coverage collection task through GitWebHook. According to the coverage data generated in the coverage report, set the threshold values for the incremental code coverage and the test pass rate. Code submissions that do not meet the standards will be automatically blocked from entering the test process.

[0057] The platform dynamically sets the threshold values of incremental code coverage and unit test pass rate to the thresholds based on historical data. The threshold values include:

[0058] The incremental code coverage reaches at least 60%;

[0059] The unit test pass rate reaches 100%;

[0060] Submissions that do not meet the above threshold values will be automatically interrupted and prevented from entering the test process.

[0061] Embodiment 1: In the process of implementing the collection of incremental code coverage, it is first necessary to accurately analyze the scope of code changes to clarify the specific line-level differences of the incremental code. The Git version management tool is used, and the JGit tool is used to obtain the code difference information between the current branch and the target baseline branch. JGit is a Java tool library specifically used to operate on Git repositories. It supports reading the changed content from code branches and details the changed ranges at the file and line levels, including the added, modified, and deleted code areas. The results parsed by JGit are output in the form of difference files and corresponding line numbers, and these results will provide accurate input for incremental code analysis.

[0062] Furthermore, the Java syntax parsing tool JavaParser is combined to deeply parse the difference code. JavaParser can parse the Java source code into a syntax tree structure, and the syntax tree contains detailed information such as classes, methods, fields, and control flow structures (such as if statements and loop statements). In the present invention, through the syntax tree parsing of the difference code, a syntax model with incremental marks is generated. For example, in the modified code, the class name, method name involved, and the specific location where the modification occurs are marked. This incremental code model not only contains the change information of the code lines but also reflects the context syntax features of the changed code, such as method call relationships or branch dependencies.

[0063] Through this difference analysis method, not only can the line-level positioning of the incremental code scope be achieved, but also a clear target is provided for subsequent bytecode instrumentation. Compared with the traditional method that only judges the change range by line numbers, this method further understands the structural information of the code through the syntax tree, avoiding possible incorrect parsing. In addition, this method can also distinguish between functional code changes and non-functional changes (such as comments or format adjustments) in Java files, thereby effectively reducing redundant instrumentation operations.

[0064] Through this precise code difference analysis method, the accuracy and efficiency of incremental code detection are significantly improved. By combining the capabilities of Git and JavaParser, not only can the scope of incremental code be quickly located, but also invalid changes can be eliminated, reducing interference with the full codebase. In addition, by generating an incremental code model with syntax markings, it is ensured that subsequent instrumentation operations can focus on the actual changed parts, reducing the instrumentation overhead and complexity.

[0065] Embodiment 2: After the differential code analysis is completed, bytecode-level instrumentation operations need to be performed on the incremental code to achieve dynamic collection of coverage data. The ASM framework is a lightweight Java bytecode manipulation library that supports dynamic modification of classes, methods, fields, and control flows. In the present invention, the ASM framework is used to perform dynamic instrumentation on the bytecode of the incremental code, and probe variables are inserted at positions such as method entry points and branch nodes. A probe is a boolean-type variable used to mark whether the code has been executed, where true indicates execution and false indicates non-execution. The positions where the probes are inserted are accurately determined according to the syntax structure and line numbers in the incremental code model to ensure that the bytecode after instrumentation is completely compatible with the original logic.

[0066] In addition, the Java Instrumentation technology is combined to perform dynamic instrumentation on classes that are not loaded during runtime. Instrumentation is a powerful tool based on JVMTI that can monitor and modify classes loaded in the JVM. In the present invention, the class loading process of the JVM is intercepted by defining the premain method, and probes are dynamically inserted at runtime for unloaded incremental classes and methods. For example, when the program starts, Instrumentation monitors the loaded classes to identify whether they belong to the scope of incremental code. If it is incremental code, ASM is called to perform bytecode instrumentation on it.

[0067] This instrumentation process adopts a just-in-time instrumentation strategy, operating only on the incremental code part to avoid the performance overhead caused by full-scale instrumentation. After the probes are inserted, during program runtime, the probes automatically update their states according to the code execution situation. For example, the probe at the entry point of a certain method is set to true when the method is called, thus recording that the method has been tested and covered.

[0068] The dynamic instrumentation implemented using the ASM and Instrumentation technologies can not only accurately insert probes but also perform real-time instrumentation on unloaded classes during runtime, ensuring full coverage of the incremental code. Compared with static instrumentation methods, this method is more flexible and efficient, and the performance overhead of the instrumentation operation is minimized. In addition, the positions where the probes are inserted are based on syntax structure and line number information, which can accurately mark the execution status of the code and provide reliable technical support for subsequent collection of coverage data.

[0069] Embodiment 3: After the instrumentation is completed and the program is run, the probes will dynamically collect the execution path information of the incremental code and generate a binary file (exec file) of the coverage data. The exec file records the execution status of each probe, including data classification at the line level, method level, and branch level. For example, whether a certain line of code is executed, whether a certain method is called, and whether a certain conditional branch is covered can all be intuitively extracted from the exec file.

[0070] In the data analysis stage, through the dynamic path analysis algorithm, the coverage data of the incremental code is integrated with the basic coverage model of the full-scale code to generate a unified coverage model. Dynamic path analysis can identify the execution paths of the incremental code and simultaneously repair the missing scenarios according to the full-scale code coverage model. Combining with the rule-based filtering algorithm, the coverage data of comments, non-Java file changes, and deleted code is excluded to ensure the integrity and accuracy of the coverage model.

[0071] Finally, a coverage report is generated. The report includes the basic coverage data of the full-scale code and highlights the coverage paths and missing scenarios of the incremental code. The highlighting is done in the form of color differentiation or symbol marking to visually display the coverage status of the incremental code. In addition, the report supports the visualization function of dynamic path analysis, helping developers quickly locate the uncovered code segments and evaluate the test sufficiency of the incremental code.

[0072] By combining dynamic path analysis and filtering algorithms, the coverage report not only comprehensively reflects the coverage of the full-scale code but also deeply analyzes the execution paths of the incremental code. The highlighting and visualization functions significantly improve the intuitiveness and usability of the report, helping developers and testers quickly discover test omissions, optimize test case design, and improve code quality and test efficiency.

[0073] The present invention realizes the precise line-level analysis of incremental code by combining the Git version management tool and the JavaParser syntax parsing tool. By using the JGit tool to obtain the change information between the current branch and the target baseline branch of the code repository, the code ranges of new additions, modifications, and deletions can be accurately distinguished. Subsequently, through JavaParser, a syntax tree model of the incremental code is generated, which not only marks the specific location of the incremental code but also clarifies the context syntax structure of the code, such as method entry points and control flow nodes. Compared with the traditional tools that only mark the code change range based on line numbers or files, this solution can deeply understand the code logic, effectively reduce misjudgments or omissions, and lay a high-precision foundation for subsequent instrumentation operations.

[0074] The accuracy of this analysis method has significantly improved the test efficiency. In a large codebase, the changes in incremental code may only account for a very small proportion of the total code volume, but the coverage monitoring of this incremental code is particularly crucial. This solution accurately locates the scope of incremental code, avoiding the instrumentation and coverage analysis of irrelevant code, which not only reduces the test time but also decreases the consumption of system resources. At the same time, this solution can effectively filter out non-functional changes such as comment modifications and format adjustments, ensuring that the focus of testers always remains on the functional code with actual changes, thereby improving the test coverage and test quality.

[0075] The present invention adopts ASM and Instrumentation technologies, and the present invention can achieve dynamic bytecode instrumentation within the scope of incremental code. Through the ASM framework, probes are inserted at the bytecode level for the classes and methods of incremental code. The probes record the dynamic state of code execution, and through the Instrumentation technology, real-time instrumentation is performed on newly added classes and methods at runtime to ensure that the instrumentation process covers all incremental code paths. This instrumentation method can accurately locate the actual execution situation of the code, avoiding the redundant statistics problem caused by traditional static instrumentation for unexecuted code, thereby improving the accuracy of coverage data.

[0076] In addition, the dynamic instrumentation feature of this solution ensures the minimum impact on the program's running logic. By inserting probes at key positions such as method entrances and branch nodes, the performance of the code running is maintained stable while collecting data. The dynamic instrumentation at runtime also supports the on-demand instrumentation strategy, only processing incremental code and avoiding the performance overhead of full-scale instrumentation. This flexible and efficient instrumentation method makes the collection of coverage data more targeted, providing a reliable basis for the design and optimization of test cases.

[0077] Through dynamic path analysis and coverage data integration, the present invention can generate a unified coverage report that includes the coverage of full-scale code and incremental code. The coverage report not only shows the basic coverage data of the full-scale code but also highlights the covered paths and missing scenarios of incremental code through colors or symbols. The dynamic path analysis algorithm further clarifies the actual coverage situation in the code execution path and repairs the missing parts in the full-scale code coverage model, making the report more complete and accurate. This unified report form significantly improves the visualization effect of coverage data.

[0078] Highlight annotation and dynamic path analysis enable developers and testers to quickly identify deficiencies in test coverage. Through the intuitive display of the coverage paths of incremental code and missing scenarios, the report effectively guides the supplementary design of test cases and helps testers focus on the key code segments that are not covered. In addition, the visualization ability of the report makes the evaluation of code quality more transparent, facilitating team members and managers to track the test progress in real time. This intuitive and comprehensive coverage analysis report improves the efficiency and accuracy of the testing work, while providing a solid technical guarantee for the continuous improvement of code quality.

[0079] Only some exemplary embodiments of the present invention have been described above by way of illustration. Without doubt, for those of ordinary skill in the art, various different ways can be used to modify the described embodiments without departing from the spirit and scope of the present invention. Therefore, the above drawings and descriptions are illustrative in nature and should not be construed as limiting the scope of protection of the claims of the present invention.

Claims

1. An incremental code coverage acquisition device based on Java bytecode dynamic instrumentation technology, characterized in that It includes a code difference analysis module, a bytecode instrumentation module, a coverage data collection module, a coverage data integration module, a coverage report generation module, and a test trigger and threshold control module: The code difference analysis module compares the current branch and the target baseline branch of the code repository through the Git version management tool, and generates the syntax tree structure of the incremental code based on the Java syntax parsing tool to achieve line-level analysis of code differences; The bytecode instrumentation module performs bytecode dynamic instrumentation on Java classes and methods within the scope of the different code based on the ASM framework, and inserts coverage collection probes; uses Instrumentation technology to perform real-time instrumentation on newly added classes and methods in the different code during runtime to ensure that the probe insertion process is efficient and does not affect the program's running logic; The coverage data collection module, when running the program where the incremental code is located, uses probes to collect dynamic coverage data, generates a binary file recording the coverage execution path, and classifies the data at the line level, method level, and branch level; The coverage data integration module combines the coverage data of the full-scale code and the incremental code, and through the dynamic execution information marked by the probes, merges the incremental code coverage data into the full-scale coverage model, and filters the changes to code comments, deletions, and non-Java files to generate a unified coverage model; The coverage report generation module generates a unified coverage report based on the coverage model. The report displays the basic data of the full-scale code coverage, and at the same time highlights the covered paths and missing scenarios of the incremental code to support dynamic path analysis; The test trigger and threshold control module triggers the coverage collection task through GitWebHook, sets the threshold values for the incremental code coverage and the test passing rate according to the coverage data generated in the coverage report, and code submissions that do not meet the standards will be automatically blocked from entering the test process.

2. The incremental code coverage acquisition device based on the Java bytecode dynamic instrumentation technology according to claim 1, characterized in that Obtain the code change range of the current branch and the target baseline branch based on the JGit tool, and further analyze the specific change types of the code. The analysis results mark the differences at the file and line level granularity.

3. The incremental code coverage acquisition device based on the Java bytecode dynamic instrumentation technology according to claim 1, characterized in that The Java syntax parsing tool uses JavaParser to analyze the classes, methods, attributes, and control flow nodes involved in the code differences through the syntax tree structure, and generates an incremental code model with syntax node markings for subsequent instrumentation processing.

4. An incremental code coverage acquisition device based on the Java bytecode dynamic instrumentation technology according to claim 1, characterized in that Add boolean-type probe variables at key positions in the incremental code through the probe insertion logic to record whether the code is executed, while ensuring that the bytecode structure after instrumentation is compatible with the original structure.

5. An incremental code coverage acquisition device based on the Java bytecode dynamic instrumentation technology according to claim 1, characterized in that, When the Instrumentation technology loads the probes during runtime, it monitors the classes loaded within the JVM by defining the premain method, and performs real-time dynamic instrumentation on unloaded incremental classes and methods to ensure that the probes cover all execution paths of the newly added code.

6. An incremental code coverage acquisition device based on Java bytecode dynamic instrumentation technology according to claim 1, characterized in that The steps to generate a binary file recording the coverage execution path store the coverage data in the following categories: Line level: Mark whether a specific code line is executed; Method level: Mark the coverage of method calls; Branch level: Mark the execution path of the conditional branch structure; The exec file contains detailed records of the corresponding incremental code path and probe status.

7. An incremental code coverage acquisition device based on the Java bytecode dynamic instrumentation technology according to claim 1, characterized in that, A rule-based filtering algorithm is used to remove changes to code comments, non-Java files, and deleted code, and dynamic path analysis is used to repair missed scenarios in the full coverage data.

8. An incremental code coverage acquisition device based on Java bytecode dynamic instrumentation technology according to claim 1, characterized in that, The execution path of the incremental code is deeply analyzed through the dynamic path analysis algorithm, and the uncovered code paths are marked. At the same time, the coverage status of the incremental code is highlighted with symbols to visually distinguish between full coverage and incremental coverage.

9. An incremental code coverage acquisition device based on Java bytecode dynamic instrumentation technology according to claim 1, characterized in that The platform dynamically sets the thresholds for incremental code coverage and unit test pass rate based on historical data. The thresholds include: Incremental code coverage reaches at least 60%; The single test pass rate reached 100%; Submissions that do not meet the above thresholds will be automatically aborted and prevented from entering the testing process.

Citation Information

Cited By

  • Method and system for evaluating test coverage rate based on Java call link

    CN121144214A

  • Coverage rate report generation method, test platform and equipment

    CN121743224A