Code coverage testing method and device, equipment and storage medium
By using preset agent identification codes to identify and locate code files in the fintech field, the problem of code coverage testing under different operating environments is solved, achieving efficient and accurate full-link display and improving testing efficiency and accuracy.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- PING AN PAY ELECTRONIC PAYMENT CO LTD
- Filing Date
- 2022-11-15
- Publication Date
- 2026-07-21
AI Technical Summary
In the fintech field, client-side software code, server-side software code, and database operation code cannot be directly covered by testing due to their different operating environments, resulting in low efficiency of code coverage testing.
The initial front-end code file is identified by a preset proxy identification code, the target front-end, back-end and database operation code files are located, and coverage testing is performed using tool code information and Java Virtual Machine to generate full-link display results.
It improves the accuracy and efficiency of code coverage testing in different operating environments under the same business scenario, and enhances the intuitiveness of test results.
Smart Images

Figure CN115794621B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of testing technology, and in particular to a code coverage testing method, apparatus, device, and storage medium. Background Technology
[0002] In software testing within the fintech sector, code coverage testing is a crucial method for software testing analysis. However, because client-side, server-side, and database operation code often run in different environments (e.g., front-end code runs on mobile devices, server-side code runs on the server itself, and database operation code runs on middleware like Redis), it's impossible to directly perform coverage testing on client-side, server-side, and database operation code within the same business scenario, thus reducing the efficiency of code coverage testing. Summary of the Invention
[0003] In view of the above, it is necessary to provide a code coverage testing method, apparatus, device, and storage medium that can solve the technical problem of low efficiency in code coverage testing, which makes it impossible to directly perform coverage testing on client software code, server software code, and database operation code under the same business scenario.
[0004] On one hand, the present invention proposes a code coverage testing method, the code coverage testing method comprising:
[0005] Obtain the initial front-end code file for the request test scenario;
[0006] The initial front-end code file is identified based on a preset proxy identification code to obtain the target front-end code file;
[0007] Run the target front-end code file, and locate the target back-end code file and the target database operation code file based on the preset proxy identification code. The target database operation code file refers to the code file of the scene database.
[0008] A coverage test is performed on the target front-end code file to obtain the front-end coverage result, and a coverage test is performed on the target back-end code file to obtain the back-end coverage result;
[0009] Generate database coverage results based on the target database operation code file and the scenario database base code file;
[0010] The front-end coverage results, the back-end coverage results, and the database coverage results are displayed in their entirety.
[0011] According to a preferred embodiment of the present invention, the initial front-end code file for obtaining the request test scenario includes:
[0012] Get the request data packet;
[0013] Extract the scene identifier from the request data packet based on the preset scene field;
[0014] Match the scene identifier with the scene identification code of the requested test scene;
[0015] If the scene identifier matches the scene identification code, the request data packet is identified as the initial front-end code file.
[0016] According to a preferred embodiment of the present invention, the step of identifying the initial front-end code file based on a preset proxy identification code to obtain the target front-end code file includes:
[0017] Create a proxy field based on a preset proxy identification code;
[0018] Locate the header code file corresponding to the preset header field from the initial front-end code file;
[0019] The proxy field and the preset proxy identification code are written into the header code file to obtain the target front-end code file corresponding to the initial front-end code file.
[0020] According to a preferred embodiment of the present invention, the step of performing a coverage test on the target front-end code file to obtain the front-end coverage result includes:
[0021] Retrieve tool code information for preset tools;
[0022] By invoking offline commands and scheduled commands, the tool code information is written into the target front-end code file to obtain the instrumented front-end code file;
[0023] Run the instrumented front-end code file to obtain the front-end coverage result.
[0024] According to a preferred embodiment of the present invention, the step of performing a coverage test on the target backend code file to obtain the backend coverage result includes:
[0025] Identify the Java Virtual Machine where the target backend code file resides;
[0026] The monitoring code is invoked from the Java Virtual Machine and loaded into the target backend code file to obtain the instrumented backend code file;
[0027] The instrumented backend code file is compiled, packaged, and run to obtain the backend overlay result.
[0028] According to a preferred embodiment of the present invention, the step of generating database coverage results based on the target database operation code file and the scenario database base code file includes:
[0029] A first database syntax tree is constructed based on the target database operation code file, and a second database syntax tree is constructed based on the base code file;
[0030] Compare the first database syntax tree and the second database syntax tree to obtain the incremental object;
[0031] Obtain the calling object and the called object of the incremental object from the first database syntax tree;
[0032] The information corresponding to the incremental object, the calling object, and the called object are obtained from the target database operation code file as the database overwrite result.
[0033] According to a preferred embodiment of the present invention, the full-link display of the front-end coverage result, the back-end coverage result, and the database coverage result includes:
[0034] Get the page dimensions of the visualization page;
[0035] Based on the page size, the front-end coverage result, the back-end coverage result, and the database coverage result, the visualization page is divided into a front-end display area, a back-end display area, and a database display area.
[0036] Based on the code volume and execution order of the front-end coverage results, the front-end coverage results are displayed in the front-end display area;
[0037] Based on the code volume and execution order of the backend coverage results, the backend coverage results are displayed in the backend display area;
[0038] Based on the amount of code and the execution order of the database coverage results, the database coverage results are displayed in the database display area.
[0039] On the other hand, the present invention also proposes a code coverage testing apparatus, the code coverage testing apparatus comprising:
[0040] The acquisition unit is used to acquire the initial front-end code file for the request test scenario;
[0041] The identification unit is used to identify the initial front-end code file based on a preset proxy identification code to obtain the target front-end code file;
[0042] The positioning unit is used to run the target front-end code file and locate the target back-end code file and the target database operation code file based on the preset proxy identification code. The target database operation code file refers to the code file of the scene database.
[0043] The testing unit is used to perform coverage testing on the target front-end code file to obtain front-end coverage results, and to perform coverage testing on the target back-end code file to obtain back-end coverage results.
[0044] The generation unit is used to generate a database coverage result based on the target database operation code file and the basic code file of the scene database;
[0045] The display unit is used to display the front-end coverage results, the back-end coverage results, and the database coverage results in a complete chain.
[0046] On the other hand, the present invention also proposes an electronic device, the electronic device comprising:
[0047] Memory, which stores computer-readable instructions; and
[0048] The processor executes computer-readable instructions stored in the memory to implement the code coverage test method.
[0049] On the other hand, the present invention also proposes a computer-readable storage medium storing computer-readable instructions, which are executed by a processor in an electronic device to implement the code coverage testing method.
[0050] As can be seen from the above technical solutions, this application identifies the initial front-end code file based on the preset proxy identification code, enabling the association of target front-end code files, target back-end code files, and target database operation code files within the same request test scenario. Therefore, the preset proxy identification code allows for the acquisition of code from different operating environments within the same business scenario. Furthermore, by performing coverage testing on the target front-end code files, target back-end code files, and target database operation code files, since these files do not contain redundant interfering code, the accuracy of coverage testing for the request test scenario can be improved. Simultaneously, since coverage testing can be directly performed on code from different operating environments within the same business scenario, coverage testing efficiency can be improved. This application enhances the intuitiveness of the scenario coverage results for the request test scenario by providing a full-link display of the front-end coverage results, back-end coverage results, and database coverage results. This application is applicable to the fintech field, and through this application, it can improve the efficiency of code testing for different operating environments within the same business scenario for relevant personnel in the fintech field, thereby promoting the development of smart cities. Attached Figure Description
[0051] Figure 1 This is a flowchart of a preferred embodiment of the code coverage testing method of the present invention.
[0052] Figure 2 This is a schematic diagram of the first database syntax tree in this invention.
[0053] Figure 3 This is a schematic diagram of the second database syntax tree in this invention.
[0054] Figure 4 This is a functional block diagram of a preferred embodiment of the code coverage testing device of the present invention.
[0055] Figure 5 This is a schematic diagram of the structure of an electronic device that implements the code coverage testing method of the present invention. Detailed Implementation
[0056] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be described in detail below with reference to the accompanying drawings and specific embodiments.
[0057] like Figure 1 The diagram shown is a flowchart of a preferred embodiment of the code coverage testing method of the present invention. Depending on different requirements, the order of the steps in this flowchart can be changed, and some steps can be omitted.
[0058] The code coverage testing method described above can acquire and process relevant data based on artificial intelligence technology. Artificial intelligence (AI) is the theory, method, technology, and application system that uses digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, perceive the environment, acquire knowledge, and use that knowledge to obtain optimal results.
[0059] Foundational technologies for artificial intelligence generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing, operating / interactive systems, and mechatronics. AI software technologies mainly encompass computer vision, robotics, biometrics, speech processing, natural language processing, and machine learning / deep learning.
[0060] The code coverage testing method is applied to one or more electronic devices. The electronic device is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored computer-readable instructions. Its hardware includes, but is not limited to, microprocessors, application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), digital signal processors (DSPs), embedded devices, etc.
[0061] The electronic device can be any electronic product that can interact with the user, such as a personal computer, tablet computer, smartphone, personal digital assistant (PDA), game console, interactive network television (IPTV), smart wearable device, etc.
[0062] The electronic devices may include network devices and / or user devices. The network devices include, but are not limited to, single network electronic devices, groups of multiple network electronic devices, or cloud computing-based systems consisting of a large number of hosts or network electronic devices.
[0063] The network in which the electronic device is located includes, but is not limited to: the Internet, wide area network, metropolitan area network, local area network, virtual private network (VPN), etc.
[0064] The code coverage testing method described above is applied in the fintech field.
[0065] 101, retrieve the initial front-end code file for the request test scenario.
[0066] In at least one embodiment of the present invention, the request test scenario can be a business scenario in the field of financial technology, for example, the request test scenario can be the business scenario corresponding to sales system A.
[0067] The initial front-end code file refers to the request data packet related to the request test scenario, and the initial front-end code file is usually in the form of an HTTP file.
[0068] In at least one embodiment of the present invention, the electronic device acquires the initial front-end code file of the requested test scenario, including:
[0069] Get the request data packet;
[0070] Extract the scene identifier from the request data packet based on the preset scene field;
[0071] Match the scene identifier with the scene identification code of the requested test scene;
[0072] If the scene identifier matches the scene identification code, the request data packet is identified as the initial front-end code file.
[0073] The request data packet typically refers to an HTTP file generated by the electronic device. When a user searches for a specific service requirement in a pre-defined browser, the electronic device generates the corresponding request data packet.
[0074] The preset scene field can be a pre-defined field; for example, the preset scene field can be changjing.
[0075] The scene identifier is obtained by parsing the request data packet based on the preset scene field.
[0076] The scene identification code is used to uniquely identify the requested test scene.
[0077] The preset scenario field allows for the accurate extraction of the scenario identifier from the request data packet. Furthermore, by matching the scenario identification code that uniquely identifies the request test scenario with the scenario identifier, the initial front-end code file can be accurately filtered out from the obtained request data packet.
[0078] 102. The initial front-end code file is identified based on a preset proxy identification code to obtain the target front-end code file.
[0079] In at least one embodiment of the present invention, the preset agent identification code refers to the identification code corresponding to a pre-configured agent. For example, the preset agent identification code may be TranseID. Through the preset agent identification code, front-end code, back-end code, and SQL (Structured Query Language) code in the financial technology field can be associated.
[0080] The target front-end code file refers to the file obtained by writing the preset proxy identification code into the header code file of the initial front-end code file. The target front-end code file typically runs on a client-side environment, such as a mobile phone.
[0081] In at least one embodiment of the present invention, the electronic device identifies the initial front-end code file based on a preset proxy identification code to obtain the target front-end code file, including:
[0082] Create a proxy field based on a preset proxy identification code;
[0083] Locate the header code file corresponding to the preset header field from the initial front-end code file;
[0084] The proxy field and the preset proxy identification code are written into the header code file to obtain the target front-end code file corresponding to the initial front-end code file.
[0085] The proxy field is used to represent the field information to which the preset proxy identification code belongs.
[0086] The preset header field is used to represent the header file in the request data packet. For example, the preset header field can be Header.
[0087] The preset header field allows for accurate location of the header code file from the initial front-end code file. Furthermore, by writing the proxy field and the preset proxy identifier into the header code file, it is easy to associate the target front-end code file with the back-end code and SQL code in the same request test scenario.
[0088] 103. Run the target front-end code file and locate the target back-end code file and the target database operation code file based on the preset proxy identification code. The target database operation code file refers to the code file of the scene database.
[0089] In at least one embodiment of the present invention, the target backend code file refers to backend code that is in the same request testing scenario as the target frontend code file. The runtime environment of the target backend code file is typically a server.
[0090] The target database operation code file refers to the SQL code that is in the same request test scenario as the target front-end code file. The runtime environment of the target database operation code file is usually a database.
[0091] The scenario database refers to the operation database that runs the target database operation code file. The scenario database stores the business data of the requested test scenario, and may also include data from other business scenarios, such as financial data in the fintech field.
[0092] In at least one embodiment of the present invention, after the electronic device runs the target front-end code file, the back-end code and SQL code that are in the same request test scenario as the target front-end code file update their own code files accordingly, thereby obtaining the target back-end code file corresponding to the back-end code and the target database operation code file corresponding to the SQL code.
[0093] In at least one embodiment of the present invention, the electronic device locates the target backend code file and the target database operation code file based on the preset proxy identification code, including:
[0094] The response file is captured from the server communicating with the electronic device, and the response file containing the preset proxy identification code is identified as the target backend code file;
[0095] The operation file is obtained from the scenario database, and the operation file containing the preset agent identification code is identified as the target database operation code file.
[0096] The response file refers to the file generated by the server after responding to the request data packet from the electronic device.
[0097] The operation file refers to the file that records the database operations in the scenario database.
[0098] 104. Perform a coverage test on the target front-end code file to obtain the front-end coverage result, and perform a coverage test on the target back-end code file to obtain the back-end coverage result.
[0099] In at least one embodiment of the present invention, the front-end coverage result refers to the code information in the target front-end code file that has been tested.
[0100] The backend coverage result refers to the code information in the target backend code file that has been tested.
[0101] In at least one embodiment of the present invention, the electronic device performs a coverage test on the target front-end code file to obtain a front-end coverage result, including:
[0102] Retrieve tool code information for preset tools;
[0103] By invoking offline commands and scheduled commands, the tool code information is written into the target front-end code file to obtain the instrumented front-end code file;
[0104] Run the instrumented front-end code file to obtain the front-end coverage result.
[0105] The preset tool can be a tool for coverage testing, for example, the preset tool can be an Istanbul tool.
[0106] The tool code information refers to the information in the preset tool used to monitor code execution.
[0107] The offline command refers to the command that puts the program into the background for execution, and the timed command refers to the command that executes the program at regular intervals.
[0108] The tool code information is obtained through the preset tool. Since there is no need to create the tool code information, the efficiency of obtaining the tool code information is improved. Furthermore, by calling the offline command and the timed command, the tool code information can be written to the target front-end code file in an offline state on a timed basis. This can improve the generation efficiency of the instrumentation front-end code file without occupying the device resources of the electronic device. In turn, by directly running the instrumentation front-end code file, the generation efficiency of the front-end coverage result can be improved.
[0109] In at least one embodiment of the present invention, the electronic device performs a coverage test on the target backend code file to obtain backend coverage results, including:
[0110] Identify the Java Virtual Machine where the target backend code file resides;
[0111] The monitoring code is invoked from the Java Virtual Machine and loaded into the target backend code file to obtain the instrumented backend code file;
[0112] The instrumented backend code file is compiled, packaged, and run to obtain the backend overlay result.
[0113] The Java Virtual Machine (JVM) refers to an abstract computer that simulates various computer functions, and the JVM stores the target backend code file.
[0114] By calling the monitoring code of the Java Virtual Machine itself and writing it into the target backend code file, the generation efficiency of the instrumented backend code file can be improved. By compiling, packaging and running the instrumented backend code file, the generation convenience of the backend coverage result can be improved.
[0115] 105. Generate database coverage results based on the target database operation code file and the scenario database base code file.
[0116] In at least one embodiment of the present invention, the basic code file refers to the code information corresponding to the initialization of the scene database.
[0117] The database coverage result refers to the code information in the target database operation code file that has been tested.
[0118] In at least one embodiment of the present invention, the electronic device generates a database coverage result based on the target database operation code file and the scenario database base code file, including:
[0119] A first database syntax tree is constructed based on the target database operation code file, and a second database syntax tree is constructed based on the base code file;
[0120] Compare the first database syntax tree and the second database syntax tree to obtain the incremental object;
[0121] Obtain the calling object and the called object of the incremental object from the first database syntax tree;
[0122] The information corresponding to the incremental object, the calling object, and the called object are obtained from the target database operation code file as the database overwrite result.
[0123] The first database syntax tree represents the syntax structure of the target database operation code file in a tree-like form, and each node in the first database syntax tree represents a structure of the target database operation code file. For example... Figure 2 As shown, Figure 2 This is a schematic diagram of the first database syntax tree in this invention. From Figure 2 It can be seen that, Figure 2 The structure objects included are SELECT, A, B, C, D, E, F, G, X, Y, Z, K, and L.
[0124] The second database syntax tree represents the syntax structure of the base code file in a tree-like form, where each node in the second database syntax tree represents a structure of the base code file. For example... Figure 3 As shown, Figure 3This is a schematic diagram of the second database syntax tree in this invention. From Figure 3 It can be seen that, Figure 3 The structure objects included are SELECT, A, B, C, E, F, G, X, and Y.
[0125] The incremental object refers to a newly added structure object in the first database syntax tree compared to the second database syntax tree. (Combined with...) Figure 2-3 For example, the incremental objects are D, Z, K, and L.
[0126] The calling object refers to the structure object called by the incremental object in the first database syntax tree. (Combined) Figure 2-3 In the example, the calling object of the incremental object D is K, and the calling object of the incremental object K is L.
[0127] The invoked object refers to the structure object that the incremental object invokes in the first database syntax tree. (Combined) Figure 2-3 In the example, the called object of the incremental object Z is C, the called object of the incremental object L is K, and the called object of the incremental object K is D.
[0128] The database coverage result includes the code information corresponding to the incremental object in the target database operation code file, the code information corresponding to the calling object in the target database operation code file, and the code information corresponding to the called object in the target database operation code file.
[0129] By comparing the first database syntax tree and the second database syntax tree, the incremental object can be quickly obtained. Then, through the incremental object, the calling object and the called object can be quickly identified in the first database syntax tree, thereby improving the generation efficiency of the database overlay structure.
[0130] Specifically, the electronic device constructs a first database syntax tree based on the target database operation code file, including:
[0131] Lexical analysis is performed on the target database operation code file to obtain multiple structure objects and the object relationships between the multiple structure objects;
[0132] Based on the object relationship, structural objects without parent nodes are identified as root nodes, and structural objects without child nodes are identified as leaf nodes.
[0133] Construct an initial syntax tree based on the root node and the leaf nodes;
[0134] Based on the object relationships, the multiple structured objects are filled into the initial syntax tree to obtain the first database syntax tree.
[0135] By using the object relationships, the root node and the leaf nodes can be accurately identified, thereby improving the accuracy of constructing the initial syntax tree. Furthermore, by filling the initial syntax tree based on the object relationships, the accuracy of constructing the first database syntax tree is improved.
[0136] In other embodiments, the construction method of the second database syntax tree is similar to that of the first database syntax tree, and will not be described in detail here.
[0137] 106. The front-end coverage results, the back-end coverage results, and the database coverage results are displayed in their entirety.
[0138] It should be emphasized that, in order to further ensure the privacy and security of the aforementioned front-end coverage results, back-end coverage results, and database coverage results, the aforementioned front-end coverage results, back-end coverage results, and database coverage results can also be stored in a node of a blockchain.
[0139] In at least one embodiment of the present invention, the electronic device displays the front-end coverage result, the back-end coverage result, and the database coverage result across the entire chain, including:
[0140] Get the page dimensions of the visualization page;
[0141] Based on the page size, the front-end coverage result, the back-end coverage result, and the database coverage result, the visualization page is divided into a front-end display area, a back-end display area, and a database display area.
[0142] Based on the code volume and execution order of the front-end coverage results, the front-end coverage results are displayed in the front-end display area;
[0143] Based on the code volume and execution order of the backend coverage results, the backend coverage results are displayed in the backend display area;
[0144] Based on the amount of code and the execution order of the database coverage results, the database coverage results are displayed in the database display area.
[0145] The visualization page can be the display screen of the electronic device, and the page size refers to the length and width of the visualization page.
[0146] By combining the page size, the front-end coverage result, the back-end coverage result, and the database coverage result to divide the visualization page, the rationality of the division of the front-end display area, the back-end display area, and the database display area can be improved. Then, based on the corresponding amount of code and the code execution order, the full-link display of the front-end coverage result, the back-end coverage result, and the database coverage result can be reasonably realized.
[0147] Specifically, the electronic device divides the visualization page based on the page size, the front-end coverage result, the back-end coverage result, and the database coverage result to obtain a front-end display area, a back-end display area, and a database display area, including:
[0148] The total amount of code for the front-end coverage results, the back-end coverage results, and the database coverage results is calculated.
[0149] Based on the ratio of the code volume of the front-end coverage results to the total code volume, the ratio of the code volume of the back-end coverage results to the total code volume, the ratio of the code volume of the database coverage results to the total code volume, and the page size, the visualization page is divided to obtain the front-end display area, the back-end display area, and the database display area.
[0150] By combining the corresponding amount of code and the page size, the front-end display area, the back-end display area, and the database display area can be reasonably divided.
[0151] Specifically, the electronic device displays the front-end coverage result in the front-end display area based on the code volume and code execution order of the front-end coverage result, including:
[0152] If the code size of the front-end coverage result is greater than the configured display size of the front-end display area, then based on the code execution order, the target coverage result is extracted from the front-end coverage result in a first-to-last order, and the code size of the target coverage result is equal to the configured display size;
[0153] Write the target coverage result into the front-end display area, and call the content display component to hide and display the remaining front-end coverage results other than the target coverage result in the front-end display area.
[0154] In other embodiments, the way in which the backend overlay results are displayed to the backend display area and the way in which the database overlay results are displayed to the database display area are similar to the way in which the frontend overlay results are displayed to the frontend display area, and will not be described in detail here.
[0155] As can be seen from the above technical solutions, this application identifies the initial front-end code file based on the preset proxy identification code, enabling the association of target front-end code files, target back-end code files, and target database operation code files within the same request test scenario. Therefore, the preset proxy identification code allows for the acquisition of code from different operating environments within the same business scenario. Furthermore, by performing coverage testing on the target front-end code files, target back-end code files, and target database operation code files, since these files do not contain redundant interfering code, the accuracy of coverage testing for the request test scenario can be improved. Simultaneously, since coverage testing can be directly performed on code from different operating environments within the same business scenario, coverage testing efficiency can be improved. This application enhances the intuitiveness of the scenario coverage results for the request test scenario by providing a full-link display of the front-end coverage results, back-end coverage results, and database coverage results. This application is applicable to the fintech field, and through this application, it can improve the efficiency of code testing for different operating environments within the same business scenario for relevant personnel in the fintech field, thereby promoting the development of smart cities.
[0156] like Figure 4 The diagram shown is a functional block diagram of a preferred embodiment of the code coverage testing device of the present invention. The code coverage testing device 11 includes an acquisition unit 110, an identification unit 111, a positioning unit 112, a testing unit 113, a generation unit 114, and a display unit 115. The module / unit referred to in this invention refers to a series of computer-readable instruction segments that can be acquired by the processor 13 and perform a fixed function, and are stored in the memory 12. In this embodiment, the functions of each module / unit will be described in detail in subsequent embodiments.
[0157] The code coverage testing device is used in the fintech field.
[0158] Unit 110 is used to obtain the initial front-end code file for the request test scenario;
[0159] Identification unit 111 is used to identify the initial front-end code file based on a preset proxy identification code to obtain the target front-end code file;
[0160] The positioning unit 112 is used to run the target front-end code file and locate the target back-end code file and the target database operation code file based on the preset agent identification code. The target database operation code file refers to the code file of the scene database.
[0161] Test unit 113 is used to perform coverage testing on the target front-end code file to obtain front-end coverage results, and to perform coverage testing on the target back-end code file to obtain back-end coverage results;
[0162] The generation unit 114 is used to generate a database coverage result based on the target database operation code file and the scene database base code file;
[0163] The display unit 115 is used to display the front-end coverage results, the back-end coverage results, and the database coverage results in a complete chain.
[0164] In at least one embodiment of the present invention, the acquiring unit 110 is further configured to:
[0165] Get the request data packet;
[0166] Extract the scene identifier from the request data packet based on the preset scene field;
[0167] Match the scene identifier with the scene identification code of the requested test scene;
[0168] If the scene identifier matches the scene identification code, the request data packet is identified as the initial front-end code file.
[0169] In at least one embodiment of the present invention, the identification unit 111 is further configured to:
[0170] The initial front-end code file is identified based on a preset proxy identification code, resulting in the target front-end code file, which includes:
[0171] Create a proxy field based on a preset proxy identification code;
[0172] Locate the header code file corresponding to the preset header field from the initial front-end code file;
[0173] The proxy field and the preset proxy identification code are written into the header code file to obtain the target front-end code file corresponding to the initial front-end code file.
[0174] In at least one embodiment of the present invention, the test unit 113 is further configured to:
[0175] The target front-end code file was subjected to a coverage test, and the front-end coverage results included:
[0176] Retrieve tool code information for preset tools;
[0177] By invoking offline commands and scheduled commands, the tool code information is written into the target front-end code file to obtain the instrumented front-end code file;
[0178] Run the instrumented front-end code file to obtain the front-end coverage result.
[0179] In at least one embodiment of the present invention, the test unit 113 is further configured to:
[0180] The target backend code file was subjected to coverage testing, and the backend coverage results included:
[0181] Identify the Java Virtual Machine where the target backend code file resides;
[0182] The monitoring code is invoked from the Java Virtual Machine and loaded into the target backend code file to obtain the instrumented backend code file;
[0183] The instrumented backend code file is compiled, packaged, and run to obtain the backend overlay result.
[0184] In at least one embodiment of the present invention, the generating unit 114 is further configured to:
[0185] A first database syntax tree is constructed based on the target database operation code file, and a second database syntax tree is constructed based on the base code file;
[0186] Compare the first database syntax tree and the second database syntax tree to obtain the incremental object;
[0187] Obtain the calling object and the called object of the incremental object from the first database syntax tree;
[0188] The information corresponding to the incremental object, the calling object, and the called object are obtained from the target database operation code file as the database overwrite result.
[0189] In at least one embodiment of the present invention, the display unit 115 is further configured to:
[0190] Get the page dimensions of the visualization page;
[0191] Based on the page size, the front-end coverage result, the back-end coverage result, and the database coverage result, the visualization page is divided into a front-end display area, a back-end display area, and a database display area.
[0192] Based on the code volume and execution order of the front-end coverage results, the front-end coverage results are displayed in the front-end display area;
[0193] Based on the code volume and execution order of the backend coverage results, the backend coverage results are displayed in the backend display area;
[0194] Based on the amount of code and the execution order of the database coverage results, the database coverage results are displayed in the database display area.
[0195] As can be seen from the above technical solutions, this application identifies the initial front-end code file based on the preset proxy identification code, enabling the association of target front-end code files, target back-end code files, and target database operation code files within the same request test scenario. Therefore, the preset proxy identification code allows for the acquisition of code from different operating environments within the same business scenario. Furthermore, by performing coverage testing on the target front-end code files, target back-end code files, and target database operation code files, since these files do not contain redundant interfering code, the accuracy of coverage testing for the request test scenario can be improved. Simultaneously, since coverage testing can be directly performed on code from different operating environments within the same business scenario, coverage testing efficiency can be improved. This application enhances the intuitiveness of the scenario coverage results for the request test scenario by providing a full-link display of the front-end coverage results, back-end coverage results, and database coverage results. This application is applicable to the fintech field, and through this application, it can improve the efficiency of code testing for different operating environments within the same business scenario for relevant personnel in the fintech field, thereby promoting the development of smart cities.
[0196] like Figure 5 The diagram shown is a schematic representation of the structure of an electronic device that implements the code coverage testing method of the present invention.
[0197] In one embodiment of the present invention, the electronic device 1 includes, but is not limited to, a memory 12, a processor 13, and computer-readable instructions stored in the memory 12 and executable on the processor 13, such as a code coverage test program.
[0198] Those skilled in the art will understand that the schematic diagram is merely an example of electronic device 1 and does not constitute a limitation on electronic device 1. It may include more or fewer components than shown in the diagram, or combine certain components, or different components. For example, electronic device 1 may also include input / output devices, network access devices, buses, etc.
[0199] The processor 13 can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or any conventional processor. The processor 13 is the computing core and control center of the electronic device 1, connecting various parts of the electronic device 1 through various interfaces and lines, and executing the operating system of the electronic device 1, as well as various installed application programs and program code.
[0200] For example, the computer-readable instructions can be divided into one or more modules / units, which are stored in the memory 12 and executed by the processor 13 to complete the present invention. The one or more modules / units can be a series of computer-readable instruction segments capable of performing a specific function, which describe the execution process of the computer-readable instructions in the electronic device 1. For example, the computer-readable instructions can be divided into an acquisition unit 110, an identification unit 111, a positioning unit 112, a testing unit 113, a generation unit 114, and a display unit 115.
[0201] The memory 12 can be used to store the computer-readable instructions and / or modules. The processor 13 implements various functions of the electronic device 1 by running or executing the computer-readable instructions and / or modules stored in the memory 12 and calling the data stored in the memory 12. The memory 12 may mainly include a program storage area and a data storage area. The program storage area may store the operating system, at least one application program required for a function (such as sound playback function, image playback function, etc.), etc.; the data storage area may store data created according to the use of the electronic device, etc. The memory 12 may include non-volatile and volatile memory, such as: hard disk, memory, plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, at least one disk storage device, flash memory device, or other storage devices.
[0202] The memory 12 can be the external memory and / or internal memory of the electronic device 1. Furthermore, the memory 12 can be a physical memory, such as a memory module, a TF card (Trans-flash Card), etc.
[0203] If the modules / units integrated in the electronic device 1 are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments of the present invention can also be implemented by instructing related hardware through computer-readable instructions. The computer-readable instructions can be stored in a computer-readable storage medium, and when executed by a processor, the computer-readable instructions can implement the steps of the various method embodiments described above.
[0204] The computer-readable instructions include computer-readable instruction code, which may be in the form of source code, object code, executable file, or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying the computer-readable instruction code, recording medium, USB flash drive, portable hard drive, magnetic disk, optical disk, computer memory, read-only memory (ROM), and random access memory (RAM).
[0205] The blockchain referred to in this invention is a novel application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanisms, and encryption algorithms. Essentially, a blockchain is a decentralized database, a chain of data blocks linked together using cryptographic methods. Each data block contains information about a batch of network transactions, used to verify the validity of the information (anti-counterfeiting) and generate the next block. A blockchain can include an underlying blockchain platform, a platform product service layer, and an application service layer.
[0206] Combination Figure 1 The memory 12 in the electronic device 1 stores computer-readable instructions to implement a code coverage testing method, and the processor 13 can execute the computer-readable instructions to achieve the following:
[0207] Obtain the initial front-end code file for the request test scenario;
[0208] The initial front-end code file is identified based on a preset proxy identification code to obtain the target front-end code file;
[0209] Run the target front-end code file, and locate the target back-end code file and the target database operation code file based on the preset proxy identification code. The target database operation code file refers to the code file of the scene database.
[0210] A coverage test is performed on the target front-end code file to obtain the front-end coverage result, and a coverage test is performed on the target back-end code file to obtain the back-end coverage result;
[0211] Generate database coverage results based on the target database operation code file and the scenario database base code file;
[0212] The front-end coverage results, the back-end coverage results, and the database coverage results are displayed in their entirety.
[0213] Specifically, the specific implementation method of the processor 13 for the above-mentioned computer-readable instructions can be found in [reference needed]. Figure 1 The descriptions of the relevant steps in the corresponding embodiments are not repeated here.
[0214] In the several embodiments provided by this invention, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of modules is only a logical functional division, and other division methods may be used in actual implementation.
[0215] The computer-readable storage medium stores computer-readable instructions, which, when executed by the processor 13, are used to perform the following steps:
[0216] Obtain the initial front-end code file for the request test scenario;
[0217] The initial front-end code file is identified based on a preset proxy identification code to obtain the target front-end code file;
[0218] Run the target front-end code file, and locate the target back-end code file and the target database operation code file based on the preset proxy identification code. The target database operation code file refers to the code file of the scene database.
[0219] A coverage test is performed on the target front-end code file to obtain the front-end coverage result, and a coverage test is performed on the target back-end code file to obtain the back-end coverage result;
[0220] Generate database coverage results based on the target database operation code file and the scenario database base code file;
[0221] The front-end coverage results, the back-end coverage results, and the database coverage results are displayed in their entirety.
[0222] The modules described as separate components may or may not be physically separate. The components shown as modules may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.
[0223] Furthermore, the functional modules in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or in the form of hardware plus software functional modules.
[0224] Therefore, the embodiments should be considered exemplary and non-limiting in all respects, and the scope of the invention is defined by the appended claims rather than the foregoing description. Thus, all variations falling within the meaning and scope of equivalents of the claims are intended to be embraced within the invention. No appended diagram markings in the claims should be construed as limiting the scope of the claims.
[0225] Furthermore, it is clear that the word "comprising" does not exclude other units or steps, and the singular does not exclude the plural. The multiple units or devices described may also be implemented by a single unit or device through software or hardware. Terms such as "first," "second," etc., are used to indicate names and do not indicate any specific order.
[0226] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit it. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of the present invention without departing from the spirit and scope of the technical solutions of the present invention.
Claims
1. A code coverage testing method, characterized in that, The code coverage testing method includes: Obtaining the initial front-end code file for a request test scenario includes: obtaining a request data packet; extracting a scenario identifier from the request data packet based on a preset scenario field; matching the scenario identifier with the scenario identification code of the request test scenario; if the scenario identifier and the scenario identification code match successfully, then determining the HTTP file corresponding to the request data packet as the initial front-end code file; The initial front-end code file is identified based on a preset proxy identification code to obtain the target front-end code file; Run the target front-end code file, and locate the target back-end code file and the target database operation code file based on the preset proxy identification code. The target database operation code file refers to the code file of the scene database. A coverage test is performed on the target front-end code file to obtain the front-end coverage result, and a coverage test is performed on the target back-end code file to obtain the back-end coverage result; Generate database coverage results based on the target database operation code file and the scenario database base code file; The front-end coverage results, the back-end coverage results, and the database coverage results are displayed in their entirety.
2. The code coverage testing method as described in claim 1, characterized in that, The step of identifying the initial front-end code file based on a preset proxy identification code to obtain the target front-end code file includes: Create a proxy field based on a preset proxy identification code; Locate the header code file corresponding to the preset header field from the initial front-end code file. The header code file is a code file used to record the headers of HTTP requests. The proxy field and the preset proxy identification code are written into the header code file to obtain the target front-end code file corresponding to the initial front-end code file.
3. The code coverage testing method as described in claim 1, characterized in that, The coverage test performed on the target front-end code file to obtain the front-end coverage results includes: Retrieve tool code information for preset tools; By invoking offline commands and scheduled commands, the tool code information is written into the target front-end code file to obtain the instrumented front-end code file; Run the instrumented front-end code file to obtain the front-end coverage result.
4. The code coverage testing method as described in claim 1, characterized in that, The coverage test performed on the target backend code file to obtain the backend coverage results include: Identify the Java Virtual Machine where the target backend code file resides; The monitoring code is invoked from the Java Virtual Machine and loaded into the target backend code file to obtain the instrumented backend code file; The instrumented backend code file is compiled, packaged, and run to obtain the backend overlay result.
5. The code coverage testing method as described in claim 1, characterized in that, The generation of database coverage results based on the target database operation code file and the scenario database base code file includes: A first database syntax tree is constructed based on the target database operation code file, and a second database syntax tree is constructed based on the base code file; Compare the first database syntax tree and the second database syntax tree to obtain the incremental object; Obtain the calling object and the called object of the incremental object from the first database syntax tree; The information corresponding to the incremental object, the calling object, and the called object are obtained from the target database operation code file as the database overwrite result.
6. The code coverage testing method as described in claim 1, characterized in that, The full-link display of the front-end coverage results, the back-end coverage results, and the database coverage results includes: Get the page dimensions of the visualization page; Based on the page size, the front-end coverage result, the back-end coverage result, and the database coverage result, the visualization page is divided into a front-end display area, a back-end display area, and a database display area. Based on the code volume and execution order of the front-end coverage results, the front-end coverage results are displayed in the front-end display area; Based on the code volume and execution order of the backend coverage results, the backend coverage results are displayed in the backend display area; Based on the amount of code and the execution order of the database coverage results, the database coverage results are displayed in the database display area.
7. A code coverage testing device, characterized in that, The code coverage testing device includes: The acquisition unit is used to acquire the initial front-end code file of the request test scenario, including: acquiring the request data packet; extracting the scenario identifier from the request data packet based on a preset scenario field; matching the scenario identifier with the scenario identification code of the request test scenario; if the scenario identifier and the scenario identification code match successfully, then determining the HTTP file corresponding to the request data packet as the initial front-end code file; The identification unit is used to identify the initial front-end code file based on a preset proxy identification code to obtain the target front-end code file; The positioning unit is used to run the target front-end code file and locate the target back-end code file and the target database operation code file based on the preset proxy identification code. The target database operation code file refers to the code file of the scene database. The testing unit is used to perform coverage testing on the target front-end code file to obtain front-end coverage results, and to perform coverage testing on the target back-end code file to obtain back-end coverage results. The generation unit is used to generate a database coverage result based on the target database operation code file and the basic code file of the scene database; The display unit is used to display the front-end coverage results, the back-end coverage results, and the database coverage results in a complete chain.
8. An electronic device, characterized in that, The electronic device includes: Memory, which stores computer-readable instructions; and The processor executes computer-readable instructions stored in the memory to implement the code coverage testing method as described in any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-readable instructions, which are executed by a processor in an electronic device to implement the code coverage testing method as described in any one of claims 1 to 6.