CN116010260A - Code coverage rate acquisition method, device and equipment - Google Patents

Code coverage rate acquisition method, device and equipment Download PDF

Info

Publication number
CN116010260A
CN116010260A CN202211658891.0A CN202211658891A CN116010260A CN 116010260 A CN116010260 A CN 116010260A CN 202211658891 A CN202211658891 A CN 202211658891A CN 116010260 A CN116010260 A CN 116010260A
Authority
CN
China
Prior art keywords
coverage
coverage rate
container
file
script
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202211658891.0A
Other languages
Chinese (zh)
Inventor
林韦妍
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Baidu Netcom Science and Technology Co Ltd
Original Assignee
Beijing Baidu Netcom Science and Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Baidu Netcom Science and Technology Co Ltd filed Critical Beijing Baidu Netcom Science and Technology Co Ltd
Priority to CN202211658891.0A priority Critical patent/CN116010260A/en
Publication of CN116010260A publication Critical patent/CN116010260A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Debugging And Monitoring (AREA)

Abstract

The disclosure provides a code coverage rate acquisition method, device and equipment, relates to the field of artificial intelligence, in particular to cloud computing and cloud protogenesis technology, and can be applied to an intelligent cloud scene. One embodiment of the method comprises the following steps: receiving dynamic parameters input by a user; performing coverage rate pile insertion based on the dynamic parameters; and carrying out coverage statistics based on the dynamic parameters, and generating a coverage report. The embodiment realizes automatic acquisition of code coverage rate without perception.

Description

Code coverage rate acquisition method, device and equipment
Technical Field
The disclosure relates to the field of artificial intelligence, in particular to cloud computing and cloud protogenesis technology, which can be applied to intelligent cloud scenes.
Background
Code coverage is a measure in software testing that describes the proportion and extent to which source code is tested in a program, the resulting proportion being referred to as code coverage. The code coverage rate reflects an important index of the coverage degree of the test case to the tested software, is a reference value used for measuring the test integrity, and can evaluate whether the test is sufficient or not through the code coverage rate data.
The prior art uses a coverage tool such as jacoco to collect test coverage. At present, the pile inserting mode for collecting the code coverage rate in common use mainly comprises the following two modes: firstly, adding a java agent of jacoco by modifying a dock mirror image to realize pile insertion; secondly, inserting piles by modifying a dock-composition.yaml file of a dock and adding a java agent of a jacoco. The English of jacoco is called Java Code Coverage Library, and the java code coverage rate tool is provided. dock is an open-source application container engine. The java agent is a parameter of the java command. The dock-composition. YAML is a YAML format template file.
Disclosure of Invention
The embodiment of the disclosure provides a code coverage rate acquisition method, a device, equipment, a storage medium and a program product.
In a first aspect, an embodiment of the present disclosure provides a code coverage rate acquisition method, including: receiving dynamic parameters input by a user; performing coverage rate pile insertion based on the dynamic parameters; and carrying out coverage statistics based on the dynamic parameters, and generating a coverage report.
In a second aspect, an embodiment of the present disclosure provides a code coverage rate acquisition device, including: a receiving module configured to receive dynamic parameters input by a user; the pile inserting module is configured to perform coverage rate pile inserting based on the dynamic parameters; and the statistics module is configured to carry out coverage statistics based on the dynamic parameters and generate a coverage report.
In a third aspect, an embodiment of the present disclosure proposes an electronic device, including: at least one processor; and a memory communicatively coupled to the at least one processor; wherein the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the method as described in any one of the implementations of the first aspect.
In a fourth aspect, embodiments of the present disclosure provide a non-transitory computer-readable storage medium storing computer instructions for causing a computer to perform a method as described in any one of the implementations of the first aspect.
In a fifth aspect, embodiments of the present disclosure propose a computer program product comprising a computer program which, when executed by a processor, implements a method as described in any of the implementations of the first aspect.
According to the code coverage rate acquisition method provided by the embodiment of the disclosure, the non-perception full-automatic code coverage rate acquisition for java containerization application is realized based on jacaco in a k8s distributed environment.
It should be understood that the description in this section is not intended to identify key or critical features of the embodiments of the disclosure, nor is it intended to be used to limit the scope of the disclosure. Other features of the present disclosure will become apparent from the following specification.
Drawings
Other features, objects and advantages of the present disclosure will become more apparent upon reading of the detailed description of non-limiting embodiments made with reference to the following drawings. The drawings are for a better understanding of the present solution and are not to be construed as limiting the present disclosure. Wherein:
FIG. 1 is a flow chart of one embodiment of a code coverage acquisition method according to the present disclosure;
FIG. 2 is a flow chart of yet another embodiment of a code coverage acquisition method according to the present disclosure;
FIG. 3 is a scene diagram of a code coverage acquisition method in which embodiments of the present disclosure may be implemented;
FIG. 4 is a schematic structural view of one embodiment of a code coverage acquisition device according to the present disclosure;
fig. 5 is a block diagram of an electronic device used to implement a code coverage acquisition method of an embodiment of the present disclosure.
Detailed Description
Exemplary embodiments of the present disclosure are described below in conjunction with the accompanying drawings, which include various details of the embodiments of the present disclosure to facilitate understanding, and should be considered as merely exemplary. Accordingly, one of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the present disclosure. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
It should be noted that, without conflict, the embodiments of the present disclosure and features of the embodiments may be combined with each other. The present disclosure will be described in detail below with reference to the accompanying drawings in conjunction with embodiments.
FIG. 1 illustrates a flow chart of one embodiment of a code coverage acquisition method according to the present disclosure. The code coverage rate acquisition method comprises the following steps:
step 101, receiving dynamic parameters input by a user.
In this embodiment, the coverage tool may receive dynamic parameters entered by the user.
Typically, the coverage tool runs on a central control computer and is remotely operated via the python third party package paramiko module. The user can input dynamic parameters, and the coverage rate tool running on the central control computer can acquire the dynamic parameters input by the user from a continuous delivery platform (such as an Ipipe platform). Wherein the dynamic parameters are json string format comprising: cluster login information, code library information (such as Icode code library information), branch information, commit identification information (commit id information), service types (such as jar, tomcat), service progress flags, compression package in-container paths (such as jar/war package in-container paths), in-container startup script paths (such as jar/war container startup script paths), source code package relative project root directory paths, files without coverage statistics, scan package scope, agent communication ports (agent communication ports), project version information, and the like.
Wherein python is a computer programming language. Paramiko is a module for remote control. The ip platform can provide continuous delivery capability, help enterprises to continuously improve the quality and efficiency of application delivery, and complete automation from code submission to application delivery through construction automation, test automation and deployment automation. json (JavaScript Object Notation, JS object numbered musical notation) is a lightweight data exchange format. The Icode platform is an enterprise-level code service platform that provides a series of functions in the form of code cores, such as code hosting, code review, code scanning, code searching, and the like. tomcat is a lightweight application server. jar and war are both compressed files, jar is an archive file of a class, and war is a web application.
And 102, performing coverage rate pile insertion based on the dynamic parameters.
In this embodiment, the coverage tool may perform coverage instrumentation based on dynamic parameters.
Typically, after the dynamic parameters input by the user are obtained, the coverage tool may pull the application source code in the Icode platform and communicate with the APP (application) running in the k8s cluster to complete multi-node coverage instrumentation.
The k8s is known as Kubernetes, is an open-source platform for building a distributed cluster application environment, and can conveniently deploy distributed applications based on docker and docker cooperation.
And step 103, carrying out coverage statistics based on the dynamic parameters, and generating a coverage report.
In this embodiment, the coverage tool may perform coverage statistics based on the dynamic parameters, generating coverage reports.
Generally, after the dynamic parameters input by the user are obtained, the coverage tool can pull the application source codes in the Icode platform and communicate with the APP running in the k8s cluster, so as to complete multi-node coverage instrumentation and final coverage data collection and generate a coverage report.
Typically, the coverage tool can push coverage reports to the Cov platform for report presentation. The Cov platform can provide a unified, standard, efficient and intelligent single-test construction infrastructure, provides comprehensive code coverage dimension measurement for various tests, and supports report data pushing and storage comparison functions.
In some embodiments, to enrich the push manner of coverage reports, coverage reports may be pushed by at least one of:
firstly, the coverage rate report is pushed in real time by calling the mail notification function.
In general, real-time mail notification can be achieved by invoking a mail notification function on the Ipipe platform.
Secondly, pushing coverage rate reports by calling a report pushing interface.
Generally, uploading and management of reports can be achieved by invoking a report pushing interface provided by the Cov platform.
According to the code coverage rate acquisition method provided by the embodiment of the disclosure, the non-perception full-automatic code coverage rate acquisition for java containerization application is realized based on jacaco in a k8s distributed environment. And in addition, by combining an Ipipe platform, an Icode platform and a Cov platform, full-automatic execution is realized, the problems that the jacoco environment is more complicated to build, source codes are depended on and the like are solved, and manual participation is not needed in the whole process.
With continued reference to fig. 2, a flow chart of yet another embodiment of a code coverage acquisition method according to the present disclosure is shown. The code coverage rate acquisition method comprises the following steps:
step 201, receiving dynamic parameters input by a user.
In this embodiment, the specific operation of step 201 is described in detail in step 101 in the embodiment shown in fig. 1, and will not be described herein.
Step 202, pulling source codes of the micro services of the items according to the code base information.
In this embodiment, the source code of each micro-service of the item may be pulled according to the code base information in the dynamic parameters.
Generally, after acquiring the dynamic parameters input by the user from the Ipipe, the coverage tool can pull the source codes of all the micro services related to the project to the central control computer according to the Icode code base information.
Step 203, generating a code increment file according to the submitting identification information.
In this embodiment, the code delta file may be generated based on commit identification information in the dynamic parameters.
Typically, two submitted commit IDs entered by the user (i.e., commit ID1 and commit ID 2) may be included in the dynamic parameters. Since the commit ID records code change information, a code delta file can be generated from the commit ID1 and the commit ID 2.
And 204, distributing the coverage tool and the source code to each node containing the application process identifier in the cluster corresponding to the cluster login information.
In this embodiment, the coverage tool and the source code are distributed to each node including the application process identifier in the cluster corresponding to the cluster login information.
In general, the coverage tool and the source code are compressed and then remotely distributed to nodes containing application process identifiers in the clusters corresponding to the cluster login information. The cluster corresponding to the cluster login information is a tested cluster. The node containing the application process identity is the node where the APP is installed.
And 205, positioning a container identifier according to the application process identifier, and copying the coverage tool and the source code into a container corresponding to the container identifier.
In this embodiment, the container identifier is located according to the application process identifier, and the coverage tool and the source code may be copied into the container corresponding to the container identifier.
Typically, the container identifier may be located by a docker ps command. The coverage tool and source code are copied into the container interior by the docker cp command.
And 206, dynamically replacing variables in the constructed template file in the container according to the service type, the service process mark, the path of the compressed package in the container, the path of the starting script in the container, the path of the source code package relative to the engineering root directory, the file without coverage statistics, the scanning package range and the proxy communication port.
In this embodiment, according to the service type, the service process flag, the path of the compressed packet in the container, the path of the startup script in the container, the path of the source code packet relative to the engineering root directory, the file without coverage statistics, the scanning packet range and the proxy communication port, the variables in the template file can be dynamically replaced and constructed in the container.
In general, according to a service type jar/tomcat, a service process mark and a jar/war package path input by a user in a container, a jar/war container starting script path, a source code package relative to an engineering root directory path, a file which is excluded from coverage statistics when a report is generated, a scanning package range and a agent communication port, and dynamically replacing variables in a build.xml template file in the container.
Step 207, dynamically writing the agent of the coverage tool into the in-container startup script file according to the in-container startup script path, and restarting the container.
In this embodiment, according to the in-container startup script path, the agent of the coverage tool may be dynamically written into the in-container startup script file, and the container restarted.
Normally, the jacobiont is dynamically written into a jar/war container internal starting script file input by a user, and then the container is restarted through a dock restart command, so that the whole pile inserting process is completed.
And step 208, dynamically generating a coverage rate file script and a coverage rate report script in the container according to the service type.
In this embodiment, the coverage file script and the coverage report script may be dynamically generated in the container according to the service type.
In general, depending on the service type jar/tomcat, an ant_dump. Sh and an ant_report. Sh may be dynamically generated within the container.
Step 209, executing the coverage rate file script on each node containing the application process identifier in the cluster to obtain the coverage rate file of each node.
In this embodiment, on each node in the cluster including the application process identifier, a coverage rate file script may be executed to obtain a coverage rate file of each node.
Typically, an ant_dump. Sh is uploaded at each node of the cluster, and a jacoco. Exec file generated at all nodes is obtained.
And step 210, selecting a master node from the cluster, and distributing coverage rate files of other nodes of the cluster to the master node.
In this embodiment, the master node is selected from the cluster, and coverage files of other nodes of the cluster may be distributed to the master node.
In general, a first node input by a user is selected as a main node, jacoco.exec files on other nodes are uniformly transmitted to a central control computer node, and then distributed to the main node by the central control computer.
Step 211, executing a coverage report script on the master node based on the coverage files of the nodes to generate full and incremental coverage reports of the micro services.
In this embodiment, a coverage report script is executed on the master node based on the coverage files of each node, generating full and incremental coverage reports for each micro-service.
Typically, an ant_report. Sh is executed on the master node, which can generate full and incremental coverage reports for each micro-service. Here, the incremental report generating function may invoke the capabilities provided by the Cov platform.
And step 212, summarizing the total and incremental coverage reports of each micro service according to the project dimension, and generating a project coverage report.
In this embodiment, the project coverage report may be generated by aggregating the full and incremental coverage reports of each micro service according to the project dimension.
Typically, the report in the container is docker cp to the physical machine and then remotely returned to the central control machine. And on the central control computer, acquiring coverage rate data of all micro services by analyzing an html report form according to project dimension through a character string, integrating all the micro service data, calculating an integral index value according to a formula, and archiving under a folder named by a project version.
In some embodiments, to avoid coverage data loss problems caused by service instability, POD drift during test execution, coverage file scripts may be executed on each node at regular intervals. And simultaneously, scanning the service progress state of each node, and repeating coverage rate instrumentation for the nodes which do not contain the target command parameters in the service progress state.
By setting a timing task, the timing dump outputs a jacoco.exec file. And simultaneously scanning the service progress state, and whether the service progress state contains a java agent keyword or not. If not, indicating that the unpinning or the unpinning failed, the unpinning needs to be performed again. By dynamically monitoring the pile inserting state, the problems of massive loss of code coverage rate data caused by restarting, breakdown and POD drift of the service are avoided, and the usability is improved.
As can be seen from fig. 2, the code coverage rate acquisition method in this embodiment highlights the instrumentation step and the statistics step compared with the embodiment corresponding to fig. 1. Therefore, the scheme described in the embodiment can realize automatic collection and combination of code coverage rates of a plurality of java micro services in a k8s distributed environment. The non-perception type pile inserting of the container is realized, the docekr mirror image or the docker-compound. Yaml does not need to be modified before the mirror image is constructed, the research personnel does not perceive, and the consistency of research, development, test and release is maintained. Supporting project-level coverage reporting, where a project contains multiple micro-services, the overall coverage can be counted in terms of project dimensions. The method effectively solves the problem of statistics of the coverage rate of the back-end codes after the smart city products are migrated to the cloud primary environment. The capacity of full-automatic statistics under the distributed k8s environment without invasion and perception is realized, and the product quality and iteration efficiency are greatly improved. The system is applied to products such as smart city enterprises, management platforms, visual workstations, one-person-one-file systems, portrait systems, view library systems and the like.
For ease of understanding, fig. 3 is a scene diagram of a code coverage acquisition method in which embodiments of the present disclosure may be implemented. As shown in FIG. 3, the coverage tool contains a total of 4 technical implementations of universal modules, including coverage instrumentation, coverage statistics, report pushing, and dynamic monitoring, respectively.
Coverage rate pile inserting: and after the dynamic parameters input by the user are obtained from the Ipipe platform, the source codes of all the micro services related to the project are pulled to the central control computer from the Icode code bin library. A code delta file is generated based on the two submitted compittIDs entered by the user. And then the coverage tool and the source code are remotely distributed to the nodes of the tested cluster after being compressed, and are copied into the container through a docker cp command after being positioned to the container ID through the docker ps command. And then dynamically generating a build.xml template file, dynamically writing the jacocoagent into a jar/war container starting script file input by a user, and restarting the container through a dock restart command, thereby completing the whole pile inserting process.
And (5) coverage rate statistics: after the dynamic parameters input by the user are obtained from the Ipipe platform, the ant_dump.sh and the ant_report.sh are dynamically generated in the container according to the service type jar/tomcat. And executing the ant_dump.sh on each node of the cluster to obtain jacoco.exec files generated on all the nodes. And selecting the first node input by the user as a main node, uniformly transmitting jacoco.exec files on other nodes to the central control computer node, and then distributing the jacoco.exec files to the main node by the central control computer. Executing ant_report.sh on the master node, generating full and incremental coverage reports for each micro-service. And then the report docker cp in the container is sent to the physical machine and then remotely returned to the central control machine. And on the central control computer, acquiring coverage rate data of all micro services by analyzing an html report form according to project dimension through a character string, integrating all the micro service data, calculating an integral index value according to a formula, and archiving under a folder named by a project version.
Report pushing: realizing real-time mail notification by calling a mail notification function on an ip platform; and uploading and managing the report are realized by calling a report pushing interface provided by the Cov platform.
Dynamic detection: setting a timing task, timing dump out of the jacoco.exec file, simultaneously scanning the service process state, and if the service process state contains a java agent keyword, informing the corresponding test classmates by mail, and simultaneously completing coverage rate instrumentation.
With further reference to fig. 4, as an implementation of the method shown in the foregoing figures, the present disclosure provides an embodiment of a code coverage rate acquisition apparatus, where the embodiment of the apparatus corresponds to the embodiment of the method shown in fig. 1, and the apparatus may be specifically applied in various electronic devices.
As shown in fig. 4, the code coverage rate acquisition apparatus 400 of the present embodiment may include: a receiving module 401, a pile inserting module 402 and a counting module 403. Wherein, the receiving module 401 is configured to receive dynamic parameters input by a user; a instrumentation module 402 configured to perform coverage instrumentation based on the dynamic parameters; the statistics module 403 is configured to perform coverage statistics based on the dynamic parameters, and generate coverage reports.
In the present embodiment, in the code coverage rate acquisition apparatus 400: the specific processing and the technical effects of the receiving module 401, the pile inserting module 402 and the statistics module 403 may refer to the relevant descriptions of steps 101 to 103 in the corresponding embodiment of fig. 1, and are not repeated here.
In some alternative implementations of the present embodiment, the dynamic parameters include: cluster login information, code library information, branch information, submission identification information, service type, service process mark, path of compressed package in container, path of starting script in container, path of source code package relative engineering root directory, file without coverage rate statistics, scanning package range, proxy communication port and project version information.
In some alternative implementations of the present embodiment, the instrumentation module 402 is further configured to: pulling source codes of all micro services of the project according to the code base information; generating a code increment file according to the submitting identification information; distributing a coverage rate tool and a source code to each node containing an application process identifier in a cluster corresponding to the cluster login information; positioning a container identifier according to the application process identifier, and copying a coverage rate tool and a source code into a container corresponding to the container identifier; according to the service type, the service process mark, the path of the compressed package in the container, the path of the starting script in the container, the path of the source code package relative to the engineering root directory, the file without coverage statistics, the scanning package range and the proxy communication port, dynamically replacing and constructing the variables in the template file in the container; and dynamically writing the agent of the coverage rate tool into the in-container startup script file according to the in-container startup script path, and restarting the container.
In some alternative implementations of the present embodiment, the statistics module 403 is further configured to: dynamically generating a coverage rate file script and a coverage rate report script in a container according to the service type; executing a coverage rate file script on each node containing an application process identifier in the cluster to obtain a coverage rate file of each node; selecting a master node from the cluster, and distributing coverage rate files of other nodes of the cluster to the master node; executing a coverage report script on the master node based on coverage files of all nodes, and generating full and incremental coverage reports of all micro services; and summarizing the total and incremental coverage rate reports of each micro service according to the project dimension, and generating a project coverage rate report.
In some alternative implementations of the present embodiment, coverage file scripts are executed on each node at regular time; the code coverage rate acquisition device 400 further includes: the scanning module is configured to scan the service progress state of each node; and the re-instrumentation module is configured to re-perform coverage rate instrumentation on the nodes which do not contain the target command parameters in the service process state.
In some optional implementations of the present embodiment, the code coverage rate acquisition apparatus 400 further includes: pushing coverage rate reports in real time by calling a mail notification function; and/or pushing the coverage report by invoking the report pushing interface.
In the technical scheme of the disclosure, the related processes of collecting, storing, using, processing, transmitting, providing, disclosing and the like of the personal information of the user accord with the regulations of related laws and regulations, and the public order colloquial is not violated.
According to embodiments of the present disclosure, the present disclosure also provides an electronic device, a readable storage medium and a computer program product.
Fig. 5 illustrates a schematic block diagram of an example electronic device 500 that may be used to implement embodiments of the present disclosure. Electronic devices are intended to represent various forms of digital computers, such as laptops, desktops, workstations, personal digital assistants, servers, blade servers, mainframes, and other appropriate computers. The electronic device may also represent various forms of mobile devices, such as personal digital processing, cellular telephones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions, are meant to be exemplary only, and are not meant to limit implementations of the disclosure described and/or claimed herein.
As shown in fig. 5, the apparatus 500 includes a computing unit 501 that can perform various suitable actions and processes according to a computer program stored in a Read Only Memory (ROM) 502 or a computer program loaded from a storage unit 508 into a Random Access Memory (RAM) 503. In the RAM 503, various programs and data required for the operation of the device 500 can also be stored. The computing unit 501, ROM 502, and RAM 503 are connected to each other by a bus 504. An input/output (I/O) interface 505 is also connected to bus 504.
Various components in the device 500 are connected to the I/O interface 505, including: an input unit 506 such as a keyboard, a mouse, etc.; an output unit 507 such as various types of displays, speakers, and the like; a storage unit 508 such as a magnetic disk, an optical disk, or the like; and a communication unit 509 such as a network card, modem, wireless communication transceiver, etc. The communication unit 509 allows the device 500 to exchange information/data with other devices via a computer network such as the internet and/or various telecommunication networks.
The computing unit 501 may be a variety of general and/or special purpose processing components having processing and computing capabilities. Some examples of computing unit 501 include, but are not limited to, a Central Processing Unit (CPU), a Graphics Processing Unit (GPU), various specialized Artificial Intelligence (AI) computing chips, various computing units running machine learning model algorithms, a Digital Signal Processor (DSP), and any suitable processor, controller, microcontroller, etc. The computing unit 501 performs the respective methods and processes described above, such as a code coverage rate acquisition method. For example, in some embodiments, the code coverage acquisition method may be implemented as a computer software program tangibly embodied on a machine-readable medium, such as the storage unit 508. In some embodiments, part or all of the computer program may be loaded and/or installed onto the device 500 via the ROM 502 and/or the communication unit 509. When the computer program is loaded into RAM 503 and executed by the computing unit 501, one or more steps of the code coverage acquisition method described above may be performed. Alternatively, in other embodiments, the computing unit 501 may be configured to perform the code coverage acquisition method by any other suitable means (e.g. by means of firmware).
Various implementations of the systems and techniques described here above may be implemented in digital electronic circuitry, integrated circuit systems, field Programmable Gate Arrays (FPGAs), application Specific Integrated Circuits (ASICs), application Specific Standard Products (ASSPs), systems On Chip (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and/or combinations thereof. These various embodiments may include: implemented in one or more computer programs, the one or more computer programs may be executed and/or interpreted on a programmable system including at least one programmable processor, which may be a special purpose or general-purpose programmable processor, that may receive data and instructions from, and transmit data and instructions to, a storage system, at least one input device, and at least one output device.
Program code for carrying out methods of the present disclosure may be written in any combination of one or more programming languages. These program code may be provided to a processor or controller of a general purpose computer, special purpose computer, or other programmable data processing apparatus such that the program code, when executed by the processor or controller, causes the functions/operations specified in the flowchart and/or block diagram to be implemented. The program code may execute entirely on the machine, partly on the machine, as a stand-alone software package, partly on the machine and partly on a remote machine or entirely on the remote machine or server.
In the context of this disclosure, a machine-readable medium may be a tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. The machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
To provide for interaction with a user, the systems and techniques described here can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to a user; and a keyboard and pointing device (e.g., a mouse or trackball) by which a user can provide input to the computer. Other kinds of devices may also be used to provide for interaction with a user; for example, feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form, including acoustic input, speech input, or tactile input.
The systems and techniques described here can be implemented in a computing system that includes a background component (e.g., as a data server), or that includes a middleware component (e.g., an application server), or that includes a front-end component (e.g., a user computer having a graphical user interface or a web browser through which a user can interact with an implementation of the systems and techniques described here), or any combination of such background, middleware, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: local Area Networks (LANs), wide Area Networks (WANs), and the internet.
The computer system may include a client and a server. The client and server are typically remote from each other and typically interact through a communication network. The relationship of client and server arises by virtue of computer programs running on the respective computers and having a client-server relationship to each other. The server may be a cloud server, a server of a distributed system, or a server incorporating a blockchain.
It should be appreciated that various forms of the flows shown above may be used to reorder, add, or delete steps. For example, the steps recited in the present disclosure may be performed in parallel, sequentially, or in a different order, provided that the desired results of the technical solutions provided by the present disclosure are achieved, and are not limited herein.
The above detailed description should not be taken as limiting the scope of the present disclosure. It will be apparent to those skilled in the art that various modifications, combinations, sub-combinations and alternatives are possible, depending on design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present disclosure are intended to be included within the scope of the present disclosure.

Claims (15)

1. A code coverage rate acquisition method comprising:
receiving dynamic parameters input by a user;
performing coverage rate pile insertion based on the dynamic parameters;
and carrying out coverage statistics based on the dynamic parameters, and generating a coverage report.
2. The method of claim 1, wherein the dynamic parameters comprise: cluster login information, code library information, branch information, submission identification information, service type, service process mark, path of compressed package in container, path of starting script in container, path of source code package relative engineering root directory, file without coverage rate statistics, scanning package range, proxy communication port and project version information.
3. The method of claim 2, wherein the performing coverage instrumentation based on the dynamic parameters comprises:
pulling source codes of all micro services of the project according to the code library information;
generating a code increment file according to the submitting identification information;
distributing a coverage rate tool and the source code to each node containing the application process identifier in a cluster corresponding to the cluster login information;
positioning a container identifier according to the application process identifier, and copying the coverage rate tool and the source code into a container corresponding to the container identifier;
dynamically replacing variables in a template file in the container according to the service type, the service process mark, the path of the compressed packet in the container, the path of the starting script in the container, the path of the source code packet relative to the engineering root directory, the file without coverage statistics, the scanning packet range and the proxy communication port;
and dynamically writing the agent of the coverage rate tool into a startup script file in the container according to the startup script path in the container, and restarting the container.
4. The method of claim 3, wherein the generating a coverage report based on the dynamic parameter coverage statistics comprises:
dynamically generating a coverage rate file script and a coverage rate report script in the container according to the service type;
executing the coverage rate file script on each node containing the application process identifier in the cluster to obtain a coverage rate file of each node;
selecting a master node from the cluster, and distributing coverage rate files of other nodes of the cluster to the master node;
executing the coverage report script on the master node based on coverage files of all nodes, and generating full and incremental coverage reports of all micro services;
and summarizing the total and incremental coverage rate reports of each micro service according to the project dimension, and generating a project coverage rate report.
5. The method of claim 4, wherein the coverage file script is executed on each node at regular time; and
the method further comprises the steps of:
scanning the service progress state of each node;
and re-performing coverage rate instrumentation on the nodes which do not contain the target command parameters in the service process state.
6. The method of any of claims 1-5, wherein the method further comprises:
pushing the coverage rate report in real time by calling a mail notification function; and/or
Pushing the coverage rate report by calling a report pushing interface.
7. A code coverage rate acquisition device comprising:
a receiving module configured to receive dynamic parameters input by a user;
the pile inserting module is configured to perform coverage rate pile inserting based on the dynamic parameters;
and the statistics module is configured to carry out coverage statistics based on the dynamic parameters and generate a coverage report.
8. The apparatus of claim 7, wherein the dynamic parameters comprise: cluster login information, code library information, branch information, submission identification information, service type, service process mark, path of compressed package in container, path of starting script in container, path of source code package relative engineering root directory, file without coverage rate statistics, scanning package range, proxy communication port and project version information.
9. The apparatus of claim 8, wherein the instrumentation module is further configured to:
pulling source codes of all micro services of the project according to the code library information;
generating a code increment file according to the submitting identification information;
distributing a coverage rate tool and the source code to each node containing the application process identifier in a cluster corresponding to the cluster login information;
positioning a container identifier according to the application process identifier, and copying the coverage rate tool and the source code into a container corresponding to the container identifier;
dynamically replacing variables in a template file in the container according to the service type, the service process mark, the path of the compressed packet in the container, the path of the starting script in the container, the path of the source code packet relative to the engineering root directory, the file without coverage statistics, the scanning packet range and the proxy communication port;
and dynamically writing the agent of the coverage rate tool into a startup script file in the container according to the startup script path in the container, and restarting the container.
10. The apparatus of claim 9, wherein the statistics module is further configured to:
dynamically generating a coverage rate file script and a coverage rate report script in the container according to the service type;
executing the coverage rate file script on each node containing the application process identifier in the cluster to obtain a coverage rate file of each node;
selecting a master node from the cluster, and distributing coverage rate files of other nodes of the cluster to the master node;
executing the coverage report script on the master node based on coverage files of all nodes, and generating full and incremental coverage reports of all micro services;
and summarizing the total and incremental coverage rate reports of each micro service according to the project dimension, and generating a project coverage rate report.
11. The apparatus of claim 10, wherein the coverage file script is executed on each node at regular time; and
the apparatus further comprises:
the scanning module is configured to scan the service progress state of each node;
and the re-instrumentation module is configured to re-perform coverage rate instrumentation on the nodes which do not contain the target command parameters in the service process state.
12. The apparatus of any of claims 7-11, wherein the apparatus further comprises:
pushing the coverage rate report in real time by calling a mail notification function; and/or
Pushing the coverage rate report by calling a report pushing interface.
13. An electronic device, comprising:
at least one processor; and
a memory communicatively coupled to the at least one processor; wherein,,
the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-6.
14. A non-transitory computer readable storage medium storing computer instructions for causing the computer to perform the method of any one of claims 1-6.
15. A computer program product comprising a computer program which, when executed by a processor, implements the method according to any of claims 1-6.
CN202211658891.0A 2022-12-22 2022-12-22 Code coverage rate acquisition method, device and equipment Pending CN116010260A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211658891.0A CN116010260A (en) 2022-12-22 2022-12-22 Code coverage rate acquisition method, device and equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211658891.0A CN116010260A (en) 2022-12-22 2022-12-22 Code coverage rate acquisition method, device and equipment

Publications (1)

Publication Number Publication Date
CN116010260A true CN116010260A (en) 2023-04-25

Family

ID=86037612

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211658891.0A Pending CN116010260A (en) 2022-12-22 2022-12-22 Code coverage rate acquisition method, device and equipment

Country Status (1)

Country Link
CN (1) CN116010260A (en)

Similar Documents

Publication Publication Date Title
CN107515826B (en) Method, device, system, equipment and storage medium for accurately recommending test cases
CN108984388B (en) Method and terminal equipment for generating automatic test case
CN109684188B (en) Test method and device
CN107302476B (en) Automatic testing method and system for testing asynchronous interactive system
WO2022179034A1 (en) Automatic testing method and apparatus, electronic device, and storage medium
US20230185702A1 (en) Method and Apparatus for Generating and Applying Deep Learning Model based on Deep Learning Framework
CN113076253A (en) Test method and test device
US11163673B1 (en) Enhanced testing by automated reuse of test metrics
CN113377665A (en) Container technology-based testing method and device, electronic equipment and storage medium
CN109408309A (en) The test method and device of multiple terminals
EP3923155A2 (en) Method and apparatus for processing snapshot, device, medium and product
US20240061759A1 (en) Automatic test method and apparatus, electronic device, and storage medium
CN112559525A (en) Data checking system, method, device and server
CN115129574A (en) Code testing method and device
CN116010260A (en) Code coverage rate acquisition method, device and equipment
CN109814911A (en) Method, apparatus, computer equipment and storage medium for Manage Scripts program
CN112948195B (en) Interface testing method, device, electronic equipment and storage medium
CN114138762A (en) Data processing method, device, storage medium and terminal
CN113434382A (en) Database performance monitoring method and device, electronic equipment and computer readable medium
CN114218313A (en) Data management method, device, electronic equipment, storage medium and product
CN113127357A (en) Unit testing method, device, equipment, storage medium and program product
CN112650815A (en) Method and device for synchronizing environmental data, storage medium and electronic device
US11797388B1 (en) Systems and methods for lossless network restoration and syncing
CN114860247A (en) Data processing method, device, equipment and storage medium
CN114238149A (en) Batch testing method of accounting system, electronic device and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination