Code coverage rate test report generation method and device, equipment and storage medium
By integrating coverage testing tools and Vue components on the test platform, automatically generating code coverage testing reports, the problem of low efficiency in the generation of test reports in the existing technology is solved, and a more efficient code testing process is achieved.
Patent Information
- Application Number
- CN202411828910.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-12
- Publication Date
- 2025-04-15
AI Technical Summary
Existing code coverage testing tools are difficult to generate efficient test reports, and developers need to manually integrate and filter data, affecting the efficiency of code testing.
By integrating coverage testing tools and Vue components on the test platform, the automatic generation of code coverage test reports is achieved. The specific steps include importing source code and test scripts, disassembling into branch code, creating data blocks, building a visual interface, selecting branch indexes, performing coverage tests, and generating and displaying test reports through Vue components.
It realizes flexible configuration and automatic generation of code coverage test reports, improves testing efficiency, and reduces the manual operation and data processing burden of developers.
Smart Images

Figure CN119829430A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of code testing technology, and in particular to a method, device, equipment and storage medium for generating a code coverage test report. Background Art
[0002] Code coverage is an important indicator in the program development process. Currently, there are some coverage testing tools on the market. Some programming languages have also integrated some libraries for monitoring code coverage. The source code is run according to the test script corresponding to the test case, and the code coverage is collected during the running process. In order to analyze the code coverage, it is usually necessary to generate a test report based on the coverage of different branches or modules. However, the existing testing tools or function libraries can usually only output the underlying coverage, requiring developers to manually integrate or filter the coverage, and then generate a test report based on the filtered data. The efficiency of generating test reports is low, which affects the efficiency of code testing. Summary of the invention
[0003] The present invention aims to solve at least one of the technical problems existing in the prior art. To this end, the present invention proposes a code coverage test report generation method, device, equipment, and storage medium, which can flexibly configure the data range of the test report, automatically generate the test report, and improve the test efficiency.
[0004] In a first aspect, an embodiment of the present invention provides a method for generating a code coverage test report, which is applied to a test platform, wherein the test platform integrates a coverage test tool and a Vue component, and the method includes:
[0005] Importing a target source code and a corresponding target test script, decomposing the target source code into a plurality of first branch codes, and determining a first branch script corresponding to each of the first branch codes from the target test script;
[0006] Creating multiple first data blocks, determining the branch name of the first branch code as the first branch index of the first data block, and saving the associated first branch code and the first branch script to the same first data block;
[0007] Building a first visualization interface based on the Vue component, generating a first option based on each of the first branch indexes in the first visualization interface, and obtaining a target branch index selected by a target user in the first option;
[0008] Determine the target data block based on the target branch index fed back by the Vue component, input the target branch code and target branch script saved in the target data block into the coverage testing tool for coverage testing, and obtain the target coverage output by the coverage testing tool;
[0009] A second visualization interface is constructed in the Vue component, a target test report is generated based on the target coverage through the Vue component, the target test report is displayed in the second visualization interface, and the target test report is saved to the target data block.
[0010] According to some embodiments of the present invention, generating a target test report based on the target coverage by the Vue component includes:
[0011] Converting the target coverage into formatted data based on a preset target format;
[0012] The formatted data is sent to the Vue component, and the target test report is generated based on the formatted data by the Vue component.
[0013] According to some embodiments of the present invention, the test platform is configured with multiple available K8S servers, and the target source code and the corresponding target test script are imported, including:
[0014] In response to the import request triggered by the target user, a third visualization interface is constructed through the Vue component, preset project indexes of various preset code projects are displayed on the third visualization interface, and the target project index is determined based on the selection operation of the target user;
[0015] Determine the target code project and the target K8S server based on the target project index fed back by the Vue component;
[0016] Import the target source code and the target test script into the target K8S server.
[0017] According to some embodiments of the present invention, creating a plurality of first data blocks includes:
[0018] Obtain a previously created second data block of the target K8S server, wherein the second data block stores associated second branch code and second branch script, and the second branch code belongs to the target code project;
[0019] Traversing the second branch indexes of the second data blocks based on the first branch names, wherein the second branch indexes are branch names of the corresponding second branch codes;
[0020] Save any first branch code and first branch script that are successfully matched to the second branch index to the corresponding second data block;
[0021] On the target K8S server, a corresponding first data block is created for each first branch code that fails to match the second branch index.
[0022] According to some embodiments of the present invention, generating a first option based on each of the first branch indexes in the first visualization interface, and obtaining a target branch index selected by a target user in the first option includes:
[0023] Generating a second option on the first visual interface, wherein the second option includes a full test item and an incremental test item;
[0024] In response to the target user selecting the full test item in the second option, adding the first branch index and the second branch index of the target K8S server to the first option;
[0025] In response to the target user selecting the incremental test item in the second option, constructing the first option based on all the first branch indexes of the target K8S server, constructing the third option based on all the second branch indexes of the target K8S server, and obtaining the reference branch index selected by the target user in the third option;
[0026] The target branch index selected by the target user in the first option is obtained.
[0027] According to some embodiments of the present invention, when the target user selects the incremental test item in the second option, the target branch code and the target branch script saved in the target data block are input into the coverage testing tool for coverage testing, and the target coverage output by the coverage testing tool is obtained, including:
[0028] Determine the second data block corresponding to the reference branch index as a reference data block, and determine the second branch code stored in the reference data block as a reference branch code;
[0029] Inputting the reference branch code, the target branch code and the target branch script into the coverage testing tool, the coverage testing tool determining the incremental branch code based on the code difference between the reference branch code and the target branch code;
[0030] Determine the incremental branch script corresponding to the incremental branch code from the target branch script;
[0031] Run the incremental branch script to obtain the target coverage.
[0032] According to some embodiments of the present invention, obtaining the target coverage output by the coverage testing tool includes:
[0033] Collecting real-time coverage output by the coverage testing tool in real time;
[0034] A preset coverage rate threshold is obtained, and when the real-time coverage rate is less than the coverage rate threshold, the real-time coverage rate is sent to the Vue component, and abnormal prompt information is displayed on the second visualization interface.
[0035] In a second aspect, an embodiment of the present invention provides a code coverage test report generating device, comprising at least one control processor and a memory for communicating with the at least one control processor; the memory stores instructions executable by the at least one control processor, and the instructions are executed by the at least one control processor so that the at least one control processor can execute the code coverage test report generating method as described in the first aspect above.
[0036] In a third aspect, an embodiment of the present invention provides an electronic device, comprising the device for generating a code coverage test report as described in the second aspect above.
[0037] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium storing computer-executable instructions, wherein the computer-executable instructions are used to execute the code coverage test report generation method as described in the first aspect above.
[0038] The code coverage test report generation method according to the embodiment of the present invention has at least the following beneficial effects: importing a target source code and a corresponding target test script, disassembling the target source code into a plurality of first branch codes, and determining the first branch script corresponding to each of the first branch codes from the target test script; creating a plurality of first data blocks, determining the branch name of the first branch code as the first branch index of the first data block, and saving the associated first branch code and the first branch script to the same first data block; constructing a first visualization interface based on the Vue component, generating a first option based on each of the first branch indexes in the first visualization interface, and obtaining the target branch index selected by the target user in the first option; determining a target data block based on the target branch index fed back by the Vue component, inputting the target branch code and the target branch script saved in the target data block into the coverage test tool for coverage testing, and obtaining the target coverage output by the coverage test tool; constructing a second visualization interface in the Vue component, generating a target test report based on the target coverage through the Vue component, displaying the target test report in the second visualization interface, and saving the target test report to the target data block. According to the technical solution of the embodiment of the present invention, the source code can be split and saved in different data blocks and the corresponding branch index can be constructed. The target user selects the target branch index according to the test requirements in the visual interface to achieve flexible selection of test branches; the corresponding branch code and test script are input into the coverage test tool to complete the coverage test, and the target test report is automatically generated and displayed through the Vue component. The data interaction between the coverage test tool and the Vue component is realized through the test platform, thereby improving the generation efficiency of the coverage test report and improving the testing efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] Figure 1 is a schematic diagram of a test platform provided by an embodiment of the present invention;
[0040] Figure 2 is a flowchart of a method for generating a code coverage test report provided by another embodiment of the present invention;
[0041] Figure 3 is a complete flow chart of a method for generating a code coverage test report provided by another embodiment of the present invention;
[0042] Figure 4 It is a structural diagram of a code coverage test report generating device provided by another embodiment of the present invention. DETAILED DESCRIPTION
[0043] Embodiments of the present invention are described in detail below, examples of which are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and cannot be understood as limiting the present invention.
[0044] In the description of the present invention, it should be understood that descriptions involving orientations, such as up, down, front, back, left, right, etc., and orientations or positional relationships indicated are based on the orientations or positional relationships shown in the accompanying drawings, and are only for the convenience of describing the present invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore should not be understood as a limitation on the present invention.
[0045] In the description of the present invention, "several" means one or more, "more" means more than two, "greater than", "less than", "exceed" etc. are understood as not including the number itself, and "above", "below", "within" etc. are understood as including the number itself. If there is a description of "first" or "second", it is only used for the purpose of distinguishing the technical features, and cannot be understood as indicating or implying the relative importance or implicitly indicating the number of the indicated technical features or implicitly indicating the order of the indicated technical features.
[0046] In the description of the present invention, unless otherwise clearly defined, terms such as setting, installing, connecting, etc. should be understood in a broad sense, and technicians in the relevant technical field can reasonably determine the specific meanings of the above terms in the present invention based on the specific content of the technical solution.
[0047] The following is an explanation of the technical terms that appear in the embodiments of the present application:
[0048] Vue.js (Vue for short) is a progressive JavaScript framework for building user interfaces, often used to build single-page applications (SPAs). At its core is a responsive data binding system and componentized structure that allows developers to easily build complex user interfaces.
[0049] K8S is the abbreviation of Kubernetes, which is an open source container orchestration and management system for automating the deployment, expansion and management of containerized applications.
[0050] An embodiment of the present invention provides a method, apparatus, device, and storage medium for generating a code coverage test report, wherein the method for generating a code coverage test report includes: importing a target source code and a corresponding target test script, decomposing the target source code into multiple first branch codes, and determining the first branch script corresponding to each first branch code from the target test script; creating multiple first data blocks, determining the branch name of the first branch code as the first branch index of the first data block, and saving the associated first branch code and the first branch script to the same first data block; constructing a first visualization interface based on the Vue component, generating a first option based on each first branch index in the first visualization interface, and obtaining the target branch index selected by the target user in the first option; determining a target data block based on the target branch index fed back by the Vue component, inputting the target branch code and the target branch script saved in the target data block into the coverage test tool for coverage testing, and obtaining the target coverage output by the coverage test tool; constructing a second visualization interface in the Vue component, generating a target test report based on the target coverage through the Vue component, displaying the target test report in the second visualization interface, and saving the target test report to the target data block. According to the technical solution of the embodiment of the present invention, the source code can be split and saved in different data blocks and the corresponding branch index can be constructed. The target user selects the target branch index according to the test requirements in the visual interface to achieve flexible selection of test branches; the corresponding branch code and test script are input into the coverage test tool to complete the coverage test, and the target test report is automatically generated and displayed through the Vue component. The data interaction between the coverage test tool and the Vue component is realized through the test platform, thereby improving the generation efficiency of the coverage test report and improving the testing efficiency.
[0051] First, refer to Figure 1 , Figure 1 This is a schematic diagram of a test platform provided in an embodiment of the present invention. The test platform in this embodiment includes a coverage test tool 30 and a Vue component 20.
[0052] It should be noted that the coverage testing tool 30 may adopt existing tools that can implement code coverage testing when code and test scripts are input, for example, using Python's coverage library.
[0053] It should be noted that the Vue component 20 is a view building component developed based on Vue.js, which can build relevant visual interfaces and corresponding options according to the input content. Those skilled in the art are familiar with how to build relevant visual interfaces based on the Vue component 20, and will not go into details here.
[0054] In addition, the test platform of this embodiment also includes multiple available K8S servers 40, each of which is used to store the source code and test scripts of a preset code project to achieve code isolation of different projects. Each available K8S server can use different containers as different data blocks,
[0055] The following is based on the Figure 1 The test platform shown further illustrates the technical solution of the embodiment of the present invention.
[0056] Reference Figure 2 , Figure 2 A flowchart of a method for generating a code coverage test report provided by an embodiment of the present invention, the method for generating a code coverage test report includes but is not limited to the following steps:
[0057] S10, importing a target source code and a corresponding target test script, decomposing the target source code into a plurality of first branch codes, and determining a first branch script corresponding to each first branch code from the target test script;
[0058] S20, creating multiple first data blocks, determining the branch name of the first branch code as the first branch index of the first data block, and saving the associated first branch code and the first branch script to the same first data block;
[0059] S30, constructing a first visualization interface based on the Vue component, generating a first option based on each first branch index in the first visualization interface, and obtaining a target branch index selected by the target user in the first option;
[0060] S40, determining a target data block based on the target branch index fed back by the Vue component, inputting the target branch code and the target branch script saved in the target data block into a coverage test tool for coverage testing, and obtaining a target coverage output by the coverage test tool;
[0061] S50, constructing a second visualization interface in the Vue component, generating a target test report based on the target coverage through the Vue component, displaying the target test report in the second visualization interface, and saving the target test report to the target data block.
[0062] It should be noted that the target source code can be an imported code file, or a code package encapsulating multiple code files, and the complete target source code can be identified after the test platform is imported. The target source code of this embodiment can be the complete code of an application, or the code of a functional module. For example, after updating a functional module of an application, the target source code of the functional module is re-imported for coverage testing. This embodiment does not limit the scale of the target source code.
[0063] It should be noted that the target test script is a script that automatically calls the target source code for coverage testing. Given the target source code, those skilled in the art are familiar with how to obtain the target test script based on the test case, which will not be repeated here.
[0064] It is worth noting that the target source code of this embodiment can be split into multiple first branch codes, and each first branch code can correspond to a branch of the target source code, such as a function, a functional module, a type, etc. The branch granularity can be determined according to the actual needs of the coverage test. The test platform can identify the branch code according to the keywords used in programming, such as the if keyword, and each first branch code corresponds to a branch name. The function can use the function name, the functional module can use the functional module name, and the judgment branch can use the variable name used for judgment as the branch name, which can uniquely identify each branch code. It is worth noting that the first branch script is used to test the corresponding first branch code. For example, when writing the target test script, each first branch script can use the same name as the first branch code, so that when parsing the target branch script, it can be divided by the name of the function or functional module, and paired with the corresponding first branch code.
[0065] It should be noted that this embodiment allocates an independent data block to each first branch code and the corresponding first branch script in the test platform, uses the branch name as the first branch index of the first data block, and associates the storage address of the first data block with the first branch index, so that after selecting the target index branch in the first visual interface, the target data block can be located according to the storage address corresponding to the target index branch, and the target branch code and target branch script stored therein can be obtained.
[0066] For example, Figure 1 As shown, the target source code 11 is divided into 4 branch codes, and the target test script 12 is divided into 4 branch scripts, wherein branch code 1 corresponds to branch script 1, branch code 2 corresponds to branch script 2, and so on. Four first data blocks 13 are constructed in the test platform, data block 1 stores branch code 1 and branch script 1, data block 2 stores branch code 2 and branch script 2, and so on. The first branch index of database 1 adopts the name branch A-1 of branch code 1, the first branch index of database 2 adopts the name branch A-2 of branch code 2, and so on.
[0067] It should be noted that the principle of building a visual interface based on the Vue component is a technology well known to those skilled in the art and will not be elaborated here. After importing the target source code, the operation of creating the first data block is an internal processing flow of the test platform and is not visible to the target user. After completing the processing of the first data block, the test platform automatically calls the Vue component to build the first visual interface and builds the first option based on the first branch index. The target user can select any number of first branch indexes as target branch indexes in the first option of the first visual interface, thereby achieving flexible configuration of the coverage test. This embodiment does not limit the number of target branch indexes.
[0068] It should be noted that after the target user selects the target branch index, the Vue component target branch index is fed back to the test platform. The test platform locates the target data block according to the storage address corresponding to the target branch index, and determines the first branch code stored in the target data block as the target branch code, and the first branch script as the target branch script. The target branch code and the target branch script are input into the coverage test tool for coverage testing to obtain the target coverage. The specific working principle of the coverage test tool will not be elaborated here. Of course, when there are multiple target branch codes, the coverage test tool can be executed in sequence, and no further description will be given here.
[0069] It is worth noting that the first option can also set options that represent multiple first branch indexes. For example, if an option is set to "Select All", the entire target source code and target test script will be used as the test target, and the relevant content will be directly obtained from all the first data blocks. Moreover, when splitting the code branches, the forward and backward calling relationships between the codes can be saved, so the target source code can be restored for coverage testing. For another example, an option can be set to "Function A", and a mapping table can be maintained on the test platform to record that "Function A" corresponds to multiple first data blocks. The first branch codes in these first data blocks jointly implement "Function A", and the corresponding first data blocks can be used as target data blocks, thereby realizing flexible configuration of test targets.
[0070] For example, Figure 1As shown, the first visualization interface 21 can be displayed on the user terminal of the target user. For example, the target user accesses the test platform through a computer. After the target source code 11 and the target test script 12 are imported into the login interface of the test platform, the test platform completes the relevant processing of the first data block 13, and generates the first visualization interface 21 through the Vue component 20 and pushes it to the computer of the target user. The first visualization interface 21 displays a first option 211. After the first option 211 is expanded, a check box can be constructed for each option, so that the target user can select any number of target branch indexes in the first option 211. For example, after selecting branch A-2, branch A-2 is used as the target branch index, and branch code 2 and branch script 2 are obtained from data block 2 and input into the coverage test tool 30 for testing to obtain the target coverage. For another example, after selecting branch A-2 and branch A-3, branch code 2 and branch script 2 are obtained from data block 2, and branch code 3 and branch script 3 are obtained from data block 3, and they are respectively input into the coverage test tool for testing.
[0071] It should be noted that the target coverage output by the coverage testing tool can include coverage data of multiple code branches, which can be determined according to the number of target data blocks. After the test platform obtains the target coverage, it forwards the target coverage to the Vue component. The Vue component extracts relevant data from the target coverage to generate a target test report, and displays the target test report through the second visual interface. The test platform integrates the coverage testing tool and the Vue component, so that the input and output data of different components can be converted and circulated within the test platform, thereby realizing the automatic generation of the target test report within the test platform.
[0072] For example, Figure 1 As shown, after the coverage testing tool 30 outputs the target coverage, the test platform forwards the target coverage to the Vue component 20, so that the Vue component 20 calls to generate a target test report and constructs a second visual interface 22 to display the target test report.
[0073] It should be noted that after obtaining the target test report, this embodiment saves the target test report to the target data block to realize classified storage of information. The target user can trigger the first visualization interface through the test platform, generate a report acquisition option in the first visualization interface, enter any first branch index in the report acquisition option, and retrieve the generated target test report from the corresponding first data block to realize flexible application of the target test report.
[0074] In addition, in one embodiment, referring to Figure 3 In step S50, a target test report is generated based on the target coverage through the Vue component, which specifically includes but is not limited to the following steps:
[0075] S51, converting the target coverage into formatted data based on a preset target format;
[0076] S52, sending the formatted data to the Vue component, and generating a target test report based on the formatted data through the Vue component.
[0077] It should be noted that, according to the description of the above embodiment, the test platform integrates the coverage testing tool and the Vue component, and the data format of the target coverage output by the coverage testing tool is different from the input format of the Vue component. If the target coverage is directly input into the Vue component, the Vue component cannot extract relevant data to generate a target test report. Therefore, the data format required for the Vue component to generate the target test report is set on the test platform, and the target coverage is converted into formatted data supported by the Vue component through the test platform, so that the Vue component can extract the target test report from the formatted data.
[0078] For example, Figure 1 As shown, the input format of the Vue component 20 is JSON. After the coverage test tool 30 outputs the target coverage, the test platform converts the target coverage into formatted data in JSON format, and inputs the formatted data in JSON format into the Vue component 20. Since the JSON format can describe different data, the Vue component 20 can extract the various parts of data required by the report template from the JSON data, and realize the automatic construction of the target test report through data filling.
[0079] In addition, in one embodiment, referring to Figure 3 The test platform is configured with multiple available K8S servers. In step S10, the target source code and the corresponding target test script are imported, including but not limited to the following steps:
[0080] S11, in response to an import request triggered by a target user, constructing a third visualization interface through a Vue component, displaying preset project indexes of various preset code projects on the third visualization interface, and determining a target project index based on an operation selected by the target user;
[0081] S12, determining the target code project and the target K8S server based on the target project index fed back by the Vue component;
[0082] S13, import the target source code and target test script into the target K8S server.
[0083] It should be noted that the test platform can be configured with multiple preset code projects. For example, a preset code project corresponds to an APP or an internal system. Different available K8S servers correspond to a preset code project to achieve code isolation of different projects.
[0084] It should be noted that after the target user logs in to the test platform, he can trigger an import request in the form of a button on the initial interface of the test platform. After the test platform obtains the import request, it builds a third visual interface through the Vue component, and displays the preset project index of each preset code project in the third visual interface in a radio button format. For example, "Internal System A" or "User APP" is displayed as the preset project index. After the target user selects any target project index, the available K8S server associated with the target project index is determined as the target K8S server, thereby determining the code project to which the target source code imported this time belongs, ensuring that the target source code is saved to the correct target K8S server.
[0085] Exemplarily, taking the property management field as an example, the test platform has multiple available K8S servers 40, the preset code projects include the owner APP and the internal management system, and the preset project indexes include "Owner APP" and "Internal System". When the target user develops the owner APP to obtain the target source code and needs to perform coverage testing, select "Owner APP" in the third visual interface of the test platform. The test platform uses the available K8S server 40 corresponding to the "Owner APP" as the target K8S server, imports the target source code and the target test script into the target K8S server, and creates the first data block 13 on the target K8S server for subsequent operations.
[0086] In addition, in one embodiment, referring to Figure 3 In step S20, multiple first data blocks are created, specifically including but not limited to the following steps:
[0087] S21, obtaining a previously created second data block of the target K8S server, wherein the second data block stores an associated second branch code and a second branch script, and the second branch code belongs to the target code project;
[0088] S22, traversing the second branch index of each second data block based on each first branch name, wherein the second branch index is the branch name of the corresponding second branch code;
[0089] S23, saving any first branch code and first branch script that successfully matches the second branch index to the corresponding second data block;
[0090] S24, creating a corresponding first data block on the target K8S server for each first branch code that fails to match the second branch index.
[0091] It should be noted that in the code development process, not only the code development of new functions is involved, but also the existing code can be iterated and updated. For example, for code branches that fail the coverage test, the developer corrects the code and re-imports it into the test platform for re-testing, or for some code branches with simple errors, some corrections are made without involving functional modifications. The target source code imported by the target user can be a complete program code, so some first code branches that do not involve modification will form a secondary import. The first data blocks of this embodiment are distinguished by the branch name of the first code branch. In the field of program development, the names of the modified code branches must be different. For example, version numbers or dates can be added to the code branches for distinction. Therefore, after importing the target source code, in order to avoid repeated storage of the same code in different data blocks, after splitting out multiple first code branches, the existing second data block is first traversed based on the first branch name. The second data block is the first data block constructed in advance. Therefore, if it is the same first code branch, the second branch index of the corresponding second data block can be traversed based on the first branch name. This embodiment directly saves the first branch code in the second data block, and overwrites and saves the second branch code to ensure that the code branch saved in each data block is the latest version, ensuring the code consistency of the target code project.
[0092] It should be noted that when the second branch index cannot be matched based on the first branch name, the first branch code is a newly created code, or a different version of an existing code branch. There is also a potential need for incremental testing of multiple code branches of different versions. Therefore, as long as the branch names are different, a new first data block is created on the target K8S server, and the first branch code is saved to the corresponding first data block.
[0093] For example, Figure 1 As shown, taking the first data block 13 including data block 1 and data block 2 as an example, data block 1 and data block 2 are used as the second data block. After importing the target source code, they are split into branch code 1, branch code 3 and branch code 4 (branch script synchronization operation, which will not be repeated here). Taking branch code 1 as an example where no modification is involved, data block 1 is matched based on branch code 1 and saved to data block 1 to ensure code consistency. Branch code 3 is the code obtained after updating based on branch code 2. Due to different versions, there are differences in the naming of branch names. For example, branch code 2 is branch A-1, and branch code 3 is branch A-2. Therefore, a new data block 3 is created for branch code 3 to be saved. Branch code 4 is a newly added code and cannot be matched to the corresponding second data block. Data block 4 is created for branch code 4 to be saved.
[0094] In addition, in one embodiment, referring to Figure 3 Step S30 specifically includes but is not limited to the following steps:
[0095] S31, generating a second option on the first visual interface, wherein the second option includes a full test item and an incremental test item;
[0096] S32, in response to the target user selecting the full test item in the second option, adding the first branch index and the second branch index of the target K8S server to the first option;
[0097] S33, in response to the target user selecting an incremental test item in the second option, constructing a first option based on all first branch indexes of the target K8S server, constructing a third option based on all second branch indexes of the target K8S server, and obtaining a reference branch index selected by the target user in the third option;
[0098] S34, obtaining the target branch index selected by the target user in the first option.
[0099] It should be noted that the coverage test of this embodiment includes two modes: full test and incremental test. For full test, the target test script is run based on the target code branch to perform coverage test. For incremental test, the incremental code is determined after selecting two branch codes, and the coverage test is performed based on the new functions represented by the incremental code. This embodiment further generates a second option in the first visual interface, and the mode selection is realized through the second option. For example, refer to Figure 1 , a second option 212 is generated in the first visualization interface 21 , and the options of the second option 212 include full test items and incremental test items.
[0100] It should be noted that when the target user selects the full test item in the second option, code comparison is not involved. The first branch index and the second branch index can be directly added to the first option for selection, which will not be repeated here.
[0101] It should be noted that when the target user selects the incremental test item in the second option, at least the first option and the third option need to be constructed in the first visual interface. Since it involves the comparison of codes of different versions, the first option is constructed only based on the first branch index, that is, the first code branch newly added when the target source code is imported this time. The third option is constructed based on the second branch index. The second branch index corresponds to the second data block constructed previously. Therefore, the second branch code saved in the second data block belongs to a different version from the code imported this time. The target user can select the branch index that needs to be incrementally tested in the first option and the third option, thereby realizing flexible selection of incremental testing.
[0102] For example, Figure 1As shown, the first option 211 and the second option 212 are displayed in the first visualization interface. When the full test item is selected in the second option 212, all the first branch indexes and second branch indexes of the target K8S server are added to the first option 211 for the target user to select. When the incremental test item is selected in the second option 212, a new third option 212 is created, the first branch index is added to the first option 211, and the second branch index is added to the third option 213. When branch A-2 is selected in the first option 211, branch A-1 is selected in the third option 213, branch A-1 is determined as the reference branch index, and branch A-2 is determined as the target branch index. The branch code is obtained according to the relevant branch index to perform subsequent operations.
[0103] It is worth noting that in both step S32 and step S33, the selection of the first option is involved, and the selection in the first option can be used as the target branch index. The difference is that step S33 also needs to further match the second branch code according to the reference branch index of the third option.
[0104] In addition, in one embodiment, referring to Figure 3 When the target user selects the incremental test item in the second option, step S40 specifically includes but is not limited to the following steps:
[0105] S41, determining the second data block corresponding to the reference branch index as the reference data block, and determining the second branch code stored in the reference data block as the reference branch code;
[0106] S42, inputting the reference branch code, the target branch code and the target branch script into the coverage testing tool, the coverage testing tool determining the incremental branch code based on the code difference between the reference branch code and the target branch code;
[0107] S43, determining the incremental branch script corresponding to the incremental branch code from the target branch script;
[0108] S44, run the incremental branch script to obtain the target coverage.
[0109] It should be noted that, under the premise of incremental test items, according to the above embodiments, a reference branch index and a target branch index can be obtained, the target branch index corresponds to the first branch code after this update, and the reference branch index corresponds to the second branch code created previously. The target data block is determined and the target branch code is obtained according to the target branch index, the reference data block is determined according to the reference branch index, and the second branch code corresponding to the reference data block is determined as the reference branch code. Two code branches for incremental testing are obtained through two indexes.
[0110] It should be noted that after obtaining the reference branch code and the target branch code, the test script adopts the target branch script to ensure that the target branch script records the test content of the updated code. The coverage testing tool first determines the incremental branch code based on the code difference between the reference branch code and the target branch code, and determines the incremental branch script from the target branch script according to the variable name or function name corresponding to the incremental branch code. The coverage testing tool runs the incremental branch script to run the incremental branch code to determine the target coverage of the incremental branch code, thereby implementing coverage testing on the incremental code.
[0111] In addition, in one embodiment, referring to Figure 3 Step S40 specifically includes but is not limited to the following steps:
[0112] S45, real-time acquisition of real-time coverage output by the coverage test tool;
[0113] S46, obtaining a preset coverage threshold, when the real-time coverage is less than the coverage threshold, sending the real-time coverage to the Vue component, and displaying abnormal prompt information on the second visualization interface.
[0114] It should be noted that this embodiment realizes data interaction between the coverage testing tool and the Vue component through the test platform. The coverage tested by the coverage testing tool includes multiple data components. For example, the real-time coverage is output for each function or variable call of the target branch code. The target coverage is composed of multiple real-time coverage. Before the coverage testing tool outputs the final target coverage, this embodiment collects the real-time coverage obtained by the coverage testing tool through the test platform in real time to realize real-time monitoring of the coverage.
[0115] It should be noted that the number of real-time coverage rates is large. If the target user monitors manually, the reliability cannot be guaranteed. This implementation automatically monitors the coverage rate through a preset coverage rate threshold. When the real-time coverage rate is lower than the coverage rate threshold, the coverage rate of the currently executed code is abnormal. The test platform converts the real-time coverage rate into a format supported by the Vue component and displays the abnormal prompt information in real time on the second visual interface, thereby realizing automatic monitoring of the abnormal coverage rate.
[0116] like Figure 4 As shown, Figure 4 : is a structural diagram of a code coverage test report generation device provided by an embodiment of the present invention. The present invention also provides a code coverage test report generation device, including:
[0117] The processor 401 may be implemented by a general-purpose central processing unit (CPU), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of the present application;
[0118] The memory 402 can be implemented in the form of a read-only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM). The memory 402 can store an operating system and other application programs. When the technical solution provided in the embodiment of this specification is implemented by software or firmware, the relevant program code is stored in the memory 402, and the processor 401 calls and executes the code coverage test report generation method of the embodiment of this application;
[0119] Input / output interface 403, used to implement information input and output;
[0120] Communication interface 404, used to realize communication interaction between the device and other devices, which can be realized through wired mode (such as USB, network cable, etc.) or wireless mode (such as mobile network, WI FI, Bluetooth, etc.);
[0121] Bus 405 , which transmits information between various components of the device (e.g., processor 401 , memory 402 , input / output interface 403 , and communication interface 404 );
[0122] The processor 401 , the memory 402 , the input / output interface 403 and the communication interface 404 are connected to each other in communication within the device via the bus 405 .
[0123] An embodiment of the present application also provides an electronic device, including the code coverage test report generating device as described above.
[0124] An embodiment of the present application also provides a storage medium, which is a computer-readable storage medium. The storage medium stores a computer program, and when the computer program is executed by a processor, the above-mentioned code coverage test report generation method is implemented.
[0125] As a non-transient computer-readable storage medium, the memory can be used to store non-transient software programs and non-transient computer executable programs. In addition, the memory may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage devices. In some embodiments, the memory may optionally include a memory remotely arranged relative to the processor, and these remote memories may be connected to the processor via a network. Examples of the above-mentioned networks include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and a combination thereof. The device embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and are implemented to be located in one place, or may also be distributed to multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the present embodiment.
[0126] It will be appreciated by those skilled in the art that all or some of the steps and systems in the disclosed method above may be implemented as software, firmware, hardware and appropriate combinations thereof. Some physical components or all physical components may be implemented as software executed by a processor, such as a central processing unit, a digital signal processor or a microprocessor, or may be implemented as hardware, or may be implemented as an integrated circuit, such as an application specific integrated circuit. Such software may be distributed on a computer-readable medium, which may include a computer storage medium (or a non-transitory medium) and a communication medium (or a temporary medium). As known to those skilled in the art, the term computer storage medium includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information (such as computer-readable instructions, data structures, program modules or other data). Computer storage media include, but are not limited to, RAM, ROM, EEPROM, flash memory or other memory technologies, CD-ROM, digital versatile disks (DVD) or other optical disk storage, magnetic cassettes, magnetic tapes, disk storage or other magnetic storage devices, or any other medium that may be used to store desired information and may be accessed by a computer. Furthermore, it is well known to those skilled in the art that communication media typically include computer readable instructions, data structures, program modules, or other data in a modulated data signal such as a carrier wave or other transport mechanism, and may include any information delivery media.
[0127] The above is a specific description of the preferred implementation of the present invention, but the present invention is not limited to the above-mentioned implementation mode. Technical personnel familiar with the field can also make various equivalent deformations or substitutions under the shared conditions without violating the spirit of the present invention. These equivalent deformations or substitutions are all included in the scope defined by the claims of the present invention.
Claims
1. A method for generating a code coverage test report, characterized in that: Applied to a test platform, the test platform integrates a coverage test tool and a Vue component, the method includes: Importing a target source code and a corresponding target test script, decomposing the target source code into a plurality of first branch codes, and determining a first branch script corresponding to each of the first branch codes from the target test script; Creating multiple first data blocks, determining the branch name of the first branch code as the first branch index of the first data block, and saving the associated first branch code and the first branch script to the same first data block; Building a first visualization interface based on the Vue component, generating a first option based on each of the first branch indexes in the first visualization interface, and obtaining a target branch index selected by a target user in the first option; Determine the target data block based on the target branch index fed back by the Vue component, input the target branch code and target branch script saved in the target data block into the coverage testing tool for coverage testing, and obtain the target coverage output by the coverage testing tool; A second visualization interface is constructed in the Vue component, a target test report is generated based on the target coverage through the Vue component, the target test report is displayed in the second visualization interface, and the target test report is saved to the target data block.
2. The method for generating a code coverage test report according to claim 1, characterized in that: Generate a target test report based on the target coverage through the Vue component, including: Converting the target coverage into formatted data based on a preset target format; The formatted data is sent to the Vue component, and the target test report is generated based on the formatted data by the Vue component.
3. The method for generating a code coverage test report according to claim 1, characterized in that: The test platform is configured with multiple available K8S servers, importing the target source code and the corresponding target test scripts, including: In response to the import request triggered by the target user, a third visualization interface is constructed through the Vue component, preset project indexes of various preset code projects are displayed on the third visualization interface, and the target project index is determined based on the selection operation of the target user; Determine the target code project and the target K8S server based on the target project index fed back by the Vue component; Import the target source code and the target test script into the target K8S server.
4. The method for generating a code coverage test report according to claim 3, characterized in that: Create a plurality of first data blocks, including: Obtain a previously created second data block of the target K8S server, wherein the second data block stores associated second branch code and second branch script, and the second branch code belongs to the target code project; Traversing the second branch indexes of the second data blocks based on the first branch names, wherein the second branch indexes are branch names of the corresponding second branch codes; Save any first branch code and first branch script that are successfully matched to the second branch index to the corresponding second data block; On the target K8S server, a corresponding first data block is created for each first branch code that fails to match the second branch index.
5. The method for generating a code coverage test report according to claim 4, characterized in that: Generating a first option based on each of the first branch indexes on the first visualization interface, and obtaining a target branch index selected by a target user from the first option, includes: Generating a second option on the first visual interface, wherein the second option includes a full test item and an incremental test item; In response to the target user selecting the full test item in the second option, adding the first branch index and the second branch index of the target K8S server to the first option; In response to the target user selecting the incremental test item in the second option, constructing the first option based on all the first branch indexes of the target K8S server, constructing the third option based on all the second branch indexes of the target K8S server, and obtaining the reference branch index selected by the target user in the third option; The target branch index selected by the target user in the first option is obtained.
6. The method for generating a code coverage test report according to claim 5, characterized in that: When the target user selects the incremental test item in the second option, the target branch code and the target branch script saved in the target data block are input into the coverage test tool for coverage test, and the target coverage output by the coverage test tool is obtained, including: Determine the second data block corresponding to the reference branch index as a reference data block, and determine the second branch code stored in the reference data block as a reference branch code; Inputting the reference branch code, the target branch code and the target branch script into the coverage testing tool, wherein the coverage testing tool determines the incremental branch code based on the code difference between the reference branch code and the target branch code; Determine the incremental branch script corresponding to the incremental branch code from the target branch script; Run the incremental branch script to obtain the target coverage.
7. The method for generating a code coverage test report according to claim 1, characterized in that: Obtaining the target coverage output by the coverage testing tool includes: Collecting real-time coverage output by the coverage testing tool in real time; A preset coverage rate threshold is obtained, and when the real-time coverage rate is less than the coverage rate threshold, the real-time coverage rate is sent to the Vue component, and abnormal prompt information is displayed on the second visualization interface.
8. A code coverage test report generating device, characterized in that: It includes at least one control processor and a memory for communicating with the at least one control processor; the memory stores instructions that can be executed by the at least one control processor, and the instructions are executed by the at least one control processor to enable the at least one control processor to execute the code coverage test report generation method as described in any one of claims 1 to 7.
9. An electronic device, characterized in that: Includes the code coverage test report generating device as described in claim 8.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are used to enable a computer to execute the code coverage test report generation method according to any one of claims 1 to 7.