Code coverage rate detection method, system and equipment and storage medium

By inserting code in the front-end program and collecting runtime data, and calculating code coverage, the problem of granularity and cost of redundant code detection in the existing technology is solved, and efficient code optimization and quality improvement are achieved.

CN118567977APending Publication Date: 2024-08-30CTRIP TRAVEL NETWORK TECH SHANGHAI0
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410643965.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-05-22
Publication Date
2024-08-30

AI Technical Summary

Technical Problem

When detecting redundant code in front-end programs, the existing technology has a large granularity and cannot add buried points within each method, which increases maintenance costs. Moreover, the generated coverage report cannot be used as a reliable basis for optimization in a production environment. .

Method used

By identifying method class function declarations in the source code of the front-end program, instrumenting the code and constructing instrumentation data, inserting the collection script to collect runtime code in real time, and analyzing the non-running code interval on the server side, calculating code coverage.

Benefits of technology

It realizes automated and universal front-end code coverage detection, reduces resource waste, improves detection efficiency, can accurately locate and clean up online redundant code, and improves code running quality and performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118567977A
    Figure CN118567977A
Patent Text Reader

Abstract

The embodiment of the invention provides a code coverage rate detection method, system and device and a storage medium, and the method comprises the steps: recognizing a method class function statement in a source code of a front-end program, determining a target function node according to the function statement, carrying out code instrumentation at a target position in the target function node, and obtaining a code coverage rate detection result; constructing instrumentation data by using the instrumentation codes and the node information of the target function where the instrumentation codes are located, and storing source codes and the instrumentation data; inserting a collection script at the starting position of the source code, wherein the collection script is set to collect and report the running instrumentation code when the front-end program runs; and searching non-running instrumentation codes and non-running target function node information where the non-running instrumentation codes are located in the instrumentation data by using the running instrumentation codes, and calculating the code coverage rate of the front-end program based on the source code and the non-running target function node information. According to the embodiment, automatic instrumentation and acquisition script insertion can be realized for any front-end program, and the running instrumentation codes and the code coverage rate can be automatically acquired and calculated while the front-end program runs.
Need to check novelty before this filing date? Find Prior Art

Description

Background Art

[0002] Front-end and back-end are common terms that describe the beginning and end of a process. In software architecture and programming, the front-end is the part of a software system that interacts directly with the user, while the back-end controls the output of the software. Dividing software into front-end and back-end is an abstraction that separates different functional parts of the software from each other.

[0003] Front-end development is the process of creating front-end interfaces such as web pages, mini programs, or applications to present to users. As front-end programs are updated and iterated, developers add new features, improve existing features, or fix defects, which may cause some useless old codes to appear in the front-end programs. However, due to negligence, lack of time, etc., these codes are not deleted in time. Over time, many redundant codes with unknown uses will appear. The accumulation of redundant codes will increase the maintenance cost of the project, cause many uncertainties in the front-end operation, increase the size of the project, and reduce the project's operating performance.

[0004] In the related art, redundant code that is not executed by the front-end is found by detecting code coverage. Code coverage is a metric in software testing, which describes the proportion and degree of source code execution in the front-end program. It helps to find redundant code and delete unnecessary code, which can improve the running quality and maintainability of the front-end code.

[0005] It should be noted that the information disclosed in the above background technology section is only used to enhance the understanding of the background of the present embodiment, and therefore may include information that does not constitute the prior art known to ordinary technicians in the field. Summary of the invention

[0006] In response to the problems in the prior art, the purpose of this embodiment is to provide a code coverage detection method, system, device and storage medium, which overcomes the difficulties of the prior art and can improve the scope of application and efficiency of code coverage detection.

[0007] The present disclosure provides a method for detecting code coverage, which includes:

[0008] Identify method class function declarations in the source code of the front-end program, determine the target function node according to the function declaration, perform code stubs at the target position in the target function node, construct stub data using the stub code and the target function node information where it is located, and store the source code and stub data;

[0009] Insert a collection script at the beginning of the source code. The collection script is set to collect and report the running instrumentation code when the front-end program is running.

[0010] Use the running instrumentation code to find the non-running instrumentation code and the non-running target function node information in the instrumentation data, and calculate the code coverage of the front-end program based on the source code and the non-running target function node information.

[0011] In an optional implementation, identifying a method class function declaration in the source code of the front-end program includes:

[0012] Read the source code of the front-end program, parse the source code into an abstract syntax tree, and traverse the abstract syntax data to identify method class function declarations.

[0013] In an optional implementation, reading the source code of the front-end program includes:

[0014] In response to CLI commands, the source code of the front-end program is read.

[0015] In an optional implementation, identifying a method class function declaration in the source code of the front-end program includes:

[0016] In response to a call instruction of the compiler during source code compilation, an instrumentation tool is called to identify method class function declarations in the source code; wherein the call instruction is generated when the compiler parses the source code to obtain an abstract syntax tree.

[0017] In an optional implementation, the compiler is implemented by a webpack tool, and receives a calling instruction from the webpack tool by accessing an entry of the webpack tool.

[0018] In an optional implementation manner, the code coverage detection method further includes:

[0019] Displaying a function node configuration interface on the client, the function node configuration interface displays at least one function node class option among a function node class to be instrumented and a function node class not to be instrumented;

[0020] Receive user configuration operations through the function node configuration interface;

[0021] In response to the user configuration operation, a selected function node class option is obtained; then, a target function node is determined according to the function declaration, including:

[0022] Determines the target function node based on the function declaration and the Function Node Class option selected.

[0023] In an optional implementation manner, the code coverage detection method further includes:

[0024] Before inserting the collection script at the beginning of the source code, determine the development platform to which the front-end program belongs based on its identification information, extract the corresponding collection template based on the development platform, and automatically generate the collection script using the collection template.

[0025] In an optional implementation manner, the collection script is specifically configured as follows:

[0026] A data transmission relationship is established with the server, and based on the data transmission relationship, the collected running instrumentation code is reported to the server.

[0027] In an optional implementation, the collection script is further configured to:

[0028] When the collection script starts running, the local cache is automatically initialized, the running instrumentation code collected last time is cleared, the collected currently running instrumentation code is sent to the server, and saved in the current cache.

[0029] In an optional implementation, the collection script is further configured to:

[0030] Before sending the collected currently running instrumentation code to the server, the currently running instrumentation code is matched with the instrumentation code in the current cache;

[0031] If the stored instrumentation code is not matched in the current cache, or part of the stored instrumentation code is matched, the current instrumentation code that is not matched to the stored instrumentation code is sent to the server and saved in the current cache.

[0032] In an optional implementation, the collection script is further configured to:

[0033] When the cache queue of the current cache exceeds a certain threshold, a first-in-first-out strategy is adopted to delete the stored instrumentation code in the current cache.

[0034] In an optional implementation, the collection script is further configured to:

[0035] Before reporting the collected running instrumentation codes to the server, multiple collected running instrumentation codes are concatenated into a string to report the string to the server.

[0036] In an optional implementation, the collection script is further configured to:

[0037] Reporting the collected application user terminal identifiers running the plug-in code and the front-end program to the server, so that the server extracts the target user terminal identifiers of the target proportion, and returns a reporting instruction to the collection script corresponding to the target user terminal identifier;

[0038] In response to the reporting instruction, continue to report the collected running instrumentation code.

[0039] In an optional implementation manner, the code coverage detection method further includes:

[0040] Before identifying the method class function declaration in the source code of the front-end program, the plug-in switch configuration interface is displayed on the client;

[0041] Receive user input through the plug-in switch configuration interface;

[0042] In case an instrumentation enable signal is obtained in response to a user input, a method class function declaration is identified in a source code of the front-end program.

[0043] In an optional implementation manner, the code coverage detection method further includes:

[0044] The client displays code coverage and information about nodes that have not executed the target function.

[0045] The disclosed embodiment also provides a code coverage detection method, which is applied to a server. The code coverage detection method includes:

[0046] Receive the source code of the front-end program and the plug-in data of the source code from the client, and store them, wherein the plug-in data includes the plug-in code in the source code and the target function node information in the source code, wherein a collection script is also inserted at the beginning of the source code;

[0047] When a front-end program with a collection script is launched, the running instrumentation code collected when the front-end program is running is received from the collection script;

[0048] Use the running instrumentation code to find the non-running instrumentation code and the non-running target function node information in the instrumentation data, and calculate the code coverage of the front-end program based on the source code and the non-running target function node information.

[0049] In an optional implementation manner, the code coverage detection method further includes:

[0050] Before calculating the code coverage of the front-end program based on the source code and the information of the target function node that has not been run, if the target function data node that has not been run and its corresponding known non-run code interval have been found according to the running stub code collected when the front-end program was run last time, then the current target function node and its corresponding current non-run code interval are found according to the currently collected running stub code to determine whether the current non-run code interval is within the known non-run code interval;

[0051] If not, then add the current unrunning code interval to the known unrunning code interval;

[0052] If yes, continue to execute the next step to find the current target function node and its corresponding currently unrunning code interval according to the currently collected running stub code; until the current front-end program is terminated;

[0053] Calculates code coverage for the front-end program based on source code and known unexecuted code intervals.

[0054] In an optional implementation manner, the code coverage detection method further includes:

[0055] When a string formed by concatenating multiple running instrumentation codes is received from the collection script, the string is disassembled based on the number of bits of each running instrumentation code to obtain multiple running instrumentation codes.

[0056] In an optional implementation manner, the code coverage detection method further includes:

[0057] When the application user terminal identifier is received from the collection script, the target user terminal identifier of the target ratio is extracted, and a reporting instruction is returned to the collection script corresponding to the target user terminal identifier, so that the collection script responds to the reporting instruction and continues to report the collected running plug-in code.

[0058] The present disclosure also provides a code coverage detection system, which includes:

[0059] The client identifies the method class function declaration in the source code of the front-end program, determines the target function node according to the function declaration, performs code stub at the target position in the target function node, constructs the stub data using the stub code and the target function node information, and reports it to the server. The client also inserts a collection script at the beginning of the source code. The collection script is set to collect and report the running stub code when the front-end program is running.

[0060] The server stores source code and instrumentation data, uses the running instrumentation code to find the non-running instrumentation code and its non-running target function node information in the instrumentation data, and calculates the code coverage of the front-end program based on the source code and the non-running target function node information.

[0061] The present disclosure also provides a code coverage detection system, which includes:

[0062] The plug-in module identifies method class function declarations in the source code of the front-end program, determines the target function node according to the function declaration, performs code plug-in at the target position in the target function node, constructs plug-in data using the plug-in code and the target function node information where it is located, and stores the source code and the plug-in data;

[0063] Insert module, insert the collection script at the beginning of the source code. The collection script is set to collect and report the running stub code when the front-end program is running;

[0064] The first calculation module uses the running instrumentation code to search the non-running instrumentation code and the non-running target function node information in the instrumentation data, and calculates the code coverage of the front-end program based on the source code and the non-running target function node information.

[0065] The embodiment of the present disclosure also provides a code coverage detection system, which is applied to a server. The code coverage detection system includes:

[0066] A receiving module receives the source code of the front-end program and the plug-in data of the source code from the client, and stores the plug-in data, wherein the plug-in data includes the plug-in code in the source code and the target function node information in the source code, wherein a collection script is also inserted at the beginning of the source code;

[0067] The collection module receives the running plug-in code collected when the front-end program is running from the collection script when the front-end program with the collection script is online;

[0068] The second calculation module uses the running instrumentation code to search the non-running instrumentation code and the non-running target function node information in the instrumentation data, and calculates the code coverage of the front-end program based on the source code and the non-running target function node information.

[0069] An embodiment of this implementation further provides an electronic device, including:

[0070] processor;

[0071] a memory in which executable instructions for the processor are stored;

[0072] The processor is configured to execute the steps of the above-mentioned code coverage detection method by executing executable instructions.

[0073] The embodiment of the present implementation also provides a computer-readable storage medium for storing a program, and the program implements the steps of the above-mentioned code coverage detection method when executed.

[0074] The code coverage detection method, system, device and storage medium provided in this embodiment have the following technical effects:

[0075] This implementation can fully cover all front-end program files, automatically add method-level plug-in code to the source code, and associate it with the release version of the front-end program, that is, generate plug-in data. Furthermore, by collecting the running plug-in code when the front-end program is running, the front-end program code execution status is collected in real time in advance to achieve code runtime coverage monitoring.

[0076] Moreover, based on the analysis of the reported running instrumented code combined with instrumented data, the code running coverage of the project as a whole and each file can be obtained, and the online non-running code can be accurately located. In this way, users can use the above code coverage as a code quality measurement indicator to quickly identify the optimization direction, and combine the path and code location of the non-running code displayed on the visualization platform to efficiently clean up redundant code. BRIEF DESCRIPTION OF THE DRAWINGS

[0077] Other features, objectives and advantages of the present embodiment will become more apparent from the detailed description of non-limiting embodiments made with reference to the following drawings.

[0078] Figure 1 One of the flowcharts of the code coverage detection method according to an embodiment of the present disclosure is shown.

[0079] Figure 2 A structural diagram showing a code coverage detection system according to an embodiment of the present disclosure.

[0080] Figure 3 Display based on Figure 2 A timing diagram of the code coverage detection method of the code coverage detection system is shown.

[0081] Figure 4 The second flowchart of the code coverage detection method of the embodiment of the present disclosure is shown.

[0082] Figure 5 A schematic diagram of CLI command-based instrumentation in the code coverage detection method of an embodiment of the present disclosure is shown.

[0083] Figure 6 A schematic diagram of the instrumentation based on the Babel+webpack plug-in in the code coverage detection method of the embodiment of the present disclosure is shown.

[0084] Figure 7 The third flowchart of the code coverage detection method of the embodiment of the present disclosure is shown.

[0085] Figure 8 A schematic diagram showing two code interval analysis processes in the code coverage detection method of an embodiment of the present disclosure.

[0086] Fig. 9 A schematic diagram showing a client display interface in the code coverage detection method of an embodiment of the present disclosure.

[0087] Fig.10 One of the structural schematic diagrams showing the code coverage detection system of the embodiment of the present disclosure.

[0088] Fig.11 The second structural diagram of the code coverage detection system of the embodiment of the present disclosure is shown.

[0089] Fig.12 The third structural diagram of the code coverage detection system of the embodiment of the present disclosure is shown.

[0090] Fig.13 is a schematic diagram of the structure of the electronic device of this embodiment. and

[0091] Fig.14 It is a schematic diagram of the structure of a computer-readable storage medium according to an embodiment of the present invention. DETAILED DESCRIPTION

[0092] In order to make the purpose, technical scheme and advantages of this embodiment more clear, this embodiment will be further described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of this embodiment, not all of the embodiments. Based on the embodiments in this embodiment, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this embodiment.

[0093] The accompanying drawings are only schematic illustrations of the present embodiment and are not necessarily drawn to scale. The same reference numerals in the figures represent the same or similar parts, and their repeated description will be omitted. Some of the block diagrams shown in the accompanying drawings are functional entities and do not necessarily correspond to physically or logically independent entities. These functional entities can be implemented in software form, or implemented in one or more hardware forwarding modules or integrated circuits, or implemented in different networks and / or processor devices and / or microcontroller devices.

[0094] In addition, the processes shown in the drawings are only exemplary and do not necessarily include all the steps. For example, some steps may be decomposed, some steps may be combined or partially combined, and the actual execution order may be changed according to the actual situation.

[0095] In the related art, there are two code coverage detection schemes:

[0096] (1) General tracking point reporting. Tracking points are set in the front-end code, and then the tracking point data is reported to analyze the execution of the business and optimize the project code. This solution has the following disadvantages: the granularity is large, and it is impossible to add tracking points inside each method; the business party needs to develop tracking points for each method one by one, and adding, deleting, and modifying will further increase the maintenance cost of the code; the existing tracking point data system is used for performance statistics. If a large number of tracking points are used to optimize project quality, it will cause a huge waste of resources for the tracking point data system.

[0097] (2) Istanbul is a JavaScript code coverage tool that helps developers and testers evaluate their code test coverage. Istanbul analyzes the running status of js code and generates reports to show which parts are covered by the test suite and which are not. Istanbul is a coverage statistics tool based on test cases. It is mainly used to improve the quality of self-testing. The coverage rate detected by this method can only indicate the proportion of the code that has been tested. It is generally only used in internal test platforms and cannot collect the actual usage of the project in the production environment. The generated coverage report cannot be used as a reliable basis for project optimization.

[0098] The disclosed embodiment provides a universal front-end code coverage detection method to realize an automated and universal front-end code coverage detection, improve the code coverage detection efficiency, and reduce resource waste.

[0099] like Figure 1 As shown, Figure 1 A flowchart of a code coverage detection method provided by an embodiment of the present disclosure is shown. The code coverage detection method of this embodiment includes but is not limited to the following steps:

[0100] Step 110: identifying a method class function declaration in the source code of the front-end program, determining a target function node according to the function declaration, inserting code at a target position in the target function node, constructing inserting data using the inserting code and the target function node information where it is located, and storing the source code and the inserting data;

[0101] Step 120: inserting a collection script at the beginning of the source code, the collection script is configured to collect and report the running instrumentation code when the front-end program is running;

[0102] Step 130: Use the running instrumentation code to search the instrumentation data for the non-running instrumentation code and the non-running target function node information where the instrumentation code is located, and calculate the code coverage of the front-end program based on the source code and the non-running target function node information.

[0103] The instrumentation code acts as an anchor point to locate the target function node in the source code. When the instrumented source code is generated into new code and compiled and put into operation, the collection script runs with the front-end program. If the instrumentation code is collected, it indicates that the code interval of the target function node where the instrumentation code is running is running normally, otherwise it is not running.

[0104] Among them, the target function node information includes its identification (such as name), code length information, etc. Since the instrumentation data has been stored in advance, the currently collected running instrumentation code is compared with the pre-stored full instrumentation data, which can not only determine all non-running instrumentation codes and their non-running target function nodes and their code intervals, but also use the source code and the code data of the non-running target function nodes to calculate the code coverage of the front-end program.

[0105] This implementation can fully cover all front-end program files, automatically add method-level plug-in code to the source code, and associate it with the release version of the front-end program, that is, generate plug-in data. Furthermore, by collecting the running plug-in code when the front-end program is running, the front-end program code execution status is collected in real time in advance to achieve code runtime coverage monitoring.

[0106] Moreover, based on the analysis of the reported running instrumented code combined with instrumented data, the code running coverage of the project as a whole and each file can be obtained, and the online non-running code can be accurately located. In this way, users can use the above code coverage as a code quality measurement indicator to quickly identify the optimization direction, and combine the path and code location of the non-running code displayed on the visualization platform to efficiently clean up redundant code.

[0107] For any front-end program, the disclosed embodiment provides a general code coverage detection solution to achieve automatic plug-in and insert collection scripts, run the collection script while the front-end program is running, automatically collect the running plug-in code and calculate the code coverage.

[0108] In one implementation, the code coverage rate can intuitively reflect the utilization of the size of the front-end program, helping business developers to determine the optimization direction. For example, the unrunning code in the front-end program can be considered as redundant code, so corresponding operations such as deletion or modification are performed to timely remove unused file content online, thereby saving size space for use when new services are launched.

[0109] Therefore, this embodiment provides an automated and universal front-end code coverage detection method, which does not require additional insertion of tracking points during the development of each program project, thereby improving the efficiency and scope of application of code coverage detection.

[0110] The disclosed embodiment also provides a detection system for implementing the above code coverage detection method, such as Figure 2 As shown, the code coverage detection system may include a client 2A and a server 2B.

[0111] like Figure 3 As shown, Figure 3A timing diagram showing the use of a code coverage detection system to implement the above code coverage detection method is shown. The code coverage detection method includes but is not limited to the following steps:

[0112] Step 310: the client 2A identifies the method class function declaration in the source code of the front-end program, determines the target function node according to the function declaration, performs code insertion at the target position in the target function node, and constructs the insertion data using the insertion code and the target function node information where it is located;

[0113] Step 320: The client 2A sends the source code and the instrumentation data to the server 2B;

[0114] Step 330: the server 2B stores the source code and the instrumentation data;

[0115] Step 340: The client 2A inserts a collection script at the beginning of the source code. The collection script is configured to collect the running plug-in code when the front-end program is running and report it to the server 2B.

[0116] Step 350: the server 2B uses the running instrumentation code to search the instrumentation data for the non-running instrumentation code and the non-running target function node information where it is located, and calculates the code coverage of the front-end program based on the source code and the non-running target function node information.

[0117] Using the code coverage detection system of this embodiment, the client 2A is user-oriented and is used to perform automatic instrumentation and insert the above-mentioned collection script, while building a mapping relationship between the instrumentation code and the target function node information. The above-mentioned instrumentation data includes the mapping relationship, and then the client 2A reports the instrumentation data to the server 2B.

[0118] The server 2B stores the above-mentioned instrumentation data in advance, and then specifically performs the positioning of the non-running code in the front-end program based on the real-time received running instrumentation code, and then calculates the running code coverage. Compared with the client 2A, the server 2B can provide stronger data processing resources, thereby reducing the size of the client 2A.

[0119] In a further implementation manner, the server 2B can send detection data such as the code coverage rate and non-running code of the front-end program to the client 2A for display, and intuitively display detection data such as the code coverage rate and non-running code to the user, so that relevant personnel can perform corresponding operations on these data, such as deleting redundant code.

[0120] use Figure 2 The code coverage detection system shown in the figure, the code coverage detection method of this embodiment can be extended to multiple program platforms. In another embodiment, the code coverage detection system can be deployed in the back end corresponding to the front end program, thereby specifically executing the above code coverage detection method.

[0121] The front-end code coverage detection system provided in this embodiment provides a one-stop service of automated plugging, collection, and analysis. Based on this, the code coverage detection method provided in this embodiment provides clear code quality measurement indicators and optimization directions, which can help developers accurately locate online redundant code, continuously improve code operation quality, and effectively improve size utilization.

[0122] by Figure 2 Taking the example, the steps of the code coverage detection method executed by each side in the code coverage detection system are described in detail below.

[0123] Figure 4 The flowchart of the code coverage detection method provided by the embodiment of the present disclosure is shown. The execution subject of the method is a client, which can be an application, a small program or a web page. Figure 4 As shown, this method includes but is not limited to the following steps:

[0124] Step 410: identifying a method class function declaration in the source code of the front-end program, determining a target function node according to the function declaration, inserting code at a target position in the target function node, and constructing inserting data using the inserting code and information of the target function node where the inserting code is located;

[0125] Step 420: Send the source code and the instrumentation data to the server;

[0126] Step 430: insert a collection script at the beginning of the source code. The collection script is set to collect the running instrumentation code when the front-end program is running and report it to the server, so that the server uses the running instrumentation code to find the non-running instrumentation code and the non-running target function node information in the instrumentation data, and calculate the code coverage of the front-end program based on the source code and the non-running target function node information.

[0127] In the embodiments of the present disclosure, the front-end program may be an application program, a small program or a web program, which is not limited here. The client in the embodiments may be an application program, a small program or a web application.

[0128] In one embodiment, before executing step 410, a plug switch configuration interface is displayed on the client;

[0129] Receive user input through the plug-in switch configuration interface;

[0130] When an instrumentation start signal is obtained in response to user input, a method class function declaration is identified in the source code of the front-end program, and then instrumentation and subsequent steps are performed.

[0131] Accordingly, in the case where an instrumentation shutdown signal is obtained in response to a user input, instrumentation and subsequent steps will no longer be performed.

[0132] Using this implementation, based on the plug-in switch configuration interface, the user can turn on or off the plug-in function at any time as needed, and supports flexible control of the plug-in switch status through the interface to meet the plug-in custom control requirements.

[0133] The switch configuration interface may be generated by rendering according to the feedback value after sending a request to the server.

[0134] In an optional embodiment, an on / off button icon is displayed in the plug switch configuration interface, and the on or off button icon is triggered according to the user input position. Alternatively, an on / off switching icon is displayed in the plug switch configuration interface, and the plug on signal or off signal is determined based on the switching signal.

[0135] The above user input may be a click or a touch, which is not limited here.

[0136] In the embodiment of the present disclosure, before executing step 410, the client further provides a user interface to receive a front-end program identifier or a front-end program file input by a user through the user interface.

[0137] If it is a front-end program identifier, the client can obtain the name and storage path of the front-end program based on the front-end program identifier. The client finds the front-end program file based on the front-end program identifier, and the front-end program file is the execution object of step 410.

[0138] Optionally, if a front-end program file is also received when an instrumentation start signal is obtained in response to a user input, step 410 is further performed.

[0139] In the disclosed embodiment, the front-end program is composed of multiple function nodes, each function node corresponds to a method entity. Function declaration is to name the function node and specify the parameter type and return value type of the function. When declaring a function, a variable is placed before its name, which is a method.

[0140] Therefore, a method-like function node can be identified from the type (type) in the function declaration.

[0141] In the embodiment of the present disclosure, step 410 is performed to identify method class function declarations in the source code of the front-end program, specifically including:

[0142] Read the source code of the front-end program, parse the source code using the abstract syntax tree (AST), and traverse the abstract syntax data to identify method class function declarations.

[0143] This implementation method directly reads the source code of the front-end program, parses the abstract syntax tree, and determines the method class function node based on the abstract syntax tree. The abstract syntax tree is a tree-like representation of the abstract syntax structure of the source code, and then the target function node on the abstract syntax tree is code-inserted, and then the source code is regenerated according to the modified abstract syntax tree.

[0144] In one embodiment, Figure 5 As shown, based on a CLI (command-line interface) command, the source code of the front-end program can be read and the target function node can be determined, and the instrumentation tool can be called to perform instrumentation on the target function node of the front-end program.

[0145] CLI is a software mechanism for interacting with the operating system using a keyboard. It refers to an interface where executable instructions can be typed at a user prompt. The user enters instructions through the keyboard, and the client responds to the keyboard input instructions, and the client automatically reads the code of the front-end program source.

[0146] In an optional implementation, it is also possible to further delete redundant code in the source code (Tree Shaking) and scan the source code after the plugging to filter out useless plugging code, and then report the plugging data to the server, where the plugging data includes the plugging code and the target function node information where it is located.

[0147] The useless instrumentation code may refer to the content about the target function node below, such as the single-line function node or the function node to be excluded configured by the user.

[0148] In another embodiment, the client may be provided with a graphical user interface (GUI) to receive user input via the GUI. For example, the GUI may specifically correspond to the above-mentioned plug switch configuration interface.

[0149] In the embodiment of the present disclosure, the function declaration includes the function type, target function node information, etc., wherein the function type is a method, and the target function node information includes a function node identifier, such as the name of the function segment.

[0150] In another embodiment of the present disclosure, executing step 410, sequentially identifying function declarations in the front-end program source code, includes the following specific execution steps:

[0151] In response to a call instruction of the compiler during source code compilation, an instrumentation tool is called to identify method class function declarations in the source code; wherein the call instruction is generated when the compiler parses the source code to obtain an abstract syntax tree.

[0152] A compiler is a computer program that is used to perform compilation, which is the process of converting source code (original language) written in a certain programming language into another device executable programming language.

[0153] In a specific embodiment, Figure 6 As shown, the compiler is implemented using Babel+webpack plugin. Webpack is a code compilation tool with entry, exit, loader and plugin. Figure 6 As shown in the figure, the operations performed by the webpack tool include building plugins (such as A and B) in the source code, removing redundant code (tree shaking), compressing and confusing, etc. On this basis, the AST instrumentation function is added.

[0154] The webpack tool compiles the source code with the help of the Babel plug-in. During compilation, it traverses the source code and performs AST parsing. When webpack executes the AST instrumentation function, it calls the instrumentation tool in this client to instrument the target function node determined based on the AST. The webpack tool returns the instrumentation code and its corresponding target function node information.

[0155] Therefore, through the entry provided by the webpack tool, the plug-in tool of this embodiment is coupled to the webpack tool and accesses the entry of the webpack tool, so that the plug-in tool is integrated into the operation process of the webpack tool.

[0156] In the disclosed embodiment, the target function node is a node that needs to be plugged in.

[0157] In one implementation, any target function node may be instrumented.

[0158] In another embodiment, the target function node that must be run can be instrumented. For example, for a method with a default filter life cycle, it must be run, so it must be instrumented. For such a target function node, it can be identified by the enumeration value in the function declaration.

[0159] In an optional implementation, for a single-line function node, it may be a case where it is put online without detection, which is invalid code. In this case, there is no necessity for detection and no need for instrumentation.

[0160] In an optional implementation, a function node configuration interface is displayed on the client, and the function node configuration interface displays at least one function node class option among a function node class to be instrumented and a function node class not to be instrumented;

[0161] Receive user configuration operations through the function node configuration interface;

[0162] In response to the user configuration operation, a selected function node class option is obtained; then, a target function node is determined according to the function declaration, specifically including:

[0163] Determines the target function node based on the function declaration and the Function Node Class option selected.

[0164] Among them, the function node configuration interface can display function node class options through a menu list or icons. The user performs configuration operations on the function node class options, and the selected function node class options are determined by identifying the object of the user's configuration operation.

[0165] The selected function node class option may be a function node class option to be plugged in, and the target function node to be plugged in is directly matched according to the selected function node class option. Alternatively, the selected function node class option may be a function node class option not to perform plugging in, and the corresponding function node is excluded according to the selected function node class option, and other function nodes are determined as target function nodes.

[0166] Therefore, this implementation supports users to customize certain files or corresponding function nodes without inserting them, which helps users to more accurately analyze the content and coverage they want to analyze, taking into account both user needs and detection efficiency.

[0167] In the disclosed embodiment, each target function node has a start position and an end position. In this case, the target position can be the start position, so that when the target function node starts to run, the plug-in code is executed first. Further, based on the collected non-running plug-in code, the non-running code interval can be quickly located.

[0168] In the embodiments of the present disclosure, the stub technology refers to inserting a probe or anchor point into the program on the basis of ensuring the logical integrity of the original program, and collecting information in the code through the probe. At this time, the probe or anchor point is in the form of stub code.

[0169] In the disclosed embodiment, the plugging code is generated in real time. When plugging, the plugging code of the corresponding position is generated based on the corresponding plugging code generation algorithm. For example, the numbers 0-9 and 26 uppercase and lowercase letters are used to generate a 3-digit (or other digit) unique plugging code for each target function node, and code reuse is achieved to reduce the change of differential mode.

[0170] In actual operation, each plug-in code is 3 bits, which can meet the capacity requirements. Of course, the number of bits of each plug-in code can be configured as needed, and this client provides configuration options.

[0171] In the embodiment of the present disclosure, step 420 is executed to insert a collection script at the beginning of the source code of the front-end program. The collection script may be automatically generated. Specifically, before inserting the collection script at the beginning of the source code, the development platform to which the front-end program belongs is determined according to the identification information of the front-end program, the corresponding collection template is extracted according to the development platform, and the collection script is automatically generated using the collection template.

[0172] By providing collection templates of front-end programs suitable for platform development for different platforms, collection scripts are automatically generated in real time during the plugging process, which can save the client of this implementation from accessing multiple platforms and reduce access costs.

[0173] The collection script is inserted into the beginning of the front-end program source code, so that the collection method based on the collection script is automatically injected into the top of each inserted front-end program file, which can reduce the code of logical judgment and ensure the stability of operation.

[0174] In the embodiment of the present disclosure, the above-mentioned collection script is configured to collect the running instrumentation code and report it to the server. Among them, the collection script is also specifically configured as follows:

[0175] A data transmission relationship is established with the server, and based on the data transmission relationship, the collected running instrumentation code is reported to the server.

[0176] In this embodiment, during the process of automatically generating the acquisition script, a data transmission relationship with the server interface is established, so that when the acquisition script subsequently acquires the running instrumentation code, the running instrumentation code is directly uploaded to the server.

[0177] In an optional implementation, the running instrumented code collected by the collection script can be directly reported to the server corresponding to the front-end program itself. In this case, the server may not be deployed in the code coverage detection system of this case.

[0178] In the embodiment of the present disclosure, the collection script is further configured as follows:

[0179] When the collection script starts running, the local cache is automatically initialized, the running instrumentation code collected last time is cleared, the collected currently running instrumentation code is sent to the server, and saved in the current cache.

[0180] In this embodiment, the previously sent running plug-in code is saved in the previous cache and does not need to be sent again, so it can be cleared before the current collection script is collected. Wherein, clearing the previously collected running plug-in code can be transferring the previously running plug-in code from the cache to a temporary memory.

[0181] In the embodiment of the present disclosure, as described above, when the running instrumentation code is sent to the server, the sent instrumentation code will be cached. In this way, the cache is used to filter the sent instrumentation code, for example, for the running instrumentation code collected during the subsequent running of the front-end program, it is matched with the sent instrumentation code in the cache. If the current running instrumentation code is matched in the current cache, the current running instrumentation code will no longer be sent to the server;

[0182] If the stored instrumentation code is not matched in the current cache, or part of the stored instrumentation code is matched, the current instrumentation code that is not matched to the stored instrumentation code is sent to the server and saved in the current cache.

[0183] The above cache is used to filter the sent instrumentation code, which can achieve deduplication of the instrumentation code in the cache, reduce the number of times the same front-end program application user sends the same information, and greatly improve the collection efficiency.

[0184] Furthermore, in order to ensure that the data in the cache queue can cover the most recently reported plug-in code as much as possible, the disclosed method adopts a "first-in, first-out" strategy. When the length of the cache queue exceeds a certain threshold, when the cache queue of the current cache exceeds a certain threshold, a first-in, first-out strategy is adopted to delete the stored plug-in code in the current cache.

[0185] In this way, by deleting the instrumentation code from the beginning of the queue, it is possible to avoid excessive memory usage due to the queue being too long. In this way, the instrumentation code in the cache can be updated in time according to the call timing, thereby improving the timeliness and accuracy of the cache.

[0186] This embodiment provides the above anti-shake measurement rate to control the frequency of instrumentation code reporting. Specifically, the collection script is also configured as:

[0187] Before reporting the collected running instrumentation codes to the server, multiple collected running instrumentation codes are concatenated into a string to report the string to the server.

[0188] In this way, the server splits the string according to the preset length of the instrumentation code to obtain multiple running instrumentation codes, which can greatly reduce the amount of transmitted data. This can avoid the waste of network bandwidth resources due to frequent reporting and reduce the impact on front-end performance.

[0189] The disclosed embodiment also provides the function of grayscale reporting. At this time, the collection script is configured as follows:

[0190] Reporting the collected application client IDs (ClientIDs) running the plug-in code and the front-end program to the server, so that the server extracts the target client IDs of the target proportion therefrom, and returns a reporting instruction to the collection script corresponding to the target client IDs;

[0191] In response to the reporting instruction, continue to report the collected running instrumentation code.

[0192] Furthermore, a report termination instruction may be returned to the collection script corresponding to other user terminal identifiers other than the target user terminal identifier, so that the collection script no longer executes the report of the running instrumentation code.

[0193] Using this implementation, the server controls the grayscale by collecting the ClientID passed in when the script is reported, so that the user can dynamically adjust the reported user terminal ratio according to actual conditions, further ensuring the security of the system and improving the execution efficiency of the front-end program code.

[0194] In this embodiment, the server extracts the target user terminal identifier by identifying the application user terminal identifier, and may specifically adopt a random extraction method, or screening based on the reception time of the application user terminal identifier, or other extraction methods, which are not limited here.

[0195] In an optional implementation manner, when a certain number of application client identifiers are received, the target client identifier may be extracted therefrom, or the target client identifier may be extracted within a preset time interval, which is not limited herein.

[0196] In the disclosed embodiment, the server recognizes the application user end identifier, and can perform a hash calculation on the application user end identifier to generate a hash code (hashcode). The hash code can be used as a unique identifier of an object to compare whether two objects are equal. In Java, if the hash code values ​​of two objects are equal, they may be equal, but not necessarily exactly the same. Therefore, by comparing hash codes, different application user end identifiers can be identified and distinguished, thereby achieving extraction.

[0197] In an optional implementation manner, the code coverage detection method further includes:

[0198] The client displays code coverage and information about nodes that have not executed the target function.

[0199] Specifically, the server calculates the code coverage and sends the code coverage and the code interval of the target function node that is not executed in the front-end program to the client, which displays it intuitively.

[0200] In this way, the user can quickly locate the unexecuted code section in the front-end program in the source code and delete it as redundant code, thereby improving the running efficiency of subsequent front-end programs.

[0201] Figure 7 A flowchart showing a code coverage detection method based on the server as the execution subject is shown. This method includes but is not limited to the following steps:

[0202] Step 710: receiving the source code of the front-end program and the plug-in data of the source code from the client, and storing them, wherein the plug-in data includes the plug-in code in the source code and the target function node information in the source code, wherein a collection script is also inserted at the beginning of the source code;

[0203] Step 720: When the front-end program with the collection script is online, receiving the running instrumentation code collected when the front-end program is running from the collection script;

[0204] Step 730: Use the running instrumentation code to search the instrumentation data for the non-running instrumentation code and the non-running target function node information where it is located, and calculate the code coverage of the front-end program based on the source code and the non-running target function node information.

[0205] In an optional implementation manner, before calculating the code coverage of the front-end program based on the source code and the information of the target function node that has not been run, if the target function data node that has not been run and its corresponding known non-run code interval have been found according to the running stub code collected when the front-end program was run last time, then the current target function node and its corresponding current non-run code interval are found according to the currently collected running stub code to determine whether the current non-run code interval is within the known non-run code interval;

[0206] If not, then add the current unrunning code interval to the known unrunning code interval;

[0207] If yes, continue to execute the next step to find the current target function node and its corresponding currently unrunning code interval according to the currently collected running stub code; until the current front-end program is terminated;

[0208] Calculates code coverage for the front-end program based on source code and known unexecuted code intervals.

[0209] Specifically, the online unexecuted code interval of each front-end file can be finally obtained by repeating the cycle. In this process, there are three types of position intervals of the current unexecuted code interval compared to the known unexecuted code interval, such as Figure 8 As shown, the corresponding processing method is as follows:

[0210] The first type is that if the current non-executing code interval (6-22) is outside the known non-executing code interval, the current non-executing code interval (6-22) is added to the known non-executing code interval (6-22).

[0211] The second type is that if the current non-running code interval (41-56) is within the known non-running code interval (35-70), this corresponds to a method nested function node type, indicating that the known non-running code interval (35-70) already contains the function node corresponding to the current non-running code interval, so that other stub codes can continue to be queried.

[0212] The third type is that if the current non-running code interval (78-96) contains a part of the known non-running code interval (80-93), the known non-running code interval contained in it is replaced by the current non-running code interval and merged into the known non-running code interval.

[0213] After analysis and processing, the server can further obtain the number and bytes of all non-running codes in the front-end program based on the running stub code to determine the non-running code interval of the front-end program line, and then obtain its code coverage. The calculation formula is:

[0214] The percentage of running code = (1 – the number of bytes of non-running code / the total number of bytes of project code) * 100%;

[0215] Proportion of running methods = (1 – number of non-running methods / total number of instrumented methods) * 100%.

[0216] In this way, the code coverage rate can be characterized by the proportion of running code and the proportion of running methods, so as to realize the detection of the front-end code running coverage rate, and the front-end code running coverage rate is the code coverage rate.

[0217] In this way, Fig. 9 As shown, the total percentage of running code and the total percentage of running methods are displayed on the client. The total percentage of running code includes the percentage of running code and the percentage of not running code and their specific values. The total percentage of running methods includes the percentage of running methods and the percentage of not running methods and their specific values, where the running method refers to the corresponding function node itself. Fig. 9 Only one display form is provided, and other embodiments may be adjusted as needed.

[0218] In an optional implementation manner, the code coverage detection method further includes:

[0219] When a string formed by concatenating multiple running instrumentation codes is received from the collection script, the string is disassembled based on the number of bits of each running instrumentation code to obtain multiple running instrumentation codes.

[0220] In an optional implementation manner, the code coverage detection method further includes:

[0221] When the application user terminal identifier is received from the collection script, the target user terminal identifier of the target ratio is extracted, and a reporting instruction is returned to the collection script corresponding to the target user terminal identifier, so that the collection script responds to the reporting instruction and continues to report the collected running plug-in code.

[0222] Specifically, the implementation method of extracting the target user terminal identifier by the server can refer to the above content, which will not be repeated here. Further, the collection scripts corresponding to other user terminal identifiers other than the target user terminal identifier return a report termination instruction, so that these collection scripts terminate uploading and running the stub code.

[0223] Using this implementation, the server controls the proportion of user terminals running the instrumented code reported by collecting the ClientID passed in when the script is reported. In this way, the user can dynamically adjust the proportion of user terminals reported according to actual conditions, further ensuring the security of the system and improving the execution efficiency of the front-end program code.

[0224] Fig.10 Schematic diagram of the structure of the code coverage detection system of this embodiment. Fig.10 As shown, the code coverage detection system 1000 of this embodiment includes:

[0225] The plugging module 1010 identifies method class function declarations in the source code of the front-end program, determines the target function node according to the function declaration, performs code plugging at the target position in the target function node, constructs plugging data using the plugging code and the target function node information where it is located, and stores the source code and the plugging data;

[0226] Insertion module 1020, inserting a collection script at the beginning of the source code, the collection script is set to collect and report the running plug-in code when the front-end program is running;

[0227] The first calculation module 1030 uses the running instrumentation code to search the instrumentation data for the non-running instrumentation code and the non-running target function node information where the code is located, and calculates the code coverage of the front-end program based on the source code and the non-running target function node information.

[0228] In an optional embodiment, the plugging module 1010 is specifically used for:

[0229] Read the source code of the front-end program, parse the source code into an abstract syntax tree, and traverse the abstract syntax data to identify method class function declarations.

[0230] In an optional embodiment, the plugging module 1010 is specifically used for:

[0231] In response to CLI commands, the source code of the front-end program is read.

[0232] In an optional embodiment, the plugging module 1010 is specifically used for:

[0233] In response to a call instruction of the compiler during source code compilation, an instrumentation tool is called to identify method class function declarations in the source code; wherein the call instruction is generated when the compiler parses the source code to obtain an abstract syntax tree.

[0234] In an optional embodiment, the plugging module 1010 is specifically used for:

[0235] The compiler is implemented through the webpack tool, and receives calling instructions from the webpack tool by accessing the entrance of the webpack tool.

[0236] In an optional embodiment, the plugging module 1010 is further used to:

[0237] Displaying a function node configuration interface on the client, the function node configuration interface displays at least one function node class option among a function node class to be instrumented and a function node class not to be instrumented;

[0238] Receive user configuration operations through the function node configuration interface;

[0239] In response to the user configuration operation, the selected function node class option is obtained; then,

[0240] Determines the target function node based on the function declaration and the Function Node Class option selected.

[0241] In an optional embodiment, the plugging module 1010 is further used to:

[0242] Before inserting the collection script at the beginning of the source code, determine the development platform to which the front-end program belongs based on its identification information, extract the corresponding collection template based on the development platform, and automatically generate the collection script using the collection template.

[0243] In an optional embodiment, the collection script is specifically configured as follows:

[0244] A data transmission relationship is established with the server, and based on the data transmission relationship, the collected running instrumentation code is reported to the server.

[0245] In an optional embodiment, the collection script is further configured to:

[0246] When the collection script starts running, the local cache is automatically initialized, the running instrumentation code collected last time is cleared, the collected currently running instrumentation code is sent to the server, and saved in the current cache.

[0247] In an optional embodiment, the collection script is further configured to:

[0248] Before sending the collected currently running instrumentation code to the server, the currently running instrumentation code is matched with the instrumentation code in the current cache;

[0249] If the stored instrumentation code is not matched in the current cache, or part of the stored instrumentation code is matched, the current instrumentation code that is not matched to the stored instrumentation code is sent to the server and saved in the current cache.

[0250] In an optional embodiment, the collection script is further configured to:

[0251] When the cache queue of the current cache exceeds a certain threshold, a first-in-first-out strategy is adopted to delete the stored instrumentation code in the current cache.

[0252] In an optional embodiment, the collection script is further configured to:

[0253] Before reporting the collected running instrumentation codes to the server, multiple collected running instrumentation codes are concatenated into a string to report the string to the server.

[0254] In an optional embodiment, the collection script is further configured to:

[0255] Reporting the collected application user terminal identifiers running the plug-in code and the front-end program to the server, so that the server extracts the target user terminal identifiers of the target proportion therefrom, and returns a reporting instruction to the collection script corresponding to the target user terminal identifier;

[0256] In response to the reporting instruction, continue to report the collected running instrumentation code.

[0257] In an optional embodiment, the plugging module 1010 is further used to:

[0258] Before identifying the method class function declaration in the source code of the front-end program, the plug-in switch configuration interface is displayed on the client;

[0259] Receive user input through the plug-in switch configuration interface;

[0260] In case an instrumentation enable signal is obtained in response to a user input, a method class function declaration is identified in a source code of the front-end program.

[0261] In an alternative embodiment, Fig.10 compared to, Fig.11 The code coverage detection system further includes:

[0262] The display module 1110 displays the code coverage and the information of the target function nodes that have not been executed through the client.

[0263] The disclosed embodiment provides a code coverage detection system, which can automatically insert a code snippet and a collection script for any front-end program, run the collection script while the front-end program is running, automatically collect the running code snippet and calculate the code coverage.

[0264] Fig.12 A structural diagram of another code coverage detection system 1200 provided in an embodiment of the present disclosure is shown, which is applied to a server. The code coverage detection system 1200 includes:

[0265] The receiving module 1210 receives the source code of the front-end program and the plug-in data of the source code from the client, and stores the plug-in data, wherein the plug-in data includes the plug-in code in the source code and the target function node information in the source code, wherein the collection script is also inserted at the beginning of the source code;

[0266] The collection module 1220 receives the running instrumentation code collected when the front-end program is running from the collection script when the front-end program with the collection script is online;

[0267] The second calculation module 1230 uses the running instrumentation code to search the non-running instrumentation code and the non-running target function node information in the instrumentation data, and calculates the code coverage of the front-end program based on the source code and the non-running target function node information.

[0268] In an optional implementation manner, the second calculation module 1230 is further specifically configured to:

[0269] Before calculating the code coverage of the front-end program based on the source code and the information of the target function node that has not been run, if the target function data node that has not been run and its corresponding known non-run code interval have been found according to the running stub code collected when the front-end program was run last time, then the current target function node and its corresponding current non-run code interval are found according to the currently collected running stub code to determine whether the current non-run code interval is within the known non-run code interval;

[0270] If not, then add the current unrunning code interval to the known unrunning code interval;

[0271] If yes, continue to execute the next step to find the current target function node and its corresponding currently unrunning code interval according to the currently collected running stub code; until the current front-end program is terminated;

[0272] Calculates code coverage for the front-end program based on source code and known unexecuted code intervals.

[0273] In an optional implementation manner, the second calculation module 1230 is further specifically configured to:

[0274] When a string formed by concatenating multiple running instrumentation codes is received from the collection script, the string is disassembled based on the number of bits of each running instrumentation code to obtain multiple running instrumentation codes.

[0275] In an optional implementation manner, the second calculation module 1230 is further specifically configured to:

[0276] When the application user terminal identifier is received from the collection script, the target user terminal identifier of the target ratio is extracted, and a reporting instruction is returned to the collection script corresponding to the target user terminal identifier, so that the collection script responds to the reporting instruction and continues to report the collected running plug-in code.

[0277] Using the code coverage detection system of this embodiment, the server interacts with the client and the collection script to obtain the instrumentation data and the running instrumentation code collected in real time, and specifically performs the code coverage calculation. Among them, the server can provide greater computing power resources to improve the efficiency of code coverage calculation.

[0278] This embodiment also provides an electronic device, including a processor and a memory, wherein executable instructions of the processor are stored, wherein the processor is configured to execute the steps of the code coverage detection method by executing the executable instructions.

[0279] As described above, the electronic device of this embodiment can automatically insert the collection script for any front-end program, run the collection script while the front-end program is running, automatically collect the running instrumented code and calculate the code coverage.

[0280] It will be appreciated by those skilled in the art that various aspects of the present embodiment may be implemented as a system, method or program product. Therefore, various aspects of the present embodiment may be specifically implemented in the following forms, namely: a complete hardware implementation, a complete software implementation (including firmware, microcode, etc.), or a combination of hardware and software, which may be collectively referred to herein as a "circuit", "module" or "platform".

[0281] Fig.13 Schematic diagram of the structure of the electronic device of this embodiment. Fig.13 An electronic device 1300 according to this embodiment of the present embodiment will be described. Fig.13 The electronic device 1300 shown is merely an example and should not limit the functions and scope of use of this embodiment.

[0282] like Fig.13As shown, the electronic device 1300 is in the form of a general computing device. The components of the electronic device 1300 may include, but are not limited to: at least one processing unit 1310, at least one storage unit 1320, a bus 1330 connecting different platform components (including the storage unit 1320 and the processing unit 1310), a display unit 1340, etc.

[0283] The storage unit stores program codes, which can be executed by the processing unit 1310, so that the processing unit 1310 executes the steps of various exemplary embodiments according to the present embodiment described in the code coverage detection method section of this specification. For example, the processing unit 1310 can execute the following steps: Figure 1 , Figure 3 , Figure 4 and Figure 7 The steps shown in any one of the embodiments.

[0284] The storage unit 1320 may include a readable medium in the form of a volatile storage unit, such as a random access memory unit (RAM) 1321 and / or a cache memory unit 1322 , and may further include a read-only memory unit (ROM) 1323 .

[0285] The storage unit 1320 may also include a program / utility 1324 having a set (at least one) of program modules 1325, such program modules 1325 including but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment.

[0286] Bus 1330 may represent one or more of several types of bus structures, including a memory unit bus or memory unit controller, a peripheral bus, an accelerated graphics port, a processing unit, or a local bus using any of a variety of bus architectures.

[0287] The electronic device 1300 may also communicate with one or more external devices 130 (e.g., keyboards, pointing devices, Bluetooth devices, etc.), may communicate with one or more devices that enable a user to interact with the electronic device 1300, and / or may communicate with any device that enables the electronic device 1300 to communicate with one or more other computing devices (e.g., routers, modems, etc.). Such communication may be performed via an input / output (I / O) interface 1350. Furthermore, the electronic device 1300 may also communicate with one or more networks (e.g., a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) via a network adapter 1360. The network adapter 1360 may communicate with other modules of the electronic device 1300 via the bus 1330. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the electronic device 1300, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage platforms.

[0288] This embodiment also provides a computer-readable storage medium for storing a program, and the steps of the code coverage detection method are implemented when the program is executed. In some possible implementations, various aspects of this implementation can also be implemented in the form of a program product, which includes program code. When the program product is run on a terminal device, the program code is used to enable the terminal device to execute the steps of various exemplary implementations of this implementation described in the above code coverage detection method section of this specification.

[0289] As shown above, when the program of the computer-readable storage medium of this embodiment is executed, it can automatically insert the collection script for any front-end program, run the collection script while the front-end program is running, automatically collect the running instrumented code and calculate the code coverage.

[0290] Fig.14 Schematic diagram of the structure of the computer-readable storage medium of this embodiment. Fig.14 As shown, a program product 1400 for implementing the above method according to an embodiment of the present embodiment is described, which can adopt a portable compact disk read-only memory (CD-ROM) and include program code, and can be run on a terminal device, such as a personal computer. However, the program product of the present embodiment is not limited thereto, and in this document, a readable storage medium can be any tangible medium containing or storing a program, which can be used by or in combination with an instruction execution system, an apparatus or a device.

[0291] The program product may use any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of readable storage media (a non-exhaustive list) include: an electrical connection with one or more wires, a portable disk, 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 disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.

[0292] Computer readable storage media may include data signals propagated in baseband or as part of a carrier wave, wherein readable program codes are carried. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. The readable storage medium may also be any readable medium other than a readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, device, or device. The program codes contained on the readable storage medium may be transmitted using any suitable medium, including but not limited to wireless, wired, optical cable, RF, etc., or any suitable combination thereof.

[0293] The program code for performing the operations of the present embodiment may be written in any combination of one or more programming languages, including object-oriented programming languages ​​such as Java, C++, etc., and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server. In the case of a remote computing device, the remote computing device may be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computing device (e.g., using an Internet service provider to connect through the Internet).

[0294] In summary, the code coverage detection method, system, device and storage medium of this embodiment can automatically insert the collection script for any front-end program, run the collection script while the front-end program is running, automatically collect the running instrumented code and calculate the code coverage.

[0295] The above content is a further detailed description of the present embodiment in combination with specific preferred embodiments, and it cannot be determined that the specific implementation of the present embodiment is limited to these descriptions. For ordinary technicians in the technical field to which the present embodiment belongs, several simple deductions or substitutions can be made without departing from the concept of the present embodiment, which should be regarded as falling within the protection scope of the present embodiment.

Claims

1. A code coverage detection method, characterized in that: include: Identify method class function declarations in the source code of the front-end program, determine a target function node according to the function declaration, perform code insertion at a target position in the target function node, construct insertion data using the insertion code and information about the target function node where it is located, and store the source code and the insertion data; Insert a collection script at the beginning of the source code, wherein the collection script is configured to collect and report the running plug-in code when the front-end program is running; The running plug-in code is used to search the non-running plug-in code and the non-running target function node information in the plug-in data, and the code coverage of the front-end program is calculated based on the source code and the non-running target function node information.

2. The code coverage detection method according to claim 1, characterized in that: The identifying method class function declaration in the source code of the front-end program includes: The source code of the front-end program is read, an abstract syntax tree is performed on the source code, and the abstract syntax data is traversed to identify the method class function declaration.

3. The code coverage detection method according to claim 2, characterized in that: The reading of the source code of the front-end program includes: In response to the CLI command, the source code of the front-end program is read.

4. The code coverage detection method according to claim 1, characterized in that: The identifying method class function declaration in the source code of the front-end program includes: In response to a call instruction of the compiler during the compilation of the source code, an instrumentation tool is called to identify method class function declarations in the source code; wherein the call instruction is generated when the compiler parses the source code to obtain an abstract syntax tree.

5. The code coverage detection method according to claim 4, characterized in that: The compiler is implemented by a webpack tool, and receives the calling instruction from the webpack tool by accessing the entrance of the webpack tool.

6. The code coverage detection method according to claim 1, characterized in that: The code coverage detection method also includes: Displaying a function node configuration interface on the client, wherein the function node configuration interface displays at least one function node class option among a function node class to be instrumented and a function node class not to be instrumented; Receiving user configuration operations through the function node configuration interface; In response to the user configuration operation, a selected function node class option is obtained; then, a target function node is determined according to the function declaration, including: A target function node is determined according to the function declaration and the selected function node class option.

7. The code coverage detection method according to claim 1, characterized in that: The code coverage detection method also includes: Before inserting the acquisition script at the beginning of the source code, the development platform to which the front-end program belongs is determined according to the identification information of the front-end program, the corresponding acquisition template is extracted according to the development platform, and the acquisition script is automatically generated using the acquisition template.

8. The code coverage detection method according to claim 7, characterized in that: The acquisition script is specifically configured as follows: A data transmission relationship is established with the server, so as to report the collected running instrumentation code to the server based on the data transmission relationship.

9. The code coverage detection method according to claim 8, characterized in that: The acquisition script is also configured to: When the acquisition script currently starts running, the local cache is automatically initialized, the running instrumentation code acquired last time is cleared, the collected currently running instrumentation code is sent to the server, and saved in the current cache.

10. The code coverage detection method according to claim 9, characterized in that: The acquisition script is also configured to: Before sending the collected currently running instrumentation code to the server, the currently running instrumentation code is matched with the instrumentation code in the current cache; If the stored plug-in code is not matched in the current cache, or a portion of the stored plug-in code is matched, the current plug-in code that is not matched to the stored plug-in code is sent to the server and saved in the current cache.

11. The code coverage detection method according to claim 10, characterized in that: The acquisition script is also configured to: When the cache queue of the current cache exceeds a certain threshold, a first-in-first-out strategy is adopted to delete the stored instrumentation code in the current cache.

12. The code coverage detection method according to claim 8, characterized in that: The acquisition script is also configured to: Before reporting the collected in-running instrumentation code to the server, the collected multiple in-running instrumentation codes are concatenated into a character string, so as to report the character string to the server.

13. The code coverage detection method according to claim 8, characterized in that: The acquisition script is also configured to: Reporting the collected application user terminal identifiers running the plug-in code and the front-end program to the server, so that the server extracts target user terminal identifiers of a target proportion, and returns a reporting instruction to the collection script corresponding to the target user terminal identifier; In response to the reporting instruction, continue to report the collected running instrumentation code.

14. The code coverage detection method according to claim 1, characterized in that: The code coverage detection method also includes: Before identifying the method class function declaration in the source code of the front-end program, the plug-in switch configuration interface is displayed on the client; Receiving user input via the plug switch configuration interface; In the case where an instrumentation start signal is obtained in response to the user input, a method class function declaration is identified in the source code of the front-end program.

15. The code coverage detection method according to claim 1, characterized in that: The code coverage detection method also includes: The code coverage and information of target function nodes that have not been executed are displayed through the client.

16. A code coverage detection method, characterized in that: Applied to the server, the code coverage detection method includes: Receive the source code of the front-end program and the plug-in data of the source code from the client, and store them, wherein the plug-in data includes the plug-in code in the source code and the target function node information in the source code, wherein a collection script is also inserted at the beginning of the source code; When a front-end program having the collection script is online, receiving the running instrumentation code collected when the front-end program is running from the collection script; The running plug-in code is used to search the non-running plug-in code and the non-running target function node information in the plug-in data, and the code coverage of the front-end program is calculated based on the source code and the non-running target function node information.

17. The code coverage detection method according to claim 16, characterized in that: The code coverage detection method also includes: Before calculating the code coverage of the front-end program based on the source code and the non-run target function node information, if the non-run target function data node and its corresponding known non-run code interval have been found according to the running stub code collected when the front-end program was previously run, then find the current target function node and its corresponding current non-run code interval according to the currently collected running stub code, and determine whether the current non-run code interval is within the known non-run code interval; If not, then add the current unrunning code interval to the known unrunning code interval; If yes, continue to execute the next step of searching the current target function node and its corresponding currently non-running code interval according to the currently collected running plug-in code; until the current running of the front-end program is terminated; The code coverage of the front-end program is calculated based on the source code and the known non-executed code interval.

18. The code coverage detection method according to claim 16, characterized in that: The code coverage detection method also includes: When a character string formed by concatenating a plurality of running instrumentation codes is received from the acquisition script, the character string is disassembled based on the number of bits of each of the running instrumentation codes to obtain a plurality of the running instrumentation codes.

19. The code coverage detection method according to claim 16, characterized in that: The code coverage detection method also includes: When the application user terminal identifier is received from the collection script, the target user terminal identifier of the target proportion is extracted, and a reporting instruction is returned to the collection script corresponding to the target user terminal identifier, so that the collection script responds to the reporting instruction and continues to report the collected running plug-in code.

20. A code coverage detection system, characterized in that: include: The client identifies a method class function declaration in the source code of the front-end program, determines a target function node according to the function declaration, performs code stubs at a target position in the target function node, constructs stub data using the stub code and information about the target function node where it is located, and reports the stub data to the server, and also inserts a collection script at the beginning of the source code, wherein the collection script is configured to collect and report the running stub code when the front-end program is running; The server stores the source code and the instrumentation data, uses the running instrumentation code to search the instrumentation data for the non-running instrumentation code and the non-running target function node information where the instrumentation code is located, and calculates the code coverage of the front-end program based on the source code and the non-running target function node information.

21. A code coverage detection system, characterized in that: include: The plugging module identifies method class function declarations in the source code of the front-end program, determines the target function node according to the function declaration, performs code plugging at the target position in the target function node, constructs plugging data using the plugging code and the target function node information where it is located, and stores the source code and the plugging data; Inserting a module to insert a collection script at the beginning of the source code, wherein the collection script is configured to collect and report the running plug-in code when the front-end program is running; The first calculation module uses the running instrumentation code to search the non-running instrumentation code and the non-running target function node information in the instrumentation data, and calculates the code coverage of the front-end program based on the source code and the non-running target function node information.

22. A code coverage detection system, characterized in that: Applied to the server, the code coverage detection system includes: A receiving module receives the source code of the front-end program and the plug-in data of the source code from the client, and stores the plug-in data, wherein the plug-in data includes the plug-in code in the source code and the target function node information in the source code, wherein a collection script is also inserted at the beginning of the source code; A collection module, when a front-end program with the collection script is online, receives from the collection script the running instrumentation code collected when the front-end program is running; The second calculation module uses the running plug-in code to search the non-running plug-in code and the non-running target function node information in the plug-in data, and calculates the code coverage of the front-end program based on the source code and the non-running target function node information.

23. An electronic device, characterized in that: include: processor; a memory storing executable instructions of the processor; The processor is configured to execute the steps of the code coverage detection method according to any one of claims 1 to 19 by executing the executable instructions.

24. A computer-readable storage medium for storing a program, characterized in that: When the program is executed, the steps of the code coverage detection method according to any one of claims 1 to 19 are implemented.