Code coverage rate monitoring method and device
By packaging the application on the continuous integration platform and automatically registering it to the automated testing platform, and using the modified jacocoagent.jar for code coverage monitoring, the problem of excessive manual intervention in existing technologies is solved, achieving automated code coverage monitoring and improving the accuracy and efficiency of monitoring.
Patent Information
- Application Number
- CN202410950280.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-16
- Publication Date
- 2024-11-08
AI Technical Summary
In continuous integration based on Kubernetes containerized deployment, existing technologies struggle to automatically monitor code coverage and suffer from issues such as excessive manual intervention and complex IP acquisition.
By packaging and deploying applications through a continuous integration platform, applications are automatically registered to an automated testing platform, coverage monitoring tasks are created, and code coverage monitoring is performed using the modified jacocoagent.jar file. This supports multi-round and multi-environment coverage monitoring, reducing manual intervention.
It has achieved automated code coverage monitoring, reducing manual operations and improving the accuracy and efficiency of coverage monitoring.
Smart Images

Figure CN118916272A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data monitoring, and in particular to a code coverage monitoring method and device. Background Art
[0002] Continuous integration based on K8s containerized deployment can ensure server resource utilization and improve test efficiency, but it also brings some challenges. Code coverage tools that rely on Jacoco need to introduce coverage collection tools into the image before collecting coverage information, and modify the application process startup command. When collecting coverage information, coverage data needs to be pulled through the configured Socket IP and port. Under the conditions of executing multiple rounds of tests in multiple applications and multiple environments, how to ensure coverage accuracy, reduce manual intervention in the front end of coverage tools, and obtain IP based on K8s dynamic orchestration, etc., there are challenges in terms of maintenance workload and mastery of Jacoco and K8s knowledge. Summary of the invention
[0003] In view of this, an object of the present invention is to provide a code coverage monitoring method and device to overcome the current problem that code coverage monitoring of applications cannot be automatically performed.
[0004] To achieve the above objectives, the present invention adopts the following technical solutions:
[0005] In a first aspect, the present application provides a code coverage monitoring method, comprising:
[0006] Package and deploy applications through a continuous integration platform, and the deployed applications will automatically register with the automated testing platform after startup;
[0007] Create a coverage monitoring task on the automated testing platform and determine the target application to be monitored;
[0008] The coverage monitoring task is started to monitor the code coverage of the target application.
[0009] Furthermore, in the above method, the step of packaging and deploying the application through a continuous integration platform and obtaining information on deploying the application includes:
[0010] Package and deploy the application through the continuous integration platform, and introduce the modified jacocoagent.jar file into the image during packaging;
[0011] The agent identifies and pushes the deployed application information and application name information to the database service registry.
[0012] Furthermore, in the method described above, the application information includes at least: application IP information, PORT information, operating environment information and application name information.
[0013] Furthermore, in the above method, the step of creating a coverage monitoring task on the automated testing platform and determining a target application to be monitored includes:
[0014] Create a coverage monitoring task on the automated testing platform, and select the target application, operating environment information, task timing collection time, branch name, and report filtering rule field information in the database service registry.
[0015] Furthermore, in the above method, starting the coverage monitoring task to monitor the code coverage of the target application includes:
[0016] Start the coverage monitoring task, support the restart of the tested service after interruption, perform multiple rounds of coverage real-time monitoring and periodic collection of coverage information for the target application, and multi-environment coverage real-time monitoring and periodic collection of coverage information, and support cross-environment inheritance and process failure reminder;
[0017] Merging multiple rounds of coverage and multiple environment test coverage of the target application;
[0018] The coverage information of the target application is refreshed according to the report filtering rule field information.
[0019] Furthermore, the above method further includes:
[0020] When the coverage information of the target application reaches the monitoring deadline, the coverage monitoring task is automatically stopped.
[0021] In a second aspect, the present application provides a code coverage monitoring device, including a processor and a memory, wherein the processor is connected to the memory:
[0022] Wherein, the processor is used to call and execute the program stored in the memory;
[0023] The memory is used to store the program, and the program is at least used to execute any one of the code coverage monitoring methods described above.
[0024] The beneficial effects of the present invention are:
[0025] This application first packages and deploys the application through a continuous integration platform. After the deployed application is started, it will automatically register with the automated testing platform, create a coverage monitoring task on the automated testing platform, determine the target application to be monitored, start the coverage monitoring task, and monitor the code coverage of the target application, thereby realizing automatic code coverage monitoring of the target application and reducing manual intervention. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0027] Figure 1 It is a flow chart provided by an embodiment of a code coverage monitoring method of the present invention;
[0028] Figure 2 It is a structural diagram provided by an embodiment of a code coverage monitoring device of the present invention. DETAILED DESCRIPTION
[0029] To make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be described in detail below. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other implementation methods obtained by ordinary technicians in this field without creative work belong to the scope of protection of the present invention.
[0030] Figure 1 This is a flowchart provided by an embodiment of a code coverage monitoring method of the present invention. Figure 1 , this embodiment may include the following steps:
[0031] S1. Package and deploy the application through the continuous integration platform. After the deployed application is started, it will be automatically registered to the automated testing platform.
[0032] S2. Create a coverage monitoring task on the automated testing platform and determine the target application that needs to be monitored.
[0033] S3. Start the coverage monitoring task to monitor the code coverage of the target application.
[0034] It should be noted that this embodiment realizes service packaging deployment of coverage functions, coverage data collection, classes and sources file download, report generation and process exception monitoring by transforming the Jacoco coverage tool and integrating the continuous integration platform, code management platform and automated testing platform.
[0035] It can be understood that this embodiment first packages and deploys the application through the continuous integration platform. After the deployed application is started, it will automatically register with the automated testing platform, create a coverage monitoring task on the automated testing platform, determine the target application to be monitored, start the coverage monitoring task, and monitor the code coverage of the target application, thereby realizing automatic code coverage monitoring of the target application and reducing manual intervention.
[0036] Preferably, step S1 comprises:
[0037] Package and deploy the application through the continuous integration platform, and introduce the modified jacocoagent.jar file into the image during packaging;
[0038] The agent identifies and pushes the information of the deployed application and the application name information to the database service registry.
[0039] Preferably, the application information includes at least: application IP information, PORT information, operating environment information and application name information.
[0040] It can be understood that the application is packaged and deployed through the continuous integration platform, in which the modified jacocoagent.jar file is introduced into the image during packaging, and the application is started to identify and push the application-related IP, port, operating environment, application name and other information to the database service registry through the agent.
[0041] Preferably, step S2 comprises:
[0042] Create a coverage monitoring task on the automated testing platform, and select the target application, operating environment information, task scheduled collection time, branch name, and report filtering rule field information in the database service registry.
[0043] Preferably, step S3 includes:
[0044] Start the coverage monitoring task, support the restart of the tested service after interruption, conduct multiple rounds of coverage real-time monitoring and periodic collection of coverage information for the target application, and multi-environment coverage real-time monitoring and periodic collection of coverage information, and support cross-environment inheritance and process failure reminders;
[0045] Merge multiple rounds of coverage and multi-environment test coverage of the target application;
[0046] Refresh the coverage information of the target application based on the report filtering rule field information.
[0047] Preferably, it also includes:
[0048] When the coverage information of the target application reaches the monitoring deadline, the coverage monitoring task is automatically stopped.
[0049] It is understandable that a coverage monitoring task is created on the automated testing platform. It includes selecting the application service and operating environment in the service registry, entering the task scheduled collection time, branch name, and report filtering rule field information, and starting the coverage monitoring task to collect coverage data regularly. It supports the merging of multiple rounds of test coverage and multiple environments for the same application. If an abnormality occurs during the period, an alarm will be issued, and manual intervention will be made to correct it if necessary. According to the report filtering rules, the coverage information will be refreshed regularly. If there is an inconsistency in the war version or a code change, the latest file will be triggered to be downloaded online. When the coverage information reaches the set target, it will be stopped manually or the coverage monitoring task will be automatically stopped when the time reaches the monitoring deadline. A coverage report can be generated at any time during the test process with one click.
[0050] The present invention also provides a code coverage monitoring device for implementing the above method embodiment. Figure 2 1 is a schematic diagram of a structure provided by an embodiment of a code coverage monitoring device of the present invention. Figure 2 As shown, the code coverage monitoring device of this embodiment includes a processor 21 and a memory 22, and the processor 21 is connected to the memory 22. The processor 21 is used to call and execute the program stored in the memory 22; the memory 22 is used to store the program, and the program is at least used to execute the code coverage monitoring method in the above embodiment.
[0051] The specific implementation scheme of the code coverage monitoring device provided in the embodiment of the present application can refer to the implementation scheme of the code coverage monitoring method in any of the above embodiments, which will not be repeated here.
[0052] It can be understood that the same or similar parts of the above embodiments can be referenced to each other, and the contents not described in detail in some embodiments can refer to the same or similar contents in other embodiments.
[0053] It should be noted that, in the description of the present invention, the terms "first", "second", etc. are only used for descriptive purposes and cannot be understood as indicating or implying relative importance. In addition, in the description of the present invention, unless otherwise specified, the meaning of "plurality" refers to at least two.
[0054] Any process or method description in a flowchart or otherwise described herein may be understood to represent a module, segment or portion of code that includes one or more executable instructions for implementing the steps of a specific logical function or process, and the scope of the preferred embodiments of the present invention includes alternative implementations in which functions may not be performed in the order shown or discussed, including performing functions in a substantially simultaneous manner or in the reverse order depending on the functions involved, which should be understood by those skilled in the art to which the embodiments of the present invention belong.
[0055] It should be understood that the various parts of the present invention can be implemented by hardware, software, firmware or a combination thereof. In the above-mentioned embodiments, a plurality of steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented by hardware, as in another embodiment, it can be implemented by any one of the following technologies known in the art or their combination: a discrete logic circuit having a logic gate circuit for implementing a logic function for a data signal, a dedicated integrated circuit having a suitable combination of logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.
[0056] A person skilled in the art may understand that all or part of the steps in the method for implementing the above-mentioned embodiment may be completed by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, which, when executed, includes one or a combination of the steps of the method embodiment.
[0057] In addition, each functional unit in each embodiment of the present invention may be integrated into a processing module, or each unit may exist physically separately, or two or more units may be integrated into one module. The above-mentioned integrated module may be implemented in the form of hardware or in the form of a software functional module. If the integrated module is implemented in the form of a software functional module and sold or used as an independent product, it may also be stored in a computer-readable storage medium.
[0058] The storage medium mentioned above can be a read-only memory, a magnetic disk or an optical disk, etc.
[0059] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "examples", "specific examples", or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner.
[0060] Although the embodiments of the present invention have been shown and described above, it is to be understood that the above embodiments are exemplary and are not to be construed as limitations of the present invention. A person skilled in the art may change, modify, replace and vary the above embodiments within the scope of the present invention.
Claims
1. A code coverage monitoring method, characterized in that: include: Package and deploy applications through a continuous integration platform, and the deployed applications will automatically register with the automated testing platform after startup; Creating a coverage monitoring task on the automated testing platform and determining a target application to be monitored; The coverage monitoring task is started to monitor the code coverage of the target application.
2. The method according to claim 1, characterized in that The packaging and deployment of the application through the continuous integration platform, and obtaining the information of deploying the application, include: Package and deploy the application through the continuous integration platform, and introduce the modified jacocoagent.jar file into the image during packaging; The agent identifies and pushes the deployed application information and application name information to the database service registry.
3. The method according to claim 2, characterized in that The application information includes at least: application IP information, PORT information, operating environment information and application name information.
4. The method according to claim 3, characterized in that The creation of coverage monitoring tasks on the automated testing platform and determination of target applications to be monitored include: Create a coverage monitoring task on the automated testing platform, and select the target application, operating environment information, task timing collection time, branch name, and report filtering rule field information in the database service registry.
5. The method according to claim 4, characterized in that The starting the coverage monitoring task to monitor the code coverage of the target application includes: Start the coverage monitoring task, support the restart of the tested service after interruption, perform multiple rounds of coverage real-time monitoring and periodic collection of coverage information for the target application, and multi-environment coverage real-time monitoring and periodic collection of coverage information, and support cross-environment inheritance and process failure reminder; Merging multiple rounds of coverage and multiple environment test coverage of the target application; The coverage information of the target application is refreshed according to the report filtering rule field information.
6. The method according to claim 5, characterized in that Also includes: When the coverage information of the target application reaches the monitoring deadline, the coverage monitoring task is automatically stopped.
7. A code coverage monitoring device, characterized in that: The invention comprises a processor and a memory, wherein the processor is connected to the memory: Wherein, the processor is used to call and execute the program stored in the memory; The memory is used to store the program, and the program is at least used to execute the code coverage monitoring method described in any one of claims 1-6.
