Code coverage rate visualization method and device and medium
By identifying and transmitting differential code coverage, combined with permission management, the performance bottlenecks and permission fault problems of traditional code coverage tools are solved, efficient code coverage visualization is achieved, and rendering efficiency and collaboration accuracy of large projects are improved.
Patent Information
- Application Number
- CN202510673963.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-23
- Publication Date
- 2025-08-26
AI Technical Summary
In the prior art, traditional code coverage tools need to refresh the interface in large projects, resulting in increased burdens on data transmission and page rendering, and there are permission fault problems, which cannot adapt to the dynamic collaboration needs in agile development.
By identifying the difference between the test code uploaded by developers and the historical code, only the differential code coverage is transmitted and rendered, and combined with the permission management mechanism, we ensure the functional permission allocation of different positions and realize efficient transmission and rendering of different codes.
It reduces network traffic by 60%, improves coverage rendering efficiency, reduces collaboration conflict rate, ensures the accuracy of code coverage and the efficiency of multi-person collaboration.
Smart Images

Figure CN120540992A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of code testing, and in particular to a code coverage visualization method, device, and medium. Background Art
[0002] Code coverage is a key metric for measuring software testing completeness, evaluating the extent to which test cases cover program code. By analyzing the proportion of code executed during testing relative to the total code, it helps developers identify untested code areas. It can quantify test completeness, identify blind spots, and assist with code optimization.
[0003] In the existing technology, traditional code coverage tools (such as JaCoCo) require a full refresh of the interface, resulting in large projects only being able to collect and render code coverage in full, which increases the burden of data transmission and page rendering and easily leads to performance bottlenecks. Summary of the Invention
[0004] To solve the above problems, this application proposes a code coverage visualization method, device, and medium, wherein the method includes:
[0005] The first test code uploaded by the developer is sent to the tester; the second test code corresponding to the first test code and the difference code between the first test code and the second test code are determined; the difference code coverage corresponding to the difference code is determined by performing coverage testing on the first test code; the difference code coverage is transmitted to the front end and rendered.
[0006] In one example, before sending the first test code uploaded by the developer to the tester, the method also includes: entering personnel information and setting different job categories in the personnel information, the job categories including development positions and testing positions; allocating job function permissions corresponding to different job categories in the optional job function permissions; the optional job function permissions corresponding to the development position include code submission permissions and coverage viewing permissions; the optional job function permissions corresponding to the testing position include test system permissions, code analysis permissions, coverage collection permissions and coverage viewing permissions.
[0007] In one example, sending the first test code uploaded by the developer to the tester specifically includes: receiving a test code upload request from the uploader; determining the personnel information corresponding to the uploader and the class file name corresponding to the first test code based on the test code upload request; determining the job position of the uploader based on the personnel information of the uploader; if the job position of the uploader is a developer and has code submission permission, forwarding the first test code to the tester corresponding to the class file name.
[0008] In one example, determining the second test code corresponding to the first test code specifically includes: determining all historical test codes with the same class file name as the first test code; determining the second test code in all historical test codes based on the comparison version number contained in the test code upload request; after determining the second test code corresponding to the first test code, the method also includes: instrumenting all valid code lines in the system under test.
[0009] In one example, determining the difference code of the first test code relative to the second test code specifically includes: generating a first abstract syntax tree corresponding to the first test code, and determining the first hash values corresponding to each first subtree of the first abstract syntax tree; determining the second abstract syntax tree corresponding to the second test code, and the second hash values corresponding to each second subtree of the second abstract syntax tree; determining the difference subtree of the first abstract syntax tree corresponding to the first test code by comparing the first hash value with the corresponding second hash value; and using the first test code contained in the difference subtree as the difference code of the first test code relative to the second test code.
[0010] In one example, transmitting the difference code coverage to the front end and rendering it specifically includes: determining the class file name and code line number corresponding to the difference code; determining the coverage status corresponding to the difference code, the coverage status including at least one of uncovered, covered and incompletely covered; sending the code line number corresponding to the difference code and the coverage status to the front end; and redrawing only the coverage display of the DOM node corresponding to the difference subtree corresponding to the difference code.
[0011] In one example, after transmitting the difference code coverage to the front end and rendering it, the method further includes: sending the rendering results to the developer and the tester for display; determining the code that failed the test, and returning the code that failed the test to the developer and / or the tester.
[0012] In one example, the code that fails the test is code whose test coverage is lower than a preset threshold.
[0013] The present application also provides a code coverage visualization device, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute: sending a first test code uploaded by a developer to a tester; determining a second test code corresponding to the first test code, and a difference code between the first test code and the second test code; determining a difference code coverage corresponding to the difference code by performing a coverage test on the first test code; transmitting the difference code coverage to the front end and rendering it.
[0014] The present application also provides a non-volatile computer storage medium storing computer-executable instructions, characterized in that the computer-executable instructions are configured to: send a first test code uploaded by a developer to a tester; determine a second test code corresponding to the first test code, and a difference code between the first test code and the second test code; determine a difference code coverage corresponding to the difference code by performing a coverage test on the first test code; and transmit the difference code coverage to a front end for rendering.
[0015] The method proposed in this application can bring the following beneficial effects:
[0016] 1. The difference code is judged based on the difference subtree, and only the code line number and coverage status of the difference code are transmitted. This can reduce the size of the network transmission data packet, effectively improve the coverage rendering efficiency, and reduce the network traffic by 60% when transmitting coverage data.
[0017] 2. By allocating permissions in advance, the rate of collaboration conflicts can be reduced, such as preventing developers from submitting changes to the object under test without authorization.
[0018] 3. Through multi-person collaborative testing, more test scenarios and test cases can be covered in a short period of time, making the collected code coverage more accurate. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0020] Figure 1 This is a flowchart of a code coverage visualization method in an embodiment of the present application;
[0021] Figure 2 A schematic diagram of rendering the difference subtree test coverage in an embodiment of the present application;
[0022] Figure 3 This is a schematic diagram of a developer viewing page in an embodiment of the present application;
[0023] Figure 4 This is a structural diagram of a code coverage visualization device in an embodiment of the present application. DETAILED DESCRIPTION
[0024] To make the purpose, technical solutions, and advantages of this application more clear, the technical solutions of this application will be clearly and completely described below in conjunction with the specific embodiments of this application and the corresponding drawings. Obviously, the embodiments described are only part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0025] The following describes in detail the technical solutions provided by various embodiments of the present application in conjunction with the accompanying drawings.
[0026] Figure 1 This is a flowchart of a code coverage visualization method provided in one or more embodiments of this specification. This method can be applied to various business code testing applications, such as internet finance, e-commerce, instant messaging, gaming, and government affairs. Certain input parameters or intermediate results in the process can be manually adjusted to improve accuracy.
[0027] Code coverage is a key metric for measuring software testing completeness, evaluating the extent to which test cases cover program code. By analyzing the proportion of code executed during testing relative to the total code, it helps developers identify untested code areas. It can quantify test completeness, identify blind spots, and assist with code optimization.
[0028] In the existing technology, traditional code coverage tools (such as JaCoCo) require a full refresh of the interface, resulting in large projects only being able to collect and render code coverage in full, which increases the burden of data transmission and page rendering and easily leads to performance bottlenecks.
[0029] In addition, existing technologies also have the problem of authority gaps. Static code coverage tools cannot adapt to the dynamic collaboration needs in agile development. For example, developers cannot directly observe the test coverage of testers.
[0030] The implementation of the analysis method involved in the embodiments of the present application can be a terminal device or a server, and this application does not impose any special restrictions on this. For ease of understanding and description, the following embodiments are described in detail using a server as an example. It should be noted that the server can be a single device or a system composed of multiple devices, that is, a distributed server, and this application does not impose any specific restrictions on this.
[0031] like Figure 1 As shown, an embodiment of the present application provides a code coverage visualization method, including:
[0032] S101: Send the first test code uploaded by the developer to the tester.
[0033] First, the server receives a first test code from a developer and sends the first test code to a tester, wherein the first test code refers to a newly submitted code for a certain function.
[0034] In one embodiment, in order to solve the problem of authority fault, this application integrates a rights management mechanism. Specifically, this application will enter personnel information in advance and set different job categories (such as development positions, testing positions) in the personnel information. It should be noted that for the same code testing task, there can be multiple testers and multiple developers, that is, multiple developers are developing the code to be tested at the same time, and multiple testers are testing it at the same time. At this time, it is necessary to set the job function permissions, for example, assign code submission permissions and coverage viewing permissions to the development position, or assign test system permissions, code analysis permissions, coverage collection permissions and coverage viewing permissions to the testing position. The specific permission allocation method can be allocated according to the actual usage scenario. For example, only one developer among multiple developers is set to have code submission permissions, and other developers only have coverage viewing permissions.
[0035] In one embodiment, after the permissions are set, subsequent use of the system must strictly adhere to the set personnel permission definition rules. Developers cannot test the target system, analyze code, or collect coverage maps, and testers cannot submit code. By assigning permissions, developers can be prevented from committing unauthorized actions such as changing the object under test. Specifically, after receiving a test code upload request from an uploader, the server determines the uploader's corresponding personnel information and the class file name corresponding to the first test code based on the test code upload request. The server then searches the uploader's personnel information in the pre-stored personnel information to determine the uploader's job position. It should be noted that when there is a job position change, it needs to be synchronized with the pre-stored personnel information database. If the uploader's job position is developer and has code submission permission, the first test code is forwarded to the tester corresponding to the class file name. If the uploader's job position is not developer, or if they are a developer but do not have code submission permission, the developer is prevented from uploading the first test code.
[0036] S102: Determine a second test code corresponding to the first test code, and a difference code between the first test code and the second test code.
[0037] After obtaining the first test code, a second test code corresponding to the first test code is determined, where the second test code refers to the tested code. After determining the second test code corresponding to the first test code, a difference code between the first test code and the second test code can be determined.
[0038] In one embodiment, when determining the second test code corresponding to the first test code, it is necessary to identify all historical test codes with the same class file name as the first test code. Here, all historical test codes refer to those for which records are still available. Then, based on the comparison version number included in the test code upload request, the second test code with the comparison version number can be identified from all historical test codes.
[0039] In one embodiment, when there is no historical test code with the same class file name as the first test code, there are the following situations: the first situation is that the first test code is the test code uploaded for the corresponding class file name for the first time; the second situation is that the first test code is not the test code uploaded for the corresponding class file name for the first time, but the historical test code has been deleted. In this case, the blank code is used as the second test code of the first test code, or the first test code itself is used as the second test code. After determining the second test code corresponding to the first test code, all valid code lines in the system under test will be instrumented to facilitate the subsequent statistical analysis of code coverage by indexing "class file name-code line number".
[0040] In one embodiment, when determining the difference code between the first test code and the second test code, the first abstract syntax tree corresponding to the first test code can be generated first, and then the first hash value corresponding to each first subtree of the first abstract syntax tree is determined, and the second abstract syntax tree corresponding to the second test code and the second hash value corresponding to each second subtree of the second abstract syntax tree are determined; finally, the first hash value is compared with the corresponding second hash value to determine the difference subtree of the first abstract syntax tree corresponding to the first test code. The code contained in the difference subtree is used as the difference code of the first test code relative to the second test code. It can be understood that when the first hash value is not equal to the second hash value, there is a difference code between the first subtree and the second subtree. Therefore, in order to improve the accuracy of the difference code, the subtree can be further divided until each line of code is regarded as a subtree, so that the code line where the difference code is located can be determined.
[0041] In one embodiment, when determining the difference code, the user can also make modifications directly based on the second test code and mark the code lines where the modification action is performed, so that the server can directly determine the code lines where the modification action is performed after receiving the first test code.
[0042] S103: Determine the difference code coverage corresponding to the difference code by performing coverage test on the first test code.
[0043] After obtaining the difference code corresponding to the first test code, coverage testing can be performed on the first test code to obtain the difference code coverage corresponding to the difference code. The difference code coverage here refers to the coverage corresponding to the line where the difference code is located.
[0044] S104: Transmit the difference code coverage to the front end and render it.
[0045] After obtaining the differential code coverage, only the differential code coverage is transmitted to the front-end, and the obtained differential code coverage is rendered in real time. The test results of everyone in the test team can also be dynamically collected at the same time, so that multiple people can mark the coverage status at the same time, ensuring that the data displayed by the browsers of multiple developers and testers is consistent.
[0046] After obtaining the differential code coverage, when transmitting the differential code coverage to the front end, you first need to determine the class file name and code line number corresponding to the differential code, and then determine the coverage of the differential code. The coverage here includes uncovered, covered, and incomplete coverage. Then, the code line number and coverage of the differential code are sent to the front end. When sending, it can be sent in a fixed format, for example: indexing and locating the code by class file name-line number, and judging whether it is covered by enumerating COVERED, NOT_COVERED, and HALF_COVERED values. The format is:
[0047] Json
[0048] {
[0049] "RtfFunctionRuntimeException.java":{#source code file name
[0050] "8":"NOT_COVERED",#"Line number":"Coverage status"
[0051] "9":"NOT_COVERED",
[0052] "20":"HALF_COVERED"
[0053] }
[0054] #COVERED: Covered NOT_COVERED: Not covered HALF_COVERED: Covered half
[0055] }
[0056] After uploading the difference coverage, the server only redraws the coverage display of the DOM nodes corresponding to the difference subtree corresponding to the difference code, so as to obtain the following Figure 2 Rendering of the differential subtree test coverage shown. Figure 2 In the figure, the red background indicates the deleted code in the AST difference subtree, the green background indicates the newly added code in the AST difference subtree, the darker background indicates the modified content, the blue box indicates complete coverage, and the orange box indicates incomplete coverage.
[0057] In one embodiment, after the rendering is completed, the server will send the rendering results to the developer and tester for display; if there is code that is determined to have failed the test, the code that failed the test will be returned to the developer and / or tester. When returning, if it is the test reason of the tester, it will be returned to the tester; if there is a problem with the code itself, it will be returned as follows: Figure 3The developer review page shown is given to the developer for retesting. The code that failed the test here is the code whose test coverage is lower than the preset threshold (such as Dead Code).
[0058] After the tester reviews the coverage results, if the modification point is not fully covered, the tester can repeat the steps again until the analysis fully covers the test code.
[0059] The method proposed in this application can bring the following beneficial effects:
[0060] By identifying differential code based on differential subtrees and transmitting only the line number and coverage status of the differential code, the size of network transmission packets can be reduced, effectively improving coverage rendering efficiency and reducing network traffic by 60% during coverage data transmission. By allocating permissions in advance, collaboration conflicts can be reduced, such as preventing developers from unauthorized submissions and changes to the tested object. Through multi-person collaborative testing, more test scenarios and test cases can be covered in a shorter period of time, resulting in more accurate code coverage.
[0061] like Figure 2 As shown, an embodiment of the present application further provides a code coverage visualization device, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to:
[0062] The first test code uploaded by the developer is sent to the tester; the second test code corresponding to the first test code and the difference code between the first test code and the second test code are determined; the difference code coverage corresponding to the difference code is determined by performing coverage testing on the first test code; the difference code coverage is transmitted to the front end and rendered.
[0063] An embodiment of the present application also provides a non-volatile computer storage medium storing computer-executable instructions, wherein the computer-executable instructions are configured to: send a first test code uploaded by a developer to a tester; determine a second test code corresponding to the first test code, and a difference code between the first test code and the second test code; determine a difference code coverage corresponding to the difference code by performing a coverage test on the first test code; and transmit the difference code coverage to a front end for rendering.
[0064] The various embodiments in this application are described in a progressive manner. Similar portions between the various embodiments can be referred to in conjunction with each other. Each embodiment focuses on the differences between the other embodiments. In particular, the device and medium embodiments are generally similar to the method embodiments, so their descriptions are relatively simple. For relevant portions, refer to the descriptions of the method embodiments.
[0065] The devices and media provided in the embodiments of the present application correspond one-to-one to the methods. Therefore, the devices and media also have similar beneficial technical effects to their corresponding methods. Since the beneficial technical effects of the methods have been described in detail above, the beneficial technical effects of the devices and media will not be repeated here.
[0066] Those skilled in the art will appreciate that the embodiments of the present application can be provided as methods, systems, or computer program products. Therefore, the present application can adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.
[0067] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the steps in the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0068] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.
[0069] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0070] In a typical configuration, a computing device includes one or more processors (CPUs), input / output interfaces, network interfaces, and memory.
[0071] Memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.
[0072] Computer-readable media includes permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. The information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include transitory computer-readable media (transitory media), such as modulated data signals and carrier waves.
[0073] It should also be noted that the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, commodity, or apparatus that includes a series of elements includes not only those elements but also other elements not explicitly listed, or includes elements inherent to such process, method, commodity, or apparatus. In the absence of further limitations, an element defined by the phrase "comprises a ..." does not exclude the presence of other identical elements in the process, method, commodity, or apparatus that includes the element.
[0074] The foregoing is merely an embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present application should all be included within the scope of the claims of the present application.
Claims
1. A code coverage visualization method, characterized in that: include: Send the first test code uploaded by the developer to the tester; Determine a second test code corresponding to the first test code, and a difference code between the first test code and the second test code; Determine the difference code coverage corresponding to the difference code by performing a coverage test on the first test code; The differential code coverage is transmitted to the front end and rendered.
2. The method according to claim 1, characterized in that Before sending the first test code uploaded by the developer to the tester, the method further includes: Enter personnel information and set different job categories in the personnel information, including development positions and testing positions; Allocate the job function permissions corresponding to different job categories in the optional job function permissions; The optional functional permissions corresponding to the development position include code submission permission and coverage viewing permission; The optional position function permissions corresponding to the testing position include test system permissions, code analysis permissions, coverage collection permissions, and coverage viewing permissions.
3. The method according to claim 2, characterized in that The sending of the first test code uploaded by the developer to the tester specifically includes: Receive test code upload requests from uploaders; Based on the test code upload request, determine the personnel information corresponding to the uploader and the class file name corresponding to the first test code; Determining the job position of the uploading person based on the person information of the uploading person; If the uploader is a developer and has code submission permission, the first test code is forwarded to the tester corresponding to the class file name.
4. The method according to claim 3, characterized in that The determining the second test code corresponding to the first test code specifically includes: Determine all historical test codes with the same class file name as the first test code; Determining the second test code from all the historical test codes based on the comparison version number included in the test code upload request; After determining the second test code corresponding to the first test code, the method further includes: Instrument all valid lines of code in the system under test.
5. The method according to claim 1, characterized in that Determining a difference code between the first test code and the second test code specifically includes: Generate a first abstract syntax tree corresponding to the first test code, and determine first hash values corresponding to each first subtree of the first abstract syntax tree; Determine a second abstract syntax tree corresponding to the second test code, and second hash values corresponding to each second subtree of the second abstract syntax tree; Determine a difference subtree of a first abstract syntax tree corresponding to the first test code by comparing the first hash value with the corresponding second hash value; The first test code included in the difference subtree is used as the difference code between the first test code and the second test code.
6. The method according to claim 5, characterized in that The transmitting the difference code coverage to the front end and rendering it specifically includes: Determine the class file name and code line number corresponding to the difference code; Determining a coverage status corresponding to the difference code, where the coverage status includes at least one of uncovered, covered, and incompletely covered; Send the code line number corresponding to the difference code and the coverage status to the front end; Only the coverage display of the DOM node corresponding to the difference subtree corresponding to the difference code is redrawn.
7. The method according to claim 1, characterized in that After transmitting the difference code coverage to the front end and rendering it, the method further includes: Sending the rendering results to the developer and the tester for display; The code that failed the test is determined, and the code that failed the test is returned to the developer and / or the tester.
8. The method according to claim 7, characterized in that The code that failed the test is the code whose test coverage is lower than a preset threshold.
9. A code coverage visualization device, characterized in that: include: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores instructions executable by the at least one processor, wherein the instructions are executed by the at least one processor to enable the at least one processor to perform: Send the first test code uploaded by the developer to the tester; Determine a second test code corresponding to the first test code, and a difference code between the first test code and the second test code; Determine the difference code coverage corresponding to the difference code by performing a coverage test on the first test code; The differential code coverage is transmitted to the front end and rendered.
10. A non-volatile computer storage medium storing computer executable instructions, characterized in that: The computer executable instructions are configured to: Send the first test code uploaded by the developer to the tester; Determine a second test code corresponding to the first test code, and a difference code between the first test code and the second test code; Determine the difference code coverage corresponding to the difference code by performing a coverage test on the first test code; The differential code coverage is transmitted to the front end and rendered.